Skip to content

Using AppSettings::SubcommandsNegateReqs #124

@erickpires

Description

@erickpires

I'm sorry if I'm missing something here, but I was unable to find any information on the documentation or in the examples.

I have a use case where my program has a required Arg (for example a input file name). I would like to implement shell completions generation using clap during runtime by passing a completionssubcommand and the shell to generate the completions for (the same way rustup does). For this to happen I need to set AppSettings::SubcommandsNegateReqs. Using the examples as a guide I did this:

#[structopt(..., raw(global_settings = "&[AppSettings::SubcommandsNegateReqs]")]

But now, when I run cargo run completions zsh for example, my program panics at Opt::from_args() due to a None been unwrap'd.

I've found a workaround this by getting the clap matches via Opt::clap().get_matches() and matching against the subcommands (and exiting early if the subcommand was found), but I found this very ugly and was thinking that there must be a clean way to do this using structopt.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementWe would love to have this feature! Feel free to supply a PRneed-designThe concrete desing is uncertain, please get involved in the discussion before sending a PRquestion

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions