Extensible Architecture for Rust

:wave: Hello everyone! I'm building a new thing and I need some advice on architecture.

I think I want to build a command architecture like git, whereby the base command is extensible with subsequent command modifiers.

To illustrate, there's a cool repo named git-extras wherein you can call (for example) $ git info and that, in turn, delegates to a separately packaged extra named git-info. This sort of extensibility in git is really nice. I think I want to make something like this, as opposed to a monolith.

My questions

  1. Does anyone know, what is this type of command architecture called?
  2. Do you know if there's rust a repository that uses this architecture that I could use as a rough guide?

Thanks to all in advance! :pray:

That's how cargo works. It's not particularly complex, it just runs the executable cargo-<subcommand> (in ~/.cargo/bin/ or the PATH) when it encounters a subcommand that isn't in the list of built-in commands. You maybe want to start by looking at the function execute_external_subcommand().

2 Likes

Thank you @jameseb7 that's very helpful, and this gives me a great start.

Does anybody know what this particular idiom is called? This git-like and cargo-like application structure?

I'd like to reawaken my question, if I can.

@jameseb7's answer is good, but Cargo is a large repo, with so much going on. It's just, way too much.

Does there exist a simple Rust a repository that uses a similar extensible architecture that I could use as a rough guide, or as a starter?

The mdbook project uses a similar system for plugins.

1 Like

Thank you @Michael-F-Bryan that's brilliant!

That looks perfect for structure and scale to get me started. AND I'm sorta familiar with the project — well its products anyway — and I'm natively predisposed to dig into it.

I'm glad I asked :upside_down_face: thanks again!

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.