-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Confusing how to override version
or help
s behavior
#3405
Comments
For anyone else that runs across this: you can disable this behavior by adding this:
Even though this behavior can be disabled, I would argue that the existing behavior violates the Principle of Least Surprise -- not least because it exits without providing any real indicator as to why. (I would also note that StructOpt seems to have had |
The intent of the current behavior is to allow you to custmize the flag while still getting the same behavior. We also offer customization by, behind the scenes, pre-creating some flags for you to modify with That said, this is still not great. My current thought
The main concern is the discoverability of the defaults but I think this moves us in the right direction. Going to rename this Issue to reflect the confusion over the existing API. |
version
or help
s behavior
Totally agreed about the change in issue name (as one might guess, I had not yet discovered |
For now, we are going to provide a better debug assert in this case. Resolving clap-rs#3405 is the better long term route. Fixes clap-rs#3403
Like was said in clap-rs#2435, this is what people would expect. While we should note this in a compatibility section in the changelog, I do not consider this a breaking change since we should be free to adjust the help output as needed. We are cautious when people might build up their own content around it (like clap-rs#3312) but apps should already handle this with `--help` so this shouldn't be a major change. We aren't offering a way for people to disable this, assuming people won't need to. Longer term, we are looking at support "Actions" (clap-rs#3405) and expect those to help customize the flags. We'll need something similar for the `help` subcommand. Fixes clap-rs#3440
Like was said in clap-rs#2435, this is what people would expect. While we should note this in a compatibility section in the changelog, I do not consider this a breaking change since we should be free to adjust the help output as needed. We are cautious when people might build up their own content around it (like clap-rs#3312) but apps should already handle this with `--help` so this shouldn't be a major change. We aren't offering a way for people to disable this, assuming people won't need to. Longer term, we are looking at support "Actions" (clap-rs#3405) and expect those to help customize the flags. We'll need something similar for the `help` subcommand. Fixes clap-rs#3440
The change in pre-generated I'd like to get Actions in for clap v3 users, independent of whats going on for clap 4. In that case, we should probably do it first so we don't couple the design to any changes for v4. Python has
Python also includes a non-native action, Items like #815 could be implemented like So the question is what can be supported without blocking on #2683 and is it worth going ahead without it? Without inheritance exposed, removing of pre-generated help, or support for #2683, I'm thinking there isn't a use case that makes this worth it enough. Going to focus on those other areas first. |
To implement this sanely, I'm going to need to do a major parser refactor Random notes
|
Working on integrating actions (#3774, #3775, #3777) into the derive API and hitting a hurdle.
How do we support the user using whatever type they want like they can today? Ideas
|
Fixes 5395 In PR 5239 we switched from using `structopt` to `clap`. It seems that the default behavior for `clap` is to override the `--version` flag, which prevented our custom version display code from running. The fix as outlined in clap-rs/clap#3405 was to set `#[clap(global_setting(AppSettings::NoAutoVersion))]` to prevent clap from setting its own default behavior for the `--version` flag.
Fixes 5395 In PR 5239 we switched from using `structopt` to `clap`. It seems that the default behavior for `clap` is to override the `--version` flag, which prevented our custom version display code from running. The fix as outlined in clap-rs/clap#3405 was to set `#[clap(global_setting(AppSettings::NoAutoVersion))]` to prevent clap from setting its own default behavior for the `--version` flag.
Before we introduced actions, it required specific setups to engage with claps version and help printing. With actions making that more explicit, we don't get as much benefit from our multiple, obscure, ways of users customizing help Before - Modify existing help or version with `mut_arg` which would automatically be pushed down the command tree like `global(true)` - Create an new help or version and have it treated as if it was the built-in on (I think) - Use the same flags as built-in and have the built-in flags automatically disabled - Users could explicitly disable the built-in functionality and do what they want Now - `mut_arg` no longer works as we define help and version flags at the end - If someone defines a flag that overlaps with the built-ins by id, long, or short, a debug assert will tell them to explicitly disable the built-in - Any customization has to be done by a user providing their own. To propagate through the command tree, they need to set `global(true)`. Benefits - Hopefully, this makes it less confusing on how to override help behavior. Someone creates an arg and we then tell them how to disable the built-in - This greatly simplifies the arg handling by pushing more responsibility onto the developer in what are hopefully just corner cases - This removes about 1Kb from .text Fixes clap-rs#3405 Fixes clap-rs#4033
Before we introduced actions, it required specific setups to engage with claps version and help printing. With actions making that more explicit, we don't get as much benefit from our multiple, obscure, ways of users customizing help Before - Modify existing help or version with `mut_arg` which would automatically be pushed down the command tree like `global(true)` - Create an new help or version and have it treated as if it was the built-in on (I think) - Use the same flags as built-in and have the built-in flags automatically disabled - Users could explicitly disable the built-in functionality and do what they want Now - `mut_arg` no longer works as we define help and version flags at the end - If someone defines a flag that overlaps with the built-ins by id, long, or short, a debug assert will tell them to explicitly disable the built-in - Any customization has to be done by a user providing their own. To propagate through the command tree, they need to set `global(true)`. Benefits - Hopefully, this makes it less confusing on how to override help behavior. Someone creates an arg and we then tell them how to disable the built-in - This greatly simplifies the arg handling by pushing more responsibility onto the developer in what are hopefully just corner cases - This removes about 1Kb from .text Fixes clap-rs#3405 Fixes clap-rs#4033
Before we introduced actions, it required specific setups to engage with claps version and help printing. With actions making that more explicit, we don't get as much benefit from our multiple, obscure, ways of users customizing help Before - Modify existing help or version with `mut_arg` which would automatically be pushed down the command tree like `global(true)` - Create an new help or version and have it treated as if it was the built-in on (I think) - Use the same flags as built-in and have the built-in flags automatically disabled - Users could explicitly disable the built-in functionality and do what they want Now - `mut_arg` no longer works as we define help and version flags at the end - If someone defines a flag that overlaps with the built-ins by id, long, or short, a debug assert will tell them to explicitly disable the built-in - Any customization has to be done by a user providing their own. To propagate through the command tree, they need to set `global(true)`. Benefits - Hopefully, this makes it less confusing on how to override help behavior. Someone creates an arg and we then tell them how to disable the built-in - This greatly simplifies the arg handling by pushing more responsibility onto the developer in what are hopefully just corner cases - This removes about 1Kb from .text Fixes clap-rs#3405 Fixes clap-rs#4033
For anyone who look to override default version: #[derive(Parser, Debug)]
#[command(author, version, about, long_about = None, disable_version_flag = true)]
struct Args {
...
} |
Maintainer's notes
Action
system where you set an arguments action toAction::Set
,Action::Extend
,Action::SetTrue
,Action::Count
, etc. The ones relevant here would beAction::Help
andAction::Version
.Action::Set
orAction::SetTrue
(depending on other settings) unless they were namedversion
orhelp
for which we'd default their actions toAction::Help
andAction::Version
Original title: "cannot have an option named "version""
#[clap(global_setting(AppSettings::NoAutoVersion))]
for solving thatPlease complete the following tasks
Rust Version
rustc 1.59.0-nightly (34926f0a1 2021-12-22)
Clap Version
3.0.14
Minimal reproducible code
Steps to reproduce the bug with the above code
cargo run -- -x
orcargo run -- --version
Actual Behaviour
Expected Behaviour
Additional Context
We need to have a
--version
option that does more than the Clap default. Currently, Clap special-cases the stringversion
, and seemingly overrides its behavior (changing the option name to anything else results in the expected behavior). This seems to be aversion
manifestation of behavior similar to #3403.Debug Output
The debug output is very helpful about indicating what it's doing, it's just that this is behavior that we do not want.
The text was updated successfully, but these errors were encountered: