This PR contains the following updates:
| Package | Type | Update | Change |
|---|---|---|---|
| clap | dependencies | major | ^2.29.0
-> ^4.0.18
|
Release Notes
clap-rs/clap
Compare Source
Fixes
- (derive) Allow
#[command(skip)]
to also work with enum variants with a value
Compare Source
Fixes
- Allow using
Arg::last(true)
with Arg::value_hint(ValueHint::CommandWithArguments)
Compare Source
Fixes
Arg::exclusive(true)
should not be exclusive with the argument's own ArgGroup
Compare Source
Fixes
- (error) Don't suggest
--
when it doesn't help
- (error) Be more consistent in quoting, punctuation, and indentation in errors
Compare Source
Fixes
- Only put
ArgGroup
in ArgMatches
whenΒ explicitly specified, fixing derives handling of option-flattened fields (#β4375)
Compare Source
Features
- (derive) Allow
()
for fields to mean "don't read" (#β4371)
Compare Source
Features
- Added
TypedValueParser::try_map
for when adapting an existing TypedValueParser
can fail
- (error) Create errors like clap with
Error::new
, Error::with_cmd
, and Error::insert
Compare Source
Fixes
- (help) Fix wrapping calculations with ANSI escape codes
Compare Source
Features
Compare Source
Fixes
- (derive) Process doc comments for
#[command(subcommand)]
like in clap v3
Compare Source
Fixes
- (derive) Remove a low-value assert preventing defaulting
Help
and Version
actions
Compare Source
Features
- (derive) Populate implicit ArgGroup (#β3165)
Fixes
- (derive) Support
#[group(skip)]
on Parser
derive
- (derive) Tell users about implicit arg groups when running into group name conflicts
- (error) Don't report unrelated groups in conflict or requires errors
Compare Source
Features
Compare Source
Compare Source
Fixes
- (error) Specialize the self-conflict error to look like clap v3
Compare Source
Fixes
- (error) Quote literals consistently
- (error) Stylize escape (
--
) suggestions
- (error) Format help flag as a literal
Compare Source
Fixes
- (parser)
SetFalse
should conflict with itself like SetTrue
and Set
- (parser) Allow one-off overrides
Compare Source
Fixes
- (derive) Allow
#[command(skip)]
to also work with enum variants with a value
Compare Source
Highlights
Arg::num_args(range)
Clap has had several ways for controlling how many values will be captured without always being clear on how they interacted, including
Arg::multiple_values(true)
Arg::number_of_values(4)
Arg::min_values(2)
Arg::max_values(20)
Arg::takes_value(true)
These have now all been collapsed into Arg::num_args
which accepts both
single values and ranges of values. num_args
controls how many raw arguments
on the command line will be captured as values per occurrence and independent
of value delimiters.
See Issue 2688 for more background.
Polishing Help
Clap strives to give a polished CLI experience out of the box with little
ceremony. With some feedback that has accumulated over time, we took this
release as an opportunity to re-evaluate our --help
output to make sure it is
meeting that goal.
In doing this evaluation, we wanted to keep in mind:
- Whether other CLIs had ideas that make sense to apply
- Providing an experience that fits within the rest of applications and works across all shells
Before:
git
A fictional versioning CLI
USAGE:
git <SUBCOMMAND>
OPTIONS:
-h, --help Print help information
SUBCOMMANDS:
add adds things
clone Clones repos
help Print this message or the help of the given subcommand(s)
push pushes things
stash
After:
A fictional versioning CLI
Usage: git <COMMAND>
Commands:
clone Clones repos
push pushes things
add adds things
stash
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help information
- name/version header was removed because we couldn't justify the space it occupied when
- Usage already includes the name
--version
is available for showing the same thing (if the program has a version set)
- Usage was dropped to one line to save space
- Focus is put on the subcommands
- Headings are now Title case
- The more general term "command" is used rather than being explicit about being "subcommands"
- The output is more dense with the expectation that it won't affect legibility but will allow more content
- We've moved to a more neutral palette for highlighting elements (not highlighted above)
In talking to users, we found some that liked clap's man
-like experience.
When deviating from this, we are making the assumption that those are more
power users and that the majority of users wouldn't look as favorably on being
consistent with man
.
See Issue 4132 for more background.
More Dynamicism
Clap's API has focused on &str
for performance but this can make
dealing with owned data difficult, like #[arg(default_value_t)]
generating a
String from the default value.
Additionally, to avoid ArgMatches
from borrowing (and for some features we
decided to forgo), clap took the &str
argument IDs and hashed them. This
prevented us from providing a usable API for iterating over existing arguments.
Now clap has switched to a string newtype that gives us the flexibility to
decide whether to use &'static str
, Cow<'static, str>
for fast dynamic behavior, or
Box<str>
for dynamic behavior with small binary size.
As an extension of that work, you can now call ArgMatches::ids
to iterate
over the arguments and groups that were found when parsing. The newtype Id
was used to prevent some classes of bugs and to make it easier to understand
when opaque Ids are used vs user-visible strings.
Clearing Out Deprecations
Instead of doing all development on clap 4.0.0, we implemented a lot of new features during clap 3's development, deprecating the old API while introducing the new API, including:
- Replacing the implicit behavior for args when parsing them with
ArgAction
- Replacing various one-off forms of value validation with the
ValueParser
API
- Allowing derives to automatically do the right thing for
PathBuf
(allowing invalid UTF-8)
- Replacing
AppSettings
and ArgSettings
enums with getters/setters
- Clarifying terms and making them more consistent
Migrating
Steps:
- Upgrade to v3 if you haven't already
- Add CLI tests (including example below),
-h
and --help
output at a minimum (recommendation: trycmd for snapshot testing)
- If using Builder API: Explicitly set the
arg.action(ArgAction::...)
on each argument (StoreValue
for options and IncOccurrences
for flags)
- Run
cargo check --features clap/deprecated
and resolve all deprecation warnings
- Upgrade to v4
- Update feature flags
- If
default-features = false
, run cargo add clap -F help,usage,error-context
- Run
cargo add clap -F wrap_help
unless you want to hard code line wraps
- Resolve compiler errors
- Resolve behavior changes (see "subtle changes" under BREAKING CHANGES)
- At your leisure: resolve new deprecation notices
Example test (derive):
#[derive(clap::Parser)]
struct Cli {
...
}
#[test]
fn verify_cli() {
use clap::CommandFactory;
Cli::command().debug_assert()
}
Example test (builder):
fn cli() -> clap::Command {
...
}
#[test]
fn verify_cli() {
cli().debug_assert();
}
Note: the idiomatic / recommended way of specifying different types of args in the Builder API has changed:
Before
.arg(Arg::new("flag").long("flag")) # --flag
.arg(Arg::new("option").long("option").takes_value(true)) # --option <option>
After:
.arg(Arg::new("flag").long("flag").action(ArgAction::SetTrue)) # --flag
.arg(Arg::new("option").long("option")) # --option <option>
In particular, num_args
(the replacement for takes_value
) will default appropriately
from the ArgAction
and generally only needs to be set explicitly for the
other num_args
use cases.
Breaking Changes
Subtle changes (i.e. compiler won't catch):
arg!
now sets one of (#β3795):
ArgAction::SetTrue
, requiring ArgMatches::get_flag
instead of ArgMatches::is_present
ArgAction::Count
, requiring ArgMatches::get_count
instead of ArgMatches::occurrences_of
ArgAction::Set
, requiring ArgMatches::get_one
instead of ArgMatches::value_of
ArgAction::Append
, requiring ArgMatches::get_many
instead of ArgMatches::values_of
ArgAction::Set
, ArgAction::SetTrue
, and Arg::Action::SetFalse
now
conflict by default to be like ArgAction::StoreValue
and
ArgAction::IncOccurrences
, requiring cmd.args_override_self(true)
to override instead (#β4261)
- By default, an
Arg
s default action is ArgAction::Set
, rather than ArgAction::IncOccurrence
to reduce confusing magic through consistency (#β2687, #β4032, see also #β3977)
mut_arg
can no longer be used to customize help and version arguments, instead disable them (Command::disable_help_flag
, Command::disable_version_flag
) and provide your own (#β4056)
- Removed lifetimes from
Command
, Arg
, ArgGroup
, and PossibleValue
, assuming 'static
. string
feature flag will enable support for String
s (#β1041, #β2150, #β4223)
arg!(--flag <value>)
is now optional, instead of required. Add .required(true)
at the end to restore the original behavior (#β4206)
- Added default feature flags,
help
, usage
and error-context
, requiring adding them back in if default-features = false
(#β4236)
- (parser) Always fill in
""
argument for external subcommands to make it easier to distinguish them from built-in commands (#β3263)
- (parser) Short flags now have higher precedence than hyphen values with
Arg::allow_hyphen_values
, to be consistent with Command::allow_hyphen_values
(#β4187)
- (parser)
Arg::value_terminator
must be its own argument on the CLI rather than being in a delimited list (#β4025)
- (help) Line wrapping of help is now behind the existing
wrap_help
feature flag, either enable it or hard code your wraps (#β4258)
- (help) Make
DeriveDisplayOrder
the default and removed the setting. To sort help, set next_display_order(None)
(#β2808)
- (help) Subcommand display order respects
Command::next_display_order
instead of DeriveDisplayOrder
and using its own initial display order value (#β2808)
- (help) Subcommands are now listed before arguments. To get the old behavior, see
Command::help_template
(#β4132)
- (help) Help headings are now title cased, making any user-provided help headings inconsistent. To get the old behavior, see
Command::help_template
, Arg::help_heading
, and Command::subcommand_help_heading
(#β4132)
- (help) "Command" is used as the section heading for subcommands and
COMMAND
for the value name. To get the old behavior, see Command::subcommand_help_heading
and Arg::subcommand_value_name
(#β4132, #β4155)
- (help) Whitespace in help output is now trimmed to ensure consistency regardless of how well a template matches the users needs. (#β4132, #β4156)
- (help) name/version/author are removed by default from help output. To get the old behavior, see
Command::help_template
. (#β4132, #β4160)
- (help) Indentation for second-line usage changed. (#β4132, #β4188)
- (env) Parse
--help
and --version
like any ArgAction::SetTrue
flag (#β3776)
- (derive) Leave
Arg::id
as verbatim
casing, requiring updating of string references to other args like in conflicts_with
or requires
(#β3282)
- (derive) Doc comments for
ValueEnum
variants will now show up in --help
(#β3312)
- (derive) When deriving
Args
, and ArgGroup
is created using the type's name, reserving it for future use (#β2621, #β4209)
- (derive)
next_help_heading
can now leak out of a #[clap(flatten)]
, like all other command settings (#β4222)
Easier to catch changes:
- Looking up a group in
ArgMatches
now returns the arg Id
s, rather than the values to reduce overhead and offer more flexibility. (#β4072)
- Changed
Arg::number_of_values
(average-across-occurrences) to Arg::num_args
(per-occurrence) (raw CLI args, not parsed values) (#β2688, #β4023)
num_args(0)
no longer implies takes_value(true).multiple_values(true)
(#β4023)
num_args(1)
no longer implies multiple_values(true)
(#β4023)
- Does not check default or env values, only what the user explicitly passes in (#β4025)
- No longer terminates on delimited values (#β4025)
- Replace
Arg::min_values
(across all occurrences) with Arg::num_args(N..)
(per occurrence) to reduce confusion over different value count APIs (#β4023)
- Replace
Arg::max_values
(across all occurrences) with Arg::num_args(1..=M)
(per occurrence) to reduce confusion over different value count APIs (#β4023)
- Replace
Arg::multiple_values(true)
with Arg::num_args(1..)
and Arg::multiple_values(false)
with Arg::num_args(0)
to reduce confusion over different value count APIs (#β4023)
- Replace
Arg::takes_value(true)
with Arg::num_args(1)
and Arg::takes_value(false)
with Arg::num_args(0)
to reduce confusion over different value count APIs
- Remove
Arg::require_value_delimiter
, either users could use Arg::value_delimiter
or implement a custom parser with TypedValueParser
as it was mostly to make multiple_values(true)
act like multiple_values(false)
and isn't needed anymore (#β4026)
Arg::new("help")
and Arg::new("version")
no longer implicitly disable the
built-in flags and be copied to all subcommands, instead disable
the built-in flags (Command::disable_help_flag
,
Command::disable_version_flag
) and mark the custom flags as global(true)
. (#β4056)
Arg::short('h')
no longer implicitly disables the short flag for help,
instead disable
the built-in flags (Command::disable_help_flag
,
Command::disable_version_flag
) provide your own Arg::new("help").long("help").action(ArgAction::Help).global(true)
. (#β4056)
ArgAction::SetTrue
and ArgAction::SetFalse
now prioritize Arg::default_missing_value
over their standard behavior (#β4000)
- Changed
Arg::requires_ifs
and Arg::default_value*_ifs*
to taking an ArgPredicate
, removing ambiguity with None
when accepting owned and borrowed types (#β4084)
- Removed
PartialEq
and Eq
from Command
so we could change external subcommands to use a ValueParser
(#β3990)
- Various
Arg
, Command
, and ArgGroup
calls were switched from accepting &[]
to []
via IntoIterator
to be more flexible (#β4072)
Arg::short_aliases
and other builder functions that took &[]
need the &
dropped (#β4081)
ErrorKind
and Result
moved into the error
module
ErrorKind::EmptyValue
replaced with ErrorKind::InvalidValue
to remove an unnecessary special case (#β3676, #β3968)
ErrorKind::UnrecognizedSubcommand
replaced with ErrorKind::InvalidSubcommand
to remove an unnecessary special case (#β3676)
- Changed the default type of
allow_external_subcommands
from String
to OsString
as that is less likely to cause bugs in user applications (#β3990)
- (help)
Command::render_usage
now returns a StyledStr
(#β4248)
- (derive) Changed the default for arguments from
parse
to value_parser
, removing parse
support (#β3827, #β3981)
#[clap(value_parser)]
and #[clap(action)]
are now redundant
- (derive)
subcommand_required(true).arg_required_else_help(true)
is set instead of SubcommandRequiredElseHelp
to give more meaningful errors when subcommands are missing and to reduce redundancy (#β3280)
- (derive) Remove
arg_enum
attribute in favor of value_enum
to match the new name (we didn't have support in v3 to mark it deprecated) (#β4127)
- (parser) Assert when the CLI looksup an unknown args when external subcommand support is enabled to help catch bugs (#β3703)
- (assert) Sometimes
Arg::default_missing_value
didn't require num_args(0..=N)
, now it does (#β4023)
- (assert) Leading dashes in
Arg::long
are no longer allowed (#β3691)
- (assert) Disallow more
value_names
than num_args
(#β2695)
- (assert) Always enforce that version is specified when the
ArgAction::Version
is used
- (assert) Add missing
#[track_caller]
s to make it easier to debug asserts
- (assert) Ensure
overrides_with
IDs are valid
- (assert) Ensure no self-
overrides_with
now that Actions replace it
- (assert) Ensure subcommand names are not duplicated
- (assert) Assert on
mut_arg
receiving an invalid arg ID or mut_subcommand
receiving an invalid command name
Compatibility
MSRV is now 1.60.0
Deprecated
Arg::use_value_delimiter
in favor of Arg::value_delimiter
to avoid having multiple ways of doing the same thing
Arg::requires_all
in favor of Arg::requires_ifs
now that it takes an ArgPredicate
to avoid having multiple ways of doing the same thing
Arg::number_of_values
in favor of Arg::num_args
to clarify semantic differences
default_value_os
, default_values_os
, default_value_if_os
, and default_value_ifs_os
as the non _os
variants now accept either a str
or an OsStr
(#β4141)
Arg::env_os
in favor of Arg::env
Command::dont_collapse_args_in_usage
is now the default (#β4151)
Command::trailing_var_arg
in favor of Arg::trailing_var_arg
to make it clearer which arg it is meant to apply to (#β4187)
Command::allow_hyphen_values
in favor of Arg::allow_hyphen_values
to make it clearer which arg it is meant to apply to (#β4187)
Command::allow_negative_numbers
in favor of Arg::allow_negative_numbers
to make it clearer which arg it is meant to apply to (#β4187)
- (help) Deprecated
Command::write_help
and Command::write_long_help
in favor of Command::render_help
and Command::render_long_help
(#β4248)
- (derive)
structopt
and clap
attributes in favor of the more specific command
, arg
, and value
to open the door for more features and clarify relationship to the builder (#β1807, #β4180)
- (derive)
#[clap(value_parser)]
and #[clap(action)]
defaulted attributes (its the default) (#β3976)
Behavior Changes
- (help) With
wrap_help
feature, if the terminal size cannot be determined, LINES
and COLUMNS
variables are used (#β4186)
Features
Arg::num_args
now accepts ranges, allowing setting both the minimum and maximum number of values per occurrence (#β2688, #β4023)
- Allow non-bool
value_parser
s for ArgAction::SetTrue
/ ArgAction::SetFalse
(#β4092)
- Add
From<&OsStr>
, From<OsString>
, From<&str>
, and From<String>
to value_parser!
(#β4257)
- Allow resetting most builder methods
- Can now pass runtime generated data to
Command
, Arg
, ArgGroup
, PossibleValue
, etc without managing lifetimes with the string
feature flag (#β2150, #β4223)
- New default
error-context
, help
and usage
feature flags that can be turned off for smaller binaries (#β4236)
- Added
StyledStr::ansi()
to Display
with ANSI escape codes (#β4248)
- (error)
Error::apply
for changing the formatter for dropping binary size (#β4111)
- (error)
Error::render
for formatting the error into a StyledStr
- (help) Show
PossibleValue::help
in long help (--help
) (#β3312)
- (help) New
{tab}
variable for Command::help_template
(#β4161)
- (help)
Command::render_help
and Command::render_long_help
for formatting the error into a StyledStr
(#β3873, #β4248)
- (help)
Command::render_usage
now returns a StyledStr
(#β4248)
Fixes
- Verify
required
is not used with conditional required settings (#β3660)
- Replaced
cmd.allow_invalid_for_utf8_external_subcommands
with cmd.external_subcommand_value_parser
(#β3733)
Arg::default_missing_value
now applies per occurrence rather than if a value is missing across all occurrences (#β3998)
arg!(--long [value])
to accept 0..=1
per occurrence rather than across all occurrences, making it safe to use with ArgAction::Append
(#β4001)
- Allow
OsStr
s for Arg::{required_if_eq,required_if_eq_any,required_if_eq_all}
(#β4084)
- (help) With
wrap_help
feature, if the terminal size cannot be determined, LINES
and COLUMNS
variables are used (#β4186)
- (help) Use
Command::display_name
in the help title rather than Command::bin_name
- (help) Show when a flag is
ArgAction::Count
by adding an ...
(#β4003)
- (help) Use a more neutral palette for coloring (#β4132, #β4117)
- (help) Don't rely on ALL CAPS for help headers (#β4132, #β4123)
- (help) List subcommands first, focusing the emphasis on them (#β4132, #β4125)
- (help) Do not include global args in
cmd help help
(#β4131)
- (help) Use
[positional]
in list when relevant (#β4144)
- (help) Show all
[positional]
in usage (#β4151)
- (help) Polish up subcommands by referring to them as commands (#β4132, #β4155)
- (help) Trim extra whitespace to avoid artifacts from different uses of templates (#β4132, #β4156)
- (help) Hint to the user the difference between
-h
/ --help
when applicable (#β4132, #β4159)
- (help) Shorten help by eliding name/version/author (#β4132, #β4160)
- (help) When short help is long enough to activate
next_line_help
, don't add blank lines (#β4132, #β4190)
- (help) Make help output more dense (reducing horizontal whitespace) (#β4132, #β4192)
- (help) Separate subcommand flags with "," like option flags (#β4232, #β4235)
- (help) Quote the suggested help flag (#β4220)
- (version) Use
Command::display_name
rather than Command::bin_name
(#β3966)
- (parser) Always fill in
""
argument for external subcommands (#β3263)
- (parser) Short flags now have higher precedence than hyphen values with
Arg::allow_hyphen_values
, like Command::allow_hyphen_values
(#β4187)
- (parser) Prefer
InvalidSubcommand
over UnknownArgument
in more cases (#β4219)
- (derive) Detect escaped external subcommands that look like built-in subcommands (#β3703)
- (derive) Leave
Arg::id
as verbatim
casing (#β3282)
- (derive) Default to
#[clap(value_parser, action)]
instead of #[clap(parse)]
(#β3827)
Compare Source
[3.2.22] - 2022-09-16
Fixes
- Unify dependencies on
terminal_size
to the 0.2 release
Compare Source
[3.2.21] - 2022-09-12
Features
TypedValueParser::map
to allow reusing existing value parsers for other purposes
Compare Source
[3.2.20] - 2022-09-02
Features
ArgMatches::get_count
help for ArgAction::Count
ArgMatches::get_flag
help for ArgAction::SetTrue
/ ArgAction::SetFalse
Compare Source
[3.2.19] - 2022-08-30
Fixes
- (help) Ensure required arguments for parent commands aren't shown in their subcommands when using
args_conflicts_with_subcommand
Compare Source
Fixes
- (help)
Command::print_help
now respects Command::colored_help
- (derive) Improved error messages
Compare Source
Fixes
- (derive) Expose
#[clap(id = ...)]
attribute to match Arg's latest API
Compare Source
Fixes
- Ensure required arguments appear in errors when they are also members of a group (#β4004)
Compare Source
Features
- (derive) New
default_values_t
and default_values_os_t
attributes
Compare Source
Fixes
- A
multiple_values
positional followed by another positional now works with multiple flags
Compare Source
Documentation
- Pulled in tutorials, cookbook, and derive reference into rustdoc
Compare Source
Fixes
- Allow an arg to declare a conflict with a group
Compare Source
Features
- Added
Arg::get_all_short_aliaes
and Arg::get_all_aliases
Compare Source
Fixes
- Loosen lifetime on
Command::mut_subcommand
Compare Source
Features
- Added
Command::mut_subcommand
to mirror Command::mut_arg
Compare Source
Fixes
- Global arguments should override env-sourced arguments
Compare Source
Fixes
- Don't panic when parsing
--=
Compare Source
Fixes
- (derive) Fix regression with
#[clap(default_value_os_t ...)]
introduced in v3.2.3
Compare Source
Fixes
- (derive) Provide more clearer deprecation messages for
#[clap(parse)]
attribute (#β3832)
Compare Source
Fixes
- Moved deprecations to be behind the
deprecated
Cargo.toml feature (#β3830)
- For now, it is disabled by default though we are considering enabling it by
default as we release the next major version to help draw attention to the
deprecation migration path
Compare Source
Fixes
- (derive) Improve the highlighted code for deprecation warnings
gated behind unstable-v4
- (derive) Default to
#[clap(value_parser, action)]
instead of #[clap(parse)]
(#β3827)
Compare Source
Fixes
- (help)
Command::print_help
now respects Command::colored_help
- (derive) Improved error messages
Compare Source
Compatibility
MSRV is now 1.56.0 (#β3732)
Behavior
- Defaults no longer satisfy
required
and its variants (#β3793)
- When misusing
ArgMatches::value_of
and friends, debug asserts were turned into panics
Moving (old location deprecated)
clap::{PossibleValue, ValueHint}
to clap::builder::{PossibleValue, ValueHint}
clap::{Indices, OsValues, ValueSource, Values}
to clap::parser::{Indices, OsValues, ValueSource, Values}
clap::ArgEnum
to clap::ValueEnum
(#β3799)
Replaced
Arg::allow_invalid_utf8
with Arg::value_parser(value_parser!(PathBuf))
(#β3753)
Arg::validator
/ Arg::validator_os
with Arg::value_parser
(#β3753)
Arg::validator_regex
with users providing their own builder::TypedValueParser
(#β3756)
Arg::forbid_empty_values
with builder::NonEmptyStringValueParser
/ builder::PathBufValueParser
(#β3753)
Arg::possible_values
with Arg::value_parser([...])
, builder::PossibleValuesParser
, or builder::EnumValueParser
(#β3753)
Arg::max_occurrences
with arg.action(ArgAction::Count).value_parser(value_parser!(u8).range(..N))
for flags (#β3797)
Arg::multiple_occurrences
with ArgAction::Append
or ArgAction::Count
though positionals will need Arg::multiple_values
(#β3772, #β3797)
Command::args_override_self
with ArgAction::Set
(#β2627, #β3797)
AppSettings::NoAutoVersion
with ArgAction
or Command::disable_version_flag
(#β3800)
AppSettings::NoHelpVersion
with ArgAction
or Command::disable_help_flag
/ Command::disable_help_subcommand
(#β3800)
ArgMatches::{value_of, value_of_os, value_of_os_lossy, value_of_t}
with ArgMatches::{get_one,remove_one}
(#β3753)
ArgMatches::{values_of, values_of_os, values_of_os_lossy, values_of_t}
with ArgMatches::{get_many,remove_many}
(#β3753)
ArgMatches::is_valid_arg
with ArgMatches::{try_get_one,try_get_many}
(#β3753)
ArgMatches::occurrences_of
with ArgMatches::value_source
or ArgAction::Count
(#β3797)
ArgMatches::is_present
with ArgMatches::contains_id
or ArgAction::SetTrue
(#β3797)
ArgAction::StoreValue
with ArgAction::Set
or ArgAction::Append
(#β3797)
ArgAction::IncOccurrences
with ArgAction::SetTrue
or ArgAction::Count
(#β3797)
- (derive)
#[clap(parse(...))]
replaced with: (#β3589, #β3794)
- For default parsers (no
parse
attribute), deprecation warnings can be
silenced by opting into the new behavior by adding either #[clap(action)]
or #[clap(value_parser)]
(ie requesting the default behavior for these
attributes). Alternatively, the unstable-v4
feature changes the default
away from parse
to action
/value_parser
.
- For
#[clap(parse(from_flag))]
replaced with #[clap(action = ArgAction::SetTrue)]
(#β3794)
- For
#[clap(parse(from_occurrences))]
replaced with #[clap(action = ArgAction::Count)]
though the field's type must be u8
(#β3794)
- For
#[clap(parse(from_os_str)]
for PathBuf
, replace it with
#[clap(value_parser)]
(as mentioned earlier this will call
value_parser!(PathBuf)
which will auto-select the right ValueParser
automatically).
- For
#[clap(parse(try_from_str = ...)]
, replace it with #[clap(value_parser = ...)]
- For most other cases, a type implementing
TypedValueParser
will be needed and specify it with #[clap(value_parser = ...)]
Features
- Parsed, typed arguments via
Arg::value_parser
/ ArgMatches::{get_one,get_many}
(#β2683, #β3732)
- Several built-in
TypedValueParser
s available with an API open for expansion
value_parser!(T)
macro for selecting a parser for a given type (#β3732) and open to expansion via the ValueParserFactory
trait (#β3755)
[&str]
is implicitly a value parser for possible values
- All
ArgMatches
getters do not assume required arguments (#β2505)
- Add
ArgMatches::remove_*
variants to transfer ownership
- Add
ArgMatches::try_*
variants to avoid panics for developer errors (#β3621)
- Add a
get_raw
to access the underlying OsStr
s
PathBuf
value parsers imply ValueHint::AnyPath
for completions (#β3732)
- Explicit control over parsing via
Arg::action
(#β3774)
ArgAction::StoreValue
: existing takes_value(true)
behavior
ArgAction::IncOccurrences
: existing takes_value(false)
behavior
ArgAction::Help
: existing --help
behavior
ArgAction::Version
: existing --version
behavior
ArgAction::Set
: Overwrite existing values (like Arg::multiple_occurrences
mixed with Command::args_override_self
) (#β3777)
ArgAction::Append
: like Arg::multiple_occurrences
(#β3777)
ArgAction::SetTrue
: Treat --flag
as --flag=true
(#β3775)
- Implies
Arg::default_value("false")
(#β3786)
- Parses
Arg::env
via Arg::value_parser
ArgAction::SetFalse
: Treat --flag
as --flag=false
(#β3775)
- Implies
Arg::default_value("true")
(#β3786)
- Parses
Arg::env
via Arg::value_parser
ArgAction::Count
: Treat --flag --flag --flag
as --flag=1 --flag=2 --flag=3
(#β3775)
- Implies
Arg::default_value("0")
(#β3786)
- Parses
Arg::env
via Arg::value_parser
- (derive) Opt-in to new
Arg::value_parser
/ Arg::action
with either #[clap(value_parser)]
(#β3589, #β3742) / #[clap(action)]
attributes (#β3794)
- Default
ValueParser
is determined by value_parser!
(#β3199, #β3496)
- Default
ArgAction
is determine by a hard-coded lookup on the type (#β3794)
Command::multicall
is now stable for busybox-like programs and REPLs (#β2861, #β3684)
ArgMatches::{try_,}contains_id
for checking if there are values for an argument that mirrors the new get_{one,many}
API
Fixes
- Don't correct argument id in
default_value_ifs_os
(#β3815)
parser
- Set
ArgMatches::value_source
and ArgMatches::occurrences_of
for external subcommands (#β3732)
- Use value delimiter for
Arg::default_missing_values
(#β3761, #β3765)
- Split
Arg::default_value
/ Arg::env
on value delimiters independent of whether --
was used (#β3765)
- Allow applying defaults to flags (#β3294, 3775)
- Defaults no longer satisfy
required
and its variants (#β3793)
Compare Source
Fixes
- Fix deprecated
arg_enum!
for users migrating to clap3 (#β3717)
- Verify all
required_unless_present_all
arguments exist
- Verify group members exist before processing group members (#β3711)
- (help) Use
...
when not enough value_names
are supplied
gated behind unstable-v4
- Verify
required
is not used with conditional required settings (#β3660)
- Disallow more
value_names
than number_of_values
(#β2695)
- (parser) Assert on unknown args when using external subcommands (#β3703)
- (parser) Always fill in
""
argument for external subcommands (#β3263)
- (derive) Detect escaped external subcommands that look like built-in subcommands (#β3703)
- (derive) Leave
Arg::id
as verbatim
casing (#β3282)
Compare Source
Fixes
- Allow value names for
arg!
macro to have dashes when quoted, like longs
Compare Source
Fixes
- (parser)
Arg::exclusive
overrides Arg::required
, like other conflicts
- (error) Don't duplicate arguments in usage
- (error) Don't show hidden arguments in conflict error usage
- (help) New
help_template
variable {name}
to fix problems with {bin}
- (help) Don't wrap URLs
gated behind unstable-v4
- Leading dashes in
Arg::long
are no longer allowed
- (help) Use
Command::display_name
in the help title rather than Command::bin_name
Compare Source
Fixes
- (error) Render actual usage for unrecognized subcommands
- (multicall) Improve bad command error
- (multicall) Always require a multicall command
- (multicall) Disallow arguments on multicall parent command
- (multicall) More consistent with rest of clap errors
Compare Source
Fixes
- Panic when calling
Command::build
with a required positional argument nested several layers in subcommands
Compare Source
Fixes
- Help subcommand and
Command::write_help
now report required arguments in usage in more circumstances
- Unknown subcommand for help subcommand flag now reports an error with more context
- More details reported when using
debug
feature
- Allow disabling
color
feature with debug
feature enabled
Compare Source
Fixes
- Regression in 3.1.11 where the (output) streams were crossed
Compare Source
Fixes
- Implied conflicts override
Arg::required
, making the behavior consistent with how we calculate conflicts for error reporting
- Members of a mutually exclusive
ArgGroup
override Arg::required
, making the behavior consistent with how we calculate conflicts for error reporting
Arg::overrides_with
always override Arg::required
, not just when the parser processes an override
Compare Source
Features
- Expose
Command::build
for custom help generation or other command introspection needs
Compare Source
Fixes
- Pin the
clap_derive
version so a compatible version is always used with clap
Compare Source
Fixes
- Add
Debug
impls to more types
Compare Source
Fixes
- (derive) Abort, rather than ignore, when deriving
ArgEnum
with non-unit unskipped variants
Compare Source
Fixes
- Don't panic when validating delimited defaults (#β3541)
- Make it clearer that
cargo
feature is needed
- Documentation improvements
Compare Source
Fixes
Compare Source
Features
- (help) Show
PossibleValue::help
in long help (--help
) (gated behind unstable-v4
) (#β3312)
Compare Source
Fixes
- Don't panic when validating delimited defaults (#β3514)
Compare Source
Fixes
- (derive) Allow other attribute with a subcommand that has subcommands
Documentation
- (examples) List example topics
- (derive) Clarify syntax and relation to builder API
Compare Source
Fixes
- Fix deprecated
arg_enum!
for users migrating to clap3 (#β3717)
- Verify all
required_unless_present_all
arguments exist
- Verify group members exist before processing group members (#β3711)
- (help) Use
...
when not enough value_names
are supplied
gated behind unstable-v4
- Verify
required
is not used with conditional required settings (#β3660)
- Disallow more
value_names
than number_of_values
(#β2695)
- (parser) Assert on unknown args when using external subcommands (#β3703)
- (parser) Always fill in
""
argument for external subcommands (#β3263)
- (derive) Detect escaped external subcommands that look like built-in subcommands (#β3703)
- (derive) Leave
Arg::id
as verbatim
casing (#β3282)
Compare Source
Compatibility
Changes in behavior of note that are not guaranteed to be compatible across releases:
- (help)
help
subcommand shows long help like --help
, rather than short help (-h
), deprecated clap::AppSettings::UseLongFormatForHelpSubcommand
(#β3440)
- (help) Pacman-style subcommands are now ordered the same as usage errors (#β3470)
- (help) Pacman-style subcommands use standard alternate syntax in usage (#β3470)
Deprecations
clap::Command
is now preferred over clap::App
([#β3089](ht
Configuration
π
Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).
π¦ Automerge: Disabled by config. Please merge this manually once you are satisfied.
β» Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
π Ignore: Close this PR and you won't be reminded about this update again.
- [ ] If you want to rebase/retry this PR, click this checkbox.
This PR has been generated by Mend Renovate. View repository job log here.