Support for using ArgGroup as Enum with derive #192
Comments
Comment by epage When I was implementing the #[derive(Clap)]
pub struct App{
#[clap(flatten)]
pub state_filter: Option<StateFilter>,
}
#[derive(Args)]
pub enum StateFilter {
/// Only running servers are returned
#[clap(long)]
Running,
/// Only exited servers are returned
#[clap(long)]
Exited,
/// Only restarting servers are returned
#[clap(long)]
Restarting,
} (with an attribute on the enum to override the group name) Though I hadn't considered
|
Comment by Skirmisher This would be lovely for my use case (an archive utility, where the operation modes are exclusive but otherwise share the same options, similar to |
Comment by epage You can workaround this by manually defining the arg group and adding the arguments to it. While its using structopt instead of clap-derive, the principle and calls are pretty much the same in this code of mine. |
Comment by 0x5c The problem with argument groups and the struct equivalent is that you can't ask clap what option was specified, all you can do is check each individual option of the group for presence in the arguments. We're back to to arguments not really being parsed into something useful. With subcommands, clab directly talls you what subcommand was found in the arguments, as either an Enum or as the string ID of the subcommand. In both cases you can actually match on something instead of having an if-else chain or iteration simply to know which one it was |
Comment by MTCoster I have a perfect use case for this right now: my app can accept a config file, or (perhaps if the config is very short) a string directly in the command line. For instance:
The config string is not designed to be parsed by the app; it's passed directly through to the output. I have no desire to parse it. Ideally, I'd write something like this:
|
Comment by epage
Yes, its only a workaround to help keep people from being blocked and is not ideal. We are trying to focus on polishing up clap v3 before before working on new features. Once v3 is out (and maybe a little after as we do high priority work we postponed), we can look into this or mentoring someone who can look into this, |
Issue by ModProg
Sunday Jul 25, 2021 at 20:41 GMT
Originally opened as clap-rs/clap#2621
Please complete the following tasks
Clap Version
3.0.0-beta.2
Describe your use case
I have multiple filters of witch only one can be set (
--running
,--exited
,--restarting
,...).Describe the solution you'd like
I would like something with this usage:
Resulting in:
Alternatives, if applicable
I could use an arggroup for this currently, but I would still need to check each boolean seperatly and could not just easily (and readable)
match
it.Additional Context
No response
The text was updated successfully, but these errors were encountered: