TeXitoi / structopt

Parse command line arguments by defining a struct.
Other
2.7k stars 149 forks source link

Possible to skip an enum variant for a subcommand? #493

Closed chipsenkbeil closed 3 years ago

chipsenkbeil commented 3 years ago

Is there any way to ignore or skip a variant in an enum being used as a subcommand?

#[derive(StructOpt)]
struct Opt {
    #[structopt(subcommand)]
    subcommand: Subcommand,
}

#[derive(StructOpt)]
enum Subcommand {
    One { arg: u8 },
    Two ( arg: u8 },

    // Don't make this available as a subcommand
    #[structopt(skip)]
    Three { arg: u8 },
}

I've got a large enum that is both used as subcommands for a CLI interface as well as the data for network calls by serializing as JSON using serde_json. This has worked great and cut down on the need to duplicate the majority of the data - something I had to deal with quite often in the past - but there are a couple of variants that I'd like to ignore/skip.

TeXitoi commented 3 years ago

Not implemented yet. Contribution is welcome.

chipsenkbeil commented 3 years ago

@TeXitoi got a PR up that does it, I believe. Check it out and let me know.