Skip to content

How to define CLI with subcommands and global arguments or flags using derive? #111

Answered by pacak
mainrs asked this question in Q&A
Discussion options

You must be logged in to vote

I'd have a top level Options struct containing all the shared flags as well as enum with commands:

#[derive(Debug, Clone, Bpaf)]
#[bpaf(options)]
struct Options {
    verbose: bool,
    #[bpaf(external)]
    action: Action
}

#[derive(Debug, Clone, Bpaf)]
enum Action {
    #[bpaf(command)]
    Foo,
    #[bpaf(command)]
    Bar,
}

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@pacak
Comment options

@mainrs
Comment options

@pacak
Comment options

@mainrs
Comment options

@pacak
Comment options

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