You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix inconsistency in precedence between positionals with a value_terminator("--") and escapes (--) where ./foo -- bar means the first arg is empty, rather than escaping future args
(derive)long_about and long_help attributes, without a value, force using doc comment (before it wouldn't be set if there wasn't anything different than the short help)
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.
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.
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
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.
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 Args 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 Strings (#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_
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, check this box
renovatebot
changed the title
fix(deps): update rust crate clap to v4
Update Rust crate clap to v4
Feb 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains the following updates:
3→4Release Notes
clap-rs/clap (clap)
v4.5.57Compare Source
v4.5.56Compare Source
Fixes
v4.5.55Compare Source
Fixes
value_terminator("--")and escapes (--) where./foo -- barmeans the first arg is empty, rather than escaping future argsv4.5.54Compare Source
Fixes
[default]to its own paragraph whenPossibleValue::helpis present in--helpv4.5.53Compare Source
Features
default_values_if,default_values_ifsv4.5.52Compare Source
Fixes
args_conflicts_with_subcommandsconflicts with anArgGroupv4.5.51Compare Source
Fixes
ArgAction::Countv4.5.50Compare Source
Features
CowwhereStringand&strare acceptedv4.5.49Compare Source
Fixes
v4.5.48Compare Source
Documentation
typed_derivecookbook entryv4.5.47Compare Source
Features
impl FromArgMatches for ()impl Args for ()impl Subcommand for ()impl FromArgMatches for Infallibleimpl Subcommand for InfallibleFixes
clapv4.5.46Compare Source
Features
StyledStr::push_strv4.5.45Compare Source
Fixes
ValueEnumvariants now use the full doc comment, not summary, forPossibleValue::helpv4.5.44Compare Source
Features
Command::mut_subcommandsv4.5.43Compare Source
Fixes
v4.5.42Compare Source
Fixes
--helpv4.5.41Compare Source
Features
Styles::contextandStyles::context_valueto customize the styling of[default: value]like notes in the--helpv4.5.40Compare Source
Features
arg!()macro (e.g.arg!("check-config": ...))v4.5.39Compare Source
Fixes
v4.5.38Compare Source
Fixes
--or-v4.5.37Compare Source
Features
ArgMatches::try_clear_id()v4.5.36Compare Source
Fixes
v4.5.35Compare Source
Fixes
help_headingv4.5.34Compare Source
Fixes
flatten_help(true)and subcommands without argumentsv4.5.33Compare Source
Fixes
v4.5.32Compare Source
Features
Error::removeDocumentation
humantimetojiffInternal
pulldown-cmarkv4.5.31Compare Source
Features
ValueParserFactoryforSaturating<T>v4.5.30Compare Source
Fixes
num_args(0..=1)to be used withSetTruetakes_valuesassertionsv4.5.29Compare Source
Fixes
ArgMatches::args_presentso not-present flags are considered not-present (matching the documentation)v4.5.28Compare Source
Features
unstable-markdownv4.5.27Compare Source
Documentation
v4.5.26Compare Source
Fixes
suggestionsfeaturev4.5.25Compare Source
Fixes
v4.5.24Compare Source
Fixes
ignore_errors(true)and when a suggestion is provided for an unknown argumentv4.5.23Compare Source
Fixes
allow_negative_numbers, allowEagainv4.5.22Compare Source
Fixes
v4.5.21Compare Source
Fixes
ignore_errors(true)v4.5.20Compare Source
Features
CommandExtv4.5.19Compare Source
Internal
v4.5.18Compare Source
Features
Arg::get_display_orderandCommand::get_display_orderv4.5.17Compare Source
Fixes
v4.5.16Compare Source
Fixes
derivefeature is missingv4.5.15Compare Source
Compatiblity
Arg::removechanged return typesFixes
Arg::removereturn the removed itemv4.5.14Compare Source
Features
Arg::addfor attaching arbitrary state, like completion hints, toArgwithoutArgknowing about itv4.5.13Compare Source
Fixes
#[flatten]ing an optional#[group(skip)]v4.5.12Compare Source
v4.5.11Compare Source
v4.5.10Compare Source
v4.5.9Compare Source
Fixes
v4.5.8Compare Source
Fixes
v4.5.7Compare Source
Fixes
num_argsv4.5.6Compare Source
v4.5.5Compare Source
Fixes
[default]to its own paragraph whenPossibleValue::helpis present in--helpv4.5.4Compare Source
Fixes
v4.5.3Compare Source
Fixes
v4.5.2Compare Source
Fixes
ArgMatches::args_presentso not-present flags are considered not-present (matching the documentation)v4.5.1Compare Source
Internal
v4.5.0Compare Source
Compatibility
v4.4.18Compare Source
Fixes
usagefeature, ensure the list of required arguments is uniquev4.4.17Compare Source
Fixes
panic!when mixingargs_conflicts_with_subcommandswithArgGroup(which is implicit withderive) introduced in 4.4.15v4.4.16Compare Source
Fixes
v4.4.15Compare Source
Fixes
args_conflicts_with_subcommandsargs_conflicts_with_subcommandswhen using subcommand short and long flagsv4.4.14Compare Source
Documentation
findcookbook entry to allow repeats of flags/optionsFeatures
num_args(0)on options which allows making them emulate being a flag for position-tracking flagsv4.4.13Compare Source
Documentation
v4.4.12Compare Source
Performance
TypedValueParserfor possible values if neededv4.4.11Compare Source
Features
Command::mut_groupv4.4.10Compare Source
Documentation
v4.4.9Compare Source
Fixes
Command::aboutunder flattened headingshidewhen flattening subcommandsv4.4.8Compare Source
Features
Command::flatten_helpto allowgit stash -hlike help for subcommandsv4.4.7Compare Source
Performance
v4.4.6Compare Source
Internal
anstreamv4.4.5Compare Source
Fixes
nameorlong_flag, allow ambiguous-looking matches that unambiguously map back to the same commandlong_flag, don't panicv4.4.4Compare Source
Internal
terminal_sizeto 0.3v4.4.3Compare Source
Documentation
v4.4.2Compare Source
Performance
once_celldependencyv4.4.1Compare Source
Fixes
usagefeature, ensure the list of required arguments is uniquev4.4.0Compare Source
compatibility
v4.3.24Compare Source
Fixes
--helpwith custom templatesv4.3.23Compare Source
Fixes
UnknownArgumentValueParserto not error on flag's absencev4.3.22Compare Source
Features
UnknownArgumentValueParserfor injecting errors for improving the experience with errorsv4.3.21Compare Source
Features
TryMapValueParserso the type can be namedv4.3.20Compare Source
Features
Command::mut_argsfor modifying all arguments en massev4.3.19Compare Source
Fixes
value_terminatoreven in the presence of later multiple-value positional argumentsv4.3.18Compare Source
Fixes
--in fewer places where it won't workv4.3.17Compare Source
Fixes
PossibleValuedescriptions in--helpv4.3.16Compare Source
Fixes
v4.3.15Compare Source
Features
anstyleDocumentation
v4.3.14Compare Source
Features
ArgAction::HelpShortandArgAction::HelpLongfor explicitly specifying which style of help to displayFixes
[OPTIONS]in usage if a help or versionArgActionis usedv4.3.13Compare Source
v4.3.12Compare Source
Fixes
v4.3.11Compare Source
Features
num::Wrapping,Box, orArcBox<str>,Box<OsStr>, andBox<Path>v4.3.10Compare Source
Performance
v4.3.9Compare Source
Fixes
Command::ignore_errorsno longer masks help/versionv4.3.8Compare Source
Fixes
infer_long_arg, rather than arbitrarily picking one, matching the documentation and subcommand's behaviorv4.3.7Compare Source
Documentation
v4.3.6Compare Source
Documentation
cliov4.3.5Compare Source
ColorChoice::possible_valuesis added to simplify things for builder usersFixes
ColorChoice::to_possible_valueno longer includes descriptions, encouraging shorter help where possiblev4.3.4Compare Source
Features
Error::exit_codev4.3.3Compare Source
Features
Command::deferfor delayed initialization of subcommands to reduce startup times of large applications like denov4.3.2Compare Source
Fixes
--helpwith custom templatesv4.3.1Compare Source
Fixes
value_terminatoreven in the presence of later multiple-value positional argumentsv4.3.0Compare Source
Fixes
lastassertionvalue_terminatorhas higher precedence thanallow_hyphen_values--helpv4.2.7Compare Source
Fixes
ArgMatchesv4.2.6Compare Source
Features
impl Eq<std::any::TypeId> for clap_builder::util::AnyValueIdv4.2.5Compare Source
Fixes
v4.2.4Compare Source
Documentation
Command::stylev4.2.3Compare Source
Features
Command::stylesfor theming help/errors (behindunstable-styles)v4.2.2Compare Source
Internal
v4.2.1Compare Source
Fixes
v4.2.0Compare Source
Compatibility
unstable-replacefeature (open to discussion at #2836)unstable-groupedfeatureFeatures
StyledStrto accept text styled with ANSI escape codesCLICOLOR,CLICOLOR_FORCEFixes
v4.1.14Compare Source
Features
#[group]raw attribute supportPerformance
clap_builderwas pulled out ofclapso it could build in parallel toclap_deriveos_str_bytesdependency was removed for faster builds and smaller binariesv4.1.13Compare Source
Performance
Commandv4.1.12Compare Source
Internal
synv2Performance
proc-macro-errordependencyv4.1.11Compare Source
Internal
bitflagsv4.1.10Compare Source
Fixes
v4.1.9Compare Source
Fixes
get_count/get_flagv4.1.8Compare Source
Fixes
denylints on the users behalfv4.1.7Compare Source
Fixes
v4.1.6Compare Source
Fixes
--helpjust because hidden possible values include a descriptionv4.1.5Compare Source
Fixes
--helpjust because a hidden arg has a possible value with a descriptionv4.1.4Compare Source
Fixes
disable_colored_helpwhen usingarg_required_else_helpPerformance
arg!macrov4.1.3Compare Source
Fixes
subcommands, rather thansubcommandv4.1.2Compare Source
Fixes
get_flag, rather thanget_one::<bool>v4.1.1Compare Source
Features
#[group]raw attribute supportPerformance
clap_builderwas pulled out ofclapso it could build in parallel toclap_deriveos_str_bytesdependency was removed for faster builds and smaller binariesv4.1.0Compare Source
Compatibility
MSRV changed to 1.64.0
For apps with custom
--helpand--versionflags:--helpand--versionchangedWhen apps have errors imitating clap's error style:
Features
ArgMatches::get_occurrencessupport for argument values to be grouped by their occurrenceFixes
upgrade_fromwhen arguments / subcommands are explicitly marked as required--helpand--version(also helps with overflow)v4.0.32Compare Source
Fixes
required(true), consider args that conflict with its groupv4.0.31Compare Source
Performance
v4.0.30Compare Source
Fixes
args_conflicts_with_subcommandv4.0.29Compare Source
v4.0.28Compare Source
Fixes
v4.0.27Compare Source
Features
Arg::value_parseracceptVec<impl Into<PossibleValue>>DisplayandFromStrforColorChoiceFixes
attytois-terminalv4.0.26Compare Source
Fixes
ContextKind::as_strv4.0.25Compare Source
Features
v4.0.24Compare Source
Fixes
v4.0.23Compare Source
Fixes
helpsubcommandv4.0.22Compare Source
Fixes
v4.0.21Compare Source
Features
long_aboutandlong_helpattributes, without a value, force using doc comment (before it wouldn't be set if there wasn't anything different than the short help)v4.0.20Compare Source
Fixes
v4.0.19Compare Source
Features
ColorChoicenow implementsValueEnumv4.0.18Compare Source
Fixes
#[command(skip)]to also work with enum variants with a valuev4.0.17Compare Source
Fixes
Arg::last(true)withArg::value_hint(ValueHint::CommandWithArguments)v4.0.16Compare Source
Fixes
Arg::exclusive(true)should not be exclusive with the argument's ownArgGroupv4.0.15Compare Source
Fixes
--when it doesn't helpv4.0.14Compare Source
Fixes
ArgGroupinArgMatcheswhen explicitly specified, fixing derives handling of option-flattened fields (#4375)v4.0.13Compare Source
Features
()for fields to mean "don't read" (#4371)v4.0.12Compare Source
Features
TypedValueParser::try_mapfor when adapting an existingTypedValueParsercan failError::new,Error::with_cmd, andError::insertv4.0.11Compare Source
Fixes
v4.0.10Compare Source
Features
#[arg(flatten)]onOptiontypes (#4211, #4350)v4.0.9Compare Source
Fixes
#[command(subcommand)]like in clap v3v4.0.8Compare Source
Fixes
HelpandVersionactionsv4.0.7Compare Source
Features
Fixes
#[group(skip)]onParserderivev4.0.6Compare Source
Features
#[group(skip)](#4279, #4301)v4.0.5Compare Source
v4.0.4Compare Source
Fixes
v4.0.3Compare Source
Fixes
required(true), consider args that conflict with its groupv4.0.2Compare Source
v4.0.1Compare Source
Features
ColorChoicenow implementsValueEnumv4.0.0Compare 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_argswhich accepts bothsingle values and ranges of values.
num_argscontrols how many raw argumentson 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
--helpoutput to make sure it ismeeting that goal.
In doing this evaluation, we wanted to keep in mind:
Before:
After:
--versionis available for showing the same thing (if the program has a version set)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
&strfor performance but this can makedealing with owned data difficult, like
#[arg(default_value_t)]generating aString from the default value.
Additionally, to avoid
ArgMatchesfrom borrowing (and for some features wedecided to forgo), clap took the
&strargument IDs and hashed them. Thisprevented 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, orBox<str>for dynamic behavior with small binary size.As an extension of that work, you can now call
ArgMatches::idsto iterateover the arguments and groups that were found when parsing. The newtype
Idwas 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:
ArgActionValueParserAPIPathBuf(allowing invalid UTF-8)AppSettingsandArgSettingsenums with getters/settersMigrating
Steps:
-hand--helpoutput at a minimum (recommendation: trycmd for snapshot testing)arg.action(ArgAction::...)on each argument (StoreValuefor options andIncOccurrencesfor flags)cargo check --features clap/deprecatedand resolve all deprecation warningsdefault-features = false, runcargo add clap -F help,usage,error-contextcargo add clap -F wrap_helpunless you want to hard code line wrapsExample test (derive):
Example test (builder):
Note: the idiomatic / recommended way of specifying different types of args in the Builder API has changed:
Before
After:
In particular,
num_args(the replacement fortakes_value) will default appropriatelyfrom the
ArgActionand generally only needs to be set explicitly for theother
num_argsuse cases.Breaking Changes
Subtle changes (i.e. compiler won't catch):
arg!now sets one of (#3795):ArgAction::SetTrue, requiringArgMatches::get_flaginstead ofArgMatches::is_presentArgAction::Count, requiringArgMatches::get_countinstead ofArgMatches::occurrences_ofArgAction::Set, requiringArgMatches::get_oneinstead ofArgMatches::value_ofArgAction::Append, requiringArgMatches::get_manyinstead ofArgMatches::values_ofArgAction::Set,ArgAction::SetTrue, andArg::Action::SetFalsenowconflict by default to be like
ArgAction::StoreValueandArgAction::IncOccurrences, requiringcmd.args_override_self(true)to override instead (#4261)Args default action isArgAction::Set, rather thanArgAction::IncOccurrenceto reduce confusing magic through consistency (#2687, #4032, see also #3977)mut_argcan 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)Command,Arg,ArgGroup, andPossibleValue, assuming'static.stringfeature flag will enable support forStrings (#1041, #2150, #4223)arg!(--flag <value>)is now optional, instead of required. Add.required(true)at the end to restore the original behavior (#4206)help,usageanderror-context, requiring adding them back in ifdefault-features = false(#4236)""argument for external subcommands to make it easier to distinguish them from built-in commands (#3263)Arg::allow_hyphen_values, to be consistent withCommand::allow_hyphen_values(#4187)Arg::value_terminatormust be its own argument on the CLI rather than being in a delimited list (#4025)wrap_helpfeature flag, either enable it or hard code your wraps (#4258)DeriveDisplayOrderthe default and removed the setting. To sort help, setnext_display_order(None)(#2808)Command::next_display_orderinstead ofDeriveDisplayOrderand using its own initial display order value (#2808)Command::help_template(#4132)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.
This PR was generated by Mend Renovate. View the repository job log.