-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow Nested Subcommands #1
Comments
You just need to use an intermediate struct with use argp::FromArgs;
/// Top-level command.
#[derive(FromArgs, PartialEq, Debug)]
struct TopLevel {
/// Be verbose.
#[argp(switch, short = 'v', global)]
verbose: bool,
/// Run locally.
#[argp(switch)]
quiet: bool,
#[argp(subcommand)]
nested: MySubCommandEnum,
}
#[derive(FromArgs, PartialEq, Debug)]
#[argp(subcommand)]
enum MySubCommandEnum {
One(SubCommandOne),
Two(SubCommandTwo),
}
/// First subcommand.
#[derive(FromArgs, PartialEq, Debug)]
#[argp(subcommand, name = "one")]
struct SubCommandOne {
/// How many x.
#[argp(option)]
x: usize,
}
/// Second subcommand.
#[derive(FromArgs, PartialEq, Debug)]
#[argp(subcommand, name = "two")]
struct SubCommandTwo {
#[argp(subcommand)]
nested: MySecondSubCommandEnum,
}
#[derive(FromArgs, PartialEq, Debug)]
#[argp(subcommand)]
enum MySecondSubCommandEnum {
Three(SubCommandThree),
}
/// Nested subcommand.
#[derive(FromArgs, PartialEq, Debug)]
#[argp(subcommand, name = "three")]
struct SubCommandThree {
/// Whether to fooey.
#[argp(switch)]
fooey: bool,
}
fn main() {
let args: TopLevel = argp::parse_args_or_exit(argp::DEFAULT);
println!("{:#?}", args);
}
|
I figured I had to be missing something. Thanks for your help! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm trying to port my code from clap, where I have a secondarily nested subcommand, but it seems like argh and argp (and gumdrop) are unable to do this. Here's the error, it seems to not like multiple enums that point to subcommands.
Here's a simple modified example from the docs, basically I want the base subcommand enum to be able to point to other subcommand enums.
The text was updated successfully, but these errors were encountered: