Skip to content

Default Subcommand #3566

Answered by epage
pvshvp-oss asked this question in Q&A
Mar 22, 2022 · 3 comments · 9 replies
Discussion options

You must be logged in to vote

At the moment there is not. You can do it manually though. Something like

let cmd = clap::Command::new("git")
    .subcommand(
        clap::Command::new("stash")
            .args_conflicts_with_subcommands(true)
            .args(push_args())
            .subcommand(clap::Command::new("push").args(push_args()))
    );

let matches = cmd.get_matches();
match matches.subcommand() {
    Some(("stash", sub_matches)) => match sub_matches.subcommand() {
        Some(("push"), sub_matches)) => push(sub_matches),
        None => push(sub_matches),
    }
}

We should probably add this to our "git" example.

Replies: 3 comments 9 replies

Comment options

You must be logged in to vote
3 replies
@pvshvp-oss
Comment options

@epage
Comment options

@epage
Comment options

Answer selected by epage
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
6 replies
@epage
Comment options

@epage
Comment options

@dnaka91
Comment options

@epage
Comment options

@dnaka91
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants