Hello!
I would like to know if it is possible to add alternatives to invoke the same Subcommand.
Take this for example:
#[derive(StructOpt, Debug)]
pub enum Subcommand {
#[structopt(name = "action")]
Action {
#[structopt(name = "something")]
something: String,
}
}
In order to use the subcommand, the user should type ./myapp action. I would like to "shorten" it to ./myapp a or even ./myapp act.
Is it possible to achieve something like this?
Thanks and keep up the awesome work!
An example with all such functionnalities with link to clap documentation: https://github.com/TeXitoi/structopt/blob/master/examples/subcommand_aliases.rs
The resulting binary:
gpinot@gpinot:~/dev/structopt$ ./target/debug/examples/subcommand_aliases f
error: The subcommand 'f' wasn't recognized
USAGE:
subcommand_aliases help <subcommands>...
For more information try --help
gpinot@gpinot:~/dev/structopt$ ./target/debug/examples/subcommand_aliases fo
Foo
gpinot@gpinot:~/dev/structopt$ ./target/debug/examples/subcommand_aliases foo
Foo
gpinot@gpinot:~/dev/structopt$ ./target/debug/examples/subcommand_aliases foobar
Foo
gpinot@gpinot:~/dev/structopt$ ./target/debug/examples/subcommand_aliases fi
Bar
gpinot@gpinot:~/dev/structopt$ ./target/debug/examples/subcommand_aliases b
Bar
gpinot@gpinot:~/dev/structopt$ ./target/debug/examples/subcommand_aliases bar
Bar
Does it answer all your questions?
Absolutely! Thanks!
On Mon, Apr 9, 2018 at 2:16 AM, Guillaume P. notifications@github.com
wrote:
An example with all such functionnalities with link to clap documentation:
https://github.com/TeXitoi/structopt/blob/master/
examples/subcommand_aliases.rsThe resulting binary:
gpinot@gpinot:~/dev/structopt$ ./target/debug/examples/subcommand_aliases f
error: The subcommand 'f' wasn't recognizedUSAGE:
subcommand_aliases help... For more information try --help
gpinot@gpinot:~/dev/structopt$ ./target/debug/examples/subcommand_aliases fo
Foo
gpinot@gpinot:~/dev/structopt$ ./target/debug/examples/subcommand_aliases foo
Foo
gpinot@gpinot:~/dev/structopt$ ./target/debug/examples/subcommand_aliases foobar
Foo
gpinot@gpinot:~/dev/structopt$ ./target/debug/examples/subcommand_aliases fi
Bar
gpinot@gpinot:~/dev/structopt$ ./target/debug/examples/subcommand_aliases b
Bar
gpinot@gpinot:~/dev/structopt$ ./target/debug/examples/subcommand_aliases bar
BarDoes it answer all your questions?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/TeXitoi/structopt/issues/91#issuecomment-379688173,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFwP62FWxn0OsyxmKbfNvYJamc7AfuUwks5tmycDgaJpZM4TL6AA
.
--
- Giulio
Most helpful comment
An example with all such functionnalities with link to clap documentation: https://github.com/TeXitoi/structopt/blob/master/examples/subcommand_aliases.rs
The resulting binary:
Does it answer all your questions?