Custom subcommands

I need a program named program1 to take ANY subcommand c1 and run an executable or an alias named program1-c1 with the arguments supplied. Like how git and cargo do.

So program1 c1 -f1 -f2 -f3 should run program1-c1 -f1 -f2 -f3. Any library dedicated for this?

I don’t know of a crate, but it should be relatively straightforward to do it yourself. Something like this: (untested, probably buggy)

let mut args=std::env::ArgsOs();
let mut exe:Path =;
let ext:Option<OsStr> = exe.extension();
let mut basename: OsString: exe.file_stem().unwrap().into();
let exe = exe.with_file_name(basename).with_extension(ext);
1 Like

I got something from cargo's source code.

Funny that something like this (probably) doesn't have its own package.

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.