In some sophisticated situations, these may be expensive to calculate.
One example might be a '--branch' option accepting any single Git
branch that exists on the remote -- in such a case, the remote would
need to be queried for all possible_values. The cost is ultimately
unavoidable at runtime since this validation has to happen eventually,
but there's no need to pay it when generating help text if
`is_hide_possible_values_set`.
To keep '-h' fast, avoid collecting `possible_values` during '-h'
unless we're actually going to use the values in display.
This optimization is repeated for the manpage renderer.
This is trivially based on the short-circuiting logic at [1], which at
least supports the idea that actually consuming the iterator is not
generally-guaranteed behavior when `hide_possible_values` is set.
Note on the 'expensive' mod: This keeps all the possible_values tests
in one file but allows the entire set of tests to be controlled by the
'strings' feature (which is required to be able to use String rather
than str for each possible value).
[1]: clap_builder/src/builder/command.rs:long_help_exists_
derive arguments like this:
#[arg(long)]
pub flag: bool,
were producing option descriptions like this:
--flag=FLAG
FLAG is spurious. It turns out that derive always sets a value name, for
simplicity, even when there are no arguments. Check for this case.
Fixes#4443.
This adds feature parity for mangen with the standard help output. Users
will now see the list of possible values for value arguments.
One change that was made to make this possible was adding the method
`get_possible_values` to the public API for an arg. I tried to think of
a way to get around this, but because this is the interface that the
help generation uses, and it is part of the crate public interface
I thing adding it as a part of the public API might be for the best.
fixes: #3861
This is a step towards #1041
- `ArgGroup` no longer takes a lifetime
- One less field type needs a lifetime
For now, we are using a more brute force type (`String`) so we can
establish performance base lines. I was torn on whether to use `&str`
everywhere or make an `IdRef`. The latter would add a lot of noise that
I'm concerned about, so i left it simple for now. `IdRef` would help to
communicate the types involved though.
Speaking of communicating types, I'm also torn on whether we should use
`Id` for all strings or if we should have `Id`, `Name`, etc types to
avoid people mixing and matching.
This added 18.7 KB.
Compared to `HEAD~` on `06_rustup`:
- build: 6.23us -> 7.41us
- parse: 8.17us -> 9.36us
- parse_sc: 7.65us -> 9.29us
This commit updates the man page renderer to use a relative margin
indent for environment variable text instead of appending to the
existing help text.
Signed-off-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
Fixes: #3630
`Command::_build_all` started as an internal function for
`clap_complete` as a stopgap until #2911. Overtime, we've been finding
more cases where this function needs to be called, so now we're going to
fully embrace it until #2911 so people aren't scrared off by the hidden
implementation from using it.
This was inspired by #3602
Comptibility: Though this adds a deprecation which we general reserve
for minor or major versions, this is enough of a corner case that I'm
fine doing this in a patch release.
The long term goals are
- Easier refactoring
- Identify needs for reflection API
Shorter term, if I want to rename `App` to `Command` and deprecate
`App`, it will mark all member access as deprecated. This works around
that.
I gave up in exploring abstractions when it came to `MKeyMap` access.
This can be refined in the future.
Now that we can use `SubcommandRequired |
ArgRequiredElseHelp`, this setting offers little value but requires we
track required subcommands with two different settings. Deprecating as
the cost is not worth the benefit anymore.
Issue #3280 will see the derive updated
This is a part of #2717
Some settings didn't get getters because
- They are transient parse settings (e.g. ignore errors)
- They get propagated to args and should be checked there
`is_allow_hyphen_values_set` is a curious case. In some cases, we only
check the app and not an arg. This seems suspicious.
I have access to the `clap-man` name but we use `clap_*`. Rather than
people getting mixed up on which is supposed to use, we went with a
different name.