cargo / clap
clap
What changed in clap 3 to 4, from its official release notes, upgrade guides and advisories. Sources checked 2026-11-25.
82 breaking11 deprecations48 new APIs and options6 behavior and defaults15 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli initclap 471 changes
Breaking changes 30
Fixes precedence between positionals using value_terminator("--") and escapes, so
./foo -- bartreats the first argument as empty rather than escaping future arguments.Its default value type changed from
StringtoOsString.Short flags now take precedence over hyphen values when this argument setting is used.
Applies per occurrence rather than when a value is missing across all occurrences.
The derive attribute was removed in favor of
value_enum.Use
Arg::num_args(1..=M)to set a maximum per occurrence.Use
Arg::num_args(N..)to set a minimum per occurrence.Use
Arg::num_argswith a range instead.Replaces several value-count APIs and controls the number of raw command-line arguments captured per occurrence; it accepts single values and ranges.
Removed; use
Arg::value_delimiteror implement a custom parser withTypedValueParser.Use
Arg::num_args(1)orArg::num_args(0)instead.Use this derive attribute in place of the removed
arg_enumattribute.Derives now default to
value_parserinstead ofparse;parsesupport was removed.The terminator must now be its own command-line argument rather than appearing in a delimited list.
The macro now assigns an action based on argument form; use the corresponding
ArgMatchesgetter for the resulting action.An argument's default action is now
ArgAction::Setrather thanArgAction::IncOccurrence.Use this instead of
ArgMatches::occurrences_offor arguments whose action isArgAction::Count.Use this instead of
ArgMatches::is_presentfor flags whose action isArgAction::SetTrue.Use this instead of
ArgMatches::values_offor arguments whose action isArgAction::Append.Use this instead of
ArgMatches::value_offor arguments whose action isArgAction::Set.Set this to
trueto allow self-overrides forArgAction::Set,ArgAction::SetTrue, andArgAction::SetFalse, which now conflict by default.Lifetimes were removed from
Command,Arg,ArgGroup, andPossibleValue, assuming'staticunless thestringfeature is enabled.Now returns a
StyledStr.Replaced with
ErrorKind::InvalidValue.Replaces
ErrorKind::UnrecognizedSubcommand.Replaced with
ErrorKind::InvalidSubcommand.Moved into the
errormodule.The minimum supported Rust version is now 1.60.0.
Replaces various one-off value-validation forms and allows derives to handle
PathBuf, including invalid UTF-8.Help line wrapping is behind this feature flag; enable it or hard-code line wraps.
Deprecations 8
Deprecated in favor of
Arg::env.Deprecated in favor of
Arg::num_args, whose per-occurrence semantics differ from the old API.Deprecated in favor of
Arg::value_delimiter.Deprecated in favor of
Arg::allow_hyphen_values.Deprecated in favor of
Arg::allow_negative_numbers.Deprecated in favor of
Arg::trailing_var_arg.Deprecated in favor of
Command::render_help.Deprecated in favor of
Command::render_long_help.
New APIs and options 17
Adds the defer attribute to opt in to lazy initialisation of subcommands.
Adds the get_overridden_usage method to Command.
Adds default_values_if for conditionally setting default values.
Adds default_values_ifs for conditionally setting default values.
Iterates over the arguments and groups found when parsing.
Use this to disable the built-in help flag when providing a custom one.
Use this to disable the built-in version flag when providing a custom one.
Supports the new
{tab}variable.Formats help into a
StyledStr.Formats long help into a
StyledStr.Changes the formatter for dropping binary size.
Formats an error into a
StyledStr.A new default feature flag that can be turned off for smaller binaries.
A string newtype used for argument IDs, distinguishing opaque IDs from user-visible strings.
Enables support for
Strings and runtime-generated data without managing lifetimes.Displays a
StyledStrwith ANSI escape codes.Now implements conversions from
OsStr,OsString,str, andString.
Behavior and default changes 3
Accept Cow where String and &str are accepted, allowing callers to use a copy-on-write string type.
Builder API users should explicitly set an action for each argument; options use
StoreValueand flags useIncOccurrences.Help output is denser, uses title-case headings and lists commands before arguments; the name, version, and author are omitted by default.
Fixes and other changes 13
Help output now correctly marks which value_names are optional according to num_args.
The derive macro now allows "literal".function() as an attribute value.
Help output says “alias” when there is only one.
Rebuilds now happen when a read environment variable changes.
Empty default values and possible values are now quoted in help output.
Command::ignore_errors no longer masks help or version on subcommands.
Fixed problems with an argument using value_terminator("--") when another argument uses last(true).
Conflicting arguments are no longer shown in the usage on conflict errors.
When PossibleValue::help is present, [default] appears in its own paragraph in --help output.
Avoids panicking when args_conflicts_with_subcommands conflicts with an ArgGroup.
Help output no longer panics on short flags using ArgAction::Count.
Help output now correctly calculates padding for short flags that take a value.
The help title and version output now use
Command::display_namerather thanCommand::bin_name.
clap 391 changes
Breaking changes 52
Provides the replacement for
ArgMatches::usage.No longer implies a leading tab, allowing multi lined usages.
Now returns
std::io::Result.Removed; use
app_from_crateinstead.Some App methods, including this one, now take mutable self instead of shared self; it also returns
std::io::Result.Removed.
Opts out of the new default colored-help behavior.
Enables debug assertions that detect missing help descriptions.
Removed because propagating global values down is now the default.
Strict UTF-8 behavior is now the default and asserts unless the documented invalid-UTF-8 settings and OS-value accessor are used together.
Unified help grouping is now the default;
{flags}and{unified}assert if present inApp::help_template.No longer implies
ArgSettings::TakesValue.Replaced by the more specific
Arg::multiple_valuesandArg::multiple_occurrencesAPIs.Specifies that an argument can occur multiple times.
Specifies that an argument accepts multiple values.
No longer implies
ArgSettings::TakesValueorArgSettings::UseValueDelimiter.No longer implies
ArgSettings::ForbidEmptyValues.Sets settings using
Arg::setting(Setting1 | Setting2).Replaced with
Arg::settingusing a setting expression.Now takes a char instead of a string slice.
Now accepts a string-slice input and a result with a displayable error type.
Now accepts a result with an OS-string error instead of requiring a unit success value.
Now sets the value name rather than appending it.
The BTreeMap conversion was replaced with conversion from YAML.
Panics on unknown arguments.
No longer checks subcommand names.
Now returns
Option<(&str, &ArgMatches)>.Replaced with
App::generate_usage.Removed in favor of
ArgSettings::ForbidEmptyValues.Crate information support is gated behind the cargo feature flag.
Completion generation has been split out into a separate crate.
Integrates the StructOpt derive approach through clap::Parser; requires the derive feature.
The derive attribute is replaced by
default_value_t.Replaces the derive attribute
default_value.Environment-variable support is gated behind the env feature flag.
Environment support is a non-default feature for faster builds and smaller binaries.
Some environment-variable values are now treated as false for flags, not only as absent.
Now has type
Vec<String>instead ofOption<Vec<String>>.Made private; use
Error::to_string.Marked non-exhaustive.
New name for
ErrorKind::MissingArgumentOrSubcommand.Renamed to
ErrorKind::DisplayHelp.Renamed to
ErrorKind::DisplayHelpOnMissingArgumentOrSubcommand.Renamed to
ErrorKind::DisplayVersion.Default help text wrapping is limited to 100 when the wrap_help feature is disabled.
The minimum required Rust compiler version is 1.54.0.
When using no-default-features, enable the std feature.
By default, the App is no longer initialized with crate information; opt in with the author, about, or version attributes.
Nested subcommands now require a
#[clap(subcommand)]attribute.Unicode support is a non-default feature, enabling faster builds and smaller binaries for ASCII-only CLIs.
Marked non-exhaustive.
Vec<_> and Option<Vec<_>> now use multiple_occurrences rather than multiple.
Deprecations 3
Deprecated in favor of
arg!.Deprecated in favor of the builder API with
arg!.The YAML API is deprecated in favor of the builder or derive APIs.
New APIs and options 31
Specifies the app's color setting.
Provides a test helper for debug assertions.
Supports custom error reporting.
Sets a custom help heading for future arguments.
Changes an existing argument, particularly useful for help and version arguments.
Experimental API for aliasing an argument to a group of arguments, behind the unstable-replace feature.
Sets a custom help heading for subcommands.
Sets the value name for subcommands.
Enables partial parsing.
Allows long argument abbreviations, like subcommand abbreviations.
Experimental BusyBox-like multi-call support, behind the unstable-multicall feature.
Disables built-in help behavior.
Disables built-in version behavior.
Detects subcommands among positional arguments.
Makes
cmd helpprint long help (--helpinstead of-h).Creates an Arg from a compile-time usage parser.
Adds extra context after the long help message.
Adds extra context before the long help message.
Provides a default value when an option is present without a value, for cases such as
--color[=<WHEN>].Supports conditional default values.
Adds a derive attribute for integrating with the ArgEnum trait.
Allows an argument to conflict with all other arguments.
Sets a custom help heading for the current argument.
Provides hints to completion scripts.
Experimental support for grouping multiple values within multiple occurrences, behind the unstable-grouped feature.
Deriving ArgEnum generates possible values for arguments; requires the derive feature.
Adds derive support for defaulting with native types.
Adds support for flag subcommands.
Enables argument validation with a regex.
Short flags can have aliases.
Adds a new update API.
Behavior and default changes 3
Version flags are generated only when App::version or App::long_version is set.
Colored help is now enabled by default and can be opted out with
AppSettings::DisableColoredHelp.Now Unicode-aware when the unicode feature is enabled.
Fixes and other changes 2
An empty authors field in Cargo.toml is handled gracefully by app_from_crate.
Now always respected, even when that means colors are skipped in some cases.