Skip to content
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

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

Closed
chipsenkbeil opened this issue Aug 29, 2021 · 2 comments · Fixed by #494
Closed

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

chipsenkbeil opened this issue Aug 29, 2021 · 2 comments · Fixed by #494
Labels
enhancement We would love to have this feature! Feel free to supply a PR

Comments

@chipsenkbeil
Copy link
Contributor

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
Copy link
Owner

TeXitoi commented Aug 29, 2021

Not implemented yet. Contribution is welcome.

@TeXitoi TeXitoi added the enhancement We would love to have this feature! Feel free to supply a PR label Aug 29, 2021
@chipsenkbeil
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement We would love to have this feature! Feel free to supply a PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants