Is there a way to share common options from subcomands? #1766
-
If all the subcommands share the same --option, currently I know the following works
But is it possible to have
wile option is parsed not at the subcommand level? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
The only way is to create an |
Beta Was this translation helpful? Give feedback.
-
Also, if you're willing to use the derive (or |
Beta Was this translation helpful? Give feedback.
-
@CreepySkeleton Thank you for the link~
Even with the following code let matches = App::new(name)
.subcommand(
SubCommand::with_name("subcommand")
...
)
.arg(
Arg::with_name("option")
.takes_value(true)
.long("option")
...
) |
Beta Was this translation helpful? Give feedback.
-
Disregard the link, I've misunderstood the question. If you want an option to be available not only on the subcommand level, you can use |
Beta Was this translation helpful? Give feedback.
-
I think you misunderstood what I meant. let common_arg = Arg::with_name("option")
.takes_value(true)
.long("option");
let matches = App::new(name)
.arg(common_arg.clone())
.subcommand(
SubCommand::with_name("subcommand")
.arg(common_arg.clone())
); |
Beta Was this translation helpful? Give feedback.
I think you misunderstood what I meant.