Repository navigation
Don't require flags if both options are provided #6475
Answered
by
InsanityOnAMachine
InsanityOnAMachine
asked this question in
Q&A
|
I have a big CLI enum, with one of the variants being a 'publish' command that takes a title and path as options. ...other variants...
#[command(name = "pub", override_help = include_str!("docs/pub.txt"))]
#[group(required=true)]
Pub {
title: Option<String>,
path: Option<PathBuf>,
},
...other variants...I want the default syntax to be that you provide both; i.e.:
But I also want you to be able to give only one option, with a flag to specify exactly which one it is;
Now there are plenty of workarounds, but they all seem to make this pretty verbose. The main point is that the args should only require flags if only one is supplied, otherwise they're positionals. |
Answered by
InsanityOnAMachine
Aug 11, 2026
Replies: 1 comment 1 reply
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It works great, but the help does get a bit ugly; I'd rather the user didn't see all this noise;
But I think that could be sorted out with custom usage and custom usage rules to cover all the edge cases; if ya have anything to say about that It'd be appreciated but otherwise I'll mark your answer as the best one.
Many thanks!