NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
crates.io · #118 most downloaded on crates.io
Parse command line argument by defining a struct, derive crate.
Last release 23 days ago
14 Sep 2026
Ships fairly regularly
a new release about every 6 weeks
Nearly every release is documented
notes for 56 of the last 60 stable releases
1 version withdrawn
withdrawn after publishing
6 years old
93 releases · first in 2020
One column per quarter.
(derive) Add #[command(defer = <bool>)] attribute to opt-in to lazy initialisation of subcommands
#[command(defer = <bool>)] attribute to opt-in to lazy initialisation of subcommands#[command(defer = <bool>)] attribute to opt-in to lazy initialisation of subcommands[4.6.4] - 2026-07-21 Internal Update to syn v3
(derive) Allow "literal".function() as attribute values
"literal".function() as attribute values*(derive)* Ensure rebuilds happen when an read env variable is changed
### Compatibility - Update MSRV to 1.85
### Internal - Update dependencies
Fix inconsistency in precedence between positionals with a value_terminator("--") and escapes (--) where ./foo -- bar means the first arg is empty, ra
value_terminator("--") and escapes (--) where ./foo -- bar means the first arg is empty, rather than escaping future args*(help)* Correctly wrap when ANSI escape codes are present
Added impl FromArgMatches for ()
impl FromArgMatches for ()impl Args for ()impl Subcommand for ()impl FromArgMatches for Infallibleimpl Subcommand for Infallibleclap*(unstable-v5)* ValueEnum variants now use the full doc comment, not summary, for PossibleValue::help
ValueEnum variants now use the full doc comment, not summary, for PossibleValue::helpAdd Styles::context and Styles::context_value to customize the styling of [default: value] like notes in the --help
Styles::context and Styles::context_value to customize the styling of [default: value] like notes in the --helpSupport quoted ids in arg!() macro (e.g. arg!("check-config": ...))
arg!() macro (e.g. arg!("check-config": ...))*(cookbook)* Switch from humantime to jiff
Error::removehumantime to jiffpulldown-cmark*(derive)* Unstable support for full markdown syntax for doc comments, enabled with unstable-markdown
unstable-markdown*(parser)* Correctly handle defaults with ignore_errors(true) and when a suggestion is provided for an unknown argument
ignore_errors(true) and when a suggestion is provided for an unknown argument*(builder)* Expose Arg::get_display_order and Command::get_display_order
Arg::get_display_order and Command::get_display_order*(derive)* Improve error message when #[flatten]ing an optional #[group(skip)]
#[flatten]ing an optional #[group(skip)]Nothing published for this version
### Fixes - Reduce extra flushes
Allow exclusive to override required_unless_present, required_unless_present_any, required_unless_present_all
exclusive to override required_unless_present, required_unless_present_any, required_unless_present_all*(derive)* Allow non-literal #[arg(id)] attributes again
#[arg(id)] attributes again### Internal - *(derive)* Update heck
heck### Compatibility - Update MSRV to 1.74
### Performance - Reduced code size
Improve build times by removing once_cell dependency
once_cell dependency### compatibility - update msrv to 1.70.0
*(derive)* Don't error on enum variant field attributes
*(derive)* Don't produce unused_equalifications warnings when someone brings a clap type into scope
unused_equalifications warnings when someone brings a clap type into scope*(derive)* Reduce the amount of generated code
*(assert)* Allow multiple, value-terminated, positional arguments
last assertionvalue_terminator has higher precedence than allow_hyphen_values--helpRemoved the languishing unstable-replace feature (open to discussion at #2836)
unstable-replace feature (open to discussion at #2836)unstable-grouped featureStyledStr to accept text styled with ANSI escape codesCLICOLOR, CLICOLOR_FORCE*(derive)* #[group] raw attribute support
#[group] raw attribute supportclap_builder was pulled out of clap so it could build in parallel to clap_deriveos_str_bytes dependency was removed for faster builds and smaller binaries*(derive)* Faster build times by dropping proc-macro-error dependency
syn v2proc-macro-error dependency*(assert)* Improve the assert when using the wrong action with get_count / get_flag
get_count / get_flag*(derive)* Don't deny lints on the users behalf
deny lints on the users behalf*(derive)* Hide some nightly clippy warnings
For apps with custom --help and --version flags:
MSRV changed to 1.64.0
For apps with custom --help and --version flags:
--help and --version changedWhen apps have errors imitating clap's error style:
ArgMatches::get_occurrences support for argument values to be grouped by their occurrenceupgrade_from when arguments / subcommands are explicitly marked as required--help and --version (also helps with overflow)*(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
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)*(derive)* Allow defaulted value parser for '()' fields
*(derive)* Allow #[command(skip)] to also work with enum variants with a value
#[command(skip)] to also work with enum variants with a value*(derive)* Allow () for fields to mean "don't read"
() for fields to mean "don't read" (#4371)*(derive)* Support #[arg(flatten)] on Option types (#4211, #4350)
#[arg(flatten)] on Option types (#4211, #4350)*(derive)* Process doc comments for #[command(subcommand)] like in clap v3
#[command(subcommand)] like in clap v3*(derive)* Remove a low-value assert preventing defaulting Help and Version actions
Help and Version actions*(derive)* Populate implicit ArgGroup
#[group(skip)] on Parser derive*(derive)* Support #[group(skip)] (#4279, #4301)
#[group(skip)] (#4279, #4301)*(derive)* Ensure #[clap(...)] attribute still works
#[clap(...)] attribute still worksResolve behavior changes (see "subtle changes" under BREAKING CHANGES)
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:
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
--version is 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 &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:
ArgActionValueParser API
PathBuf (allowing invalid UTF-8)AppSettings and ArgSettings enums with getters/settersSteps:
-h and --help output at a minimum (recommendation: trycmd for snapshot testing)arg.action(ArgAction::...) on each argument (StoreValue for options and IncOccurrences for flags)cargo check --features clap/deprecated and resolve all deprecation warningsdefault-features = false, run cargo add clap -F help,usage,error-contextcargo add clap -F wrap_help unless you want to hard code line wrapsExample 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.
Subtle changes (i.e. compiler won't catch):
arg! now sets one of (#3795):
ArgAction::SetTrue, requiring ArgMatches::get_flag instead of ArgMatches::is_presentArgAction::Count, requiring ArgMatches::get_count instead of ArgMatches::occurrences_ofArgAction::Set, requiring ArgMatches::get_one instead of ArgMatches::value_ofArgAction::Append, requiring ArgMatches::get_many instead of ArgMatches::values_ofArgAction::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)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)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)help, usage and error-context, requiring adding them back in if default-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 with Command::allow_hyphen_values (#4187)Arg::value_terminator must be its own argument on the CLI rather than being in a delimited list (#4025)wrap_help feature flag, either enable it or hard code your wraps (#4258)DeriveDisplayOrder the default and removed the setting. To sort help, set next_display_order(None) (#2808)Command::next_display_order instead of DeriveDisplayOrder and using its own initial display order value (#2808)Command::help_template (#4132)Command::help_template, Arg::help_heading, and Command::subcommand_help_heading (#4132)COMMAND for the value name. To get the old behavior, see Command::subcommand_help_heading and Arg::subcommand_value_name (#4132, #4155)Command::help_template. (#4132, #4160)--help and --version like any ArgAction::SetTrue flag (#3776)Arg::id as verbatim casing, requiring updating of string references to other args like in conflicts_with or requires (#3282)ValueEnum variants will now show up in --help (#3312)Args, and ArgGroup is created using the type's name, reserving it for future use (#2621, #4209)next_help_heading can now leak out of a #[clap(flatten)], like all other command settings (#4222)Easier to catch changes:
ArgMatches now returns the arg Ids, rather than the values to reduce overhead and offer more flexibility. (#4072)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)Arg::min_values (across all occurrences) with Arg::num_args(N..) (per occurrence) to reduce confusion over different value count APIs (#4023)Arg::max_values (across all occurrences) with Arg::num_args(1..=M) (per occurrence) to reduce confusion over different value count APIs (#4023)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)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 APIsArg::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)Arg::requires_ifs and Arg::default_value*_ifs* to taking an ArgPredicate, removing ambiguity with None when accepting owned and borrowed types (#4084)PartialEq and Eq from Command so we could change external subcommands to use a ValueParser (#3990)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 moduleErrorKind::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)allow_external_subcommands from String to OsString as that is less likely to cause bugs in user applications (#3990)Command::render_usage now returns a StyledStr (#4248)parse to value_parser, removing parse support (#3827, #3981)
#[clap(value_parser)] and #[clap(action)] are now redundantsubcommand_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)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)Arg::default_missing_value didn't require num_args(0..=N), now it does (#4023)Arg::long are no longer allowed (#3691)value_names than num_args (#2695)ArgAction::Version is used#[track_caller]s to make it easier to debug assertsoverrides_with IDs are validoverrides_with now that Actions replace itmut_arg receiving an invalid arg ID or mut_subcommand receiving an invalid command nameMSRV 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 thingArg::requires_all in favor of Arg::requires_ifs now that it takes an ArgPredicate to avoid having multiple ways of doing the same thingArg::number_of_values in favor of Arg::num_args to clarify semantic differencesdefault_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::envCommand::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)Command::write_help and Command::write_long_help in favor of Command::render_help and Command::render_long_help (#4248)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)#[clap(value_parser)] and #[clap(action)] defaulted attributes (its the default) (#3976)Behavior Changes
wrap_help feature, if the terminal size cannot be determined, LINES and COLUMNS variables are used (#4186)Arg::num_args now accepts ranges, allowing setting both the minimum and maximum number of values per occurrence (#2688, #4023)value_parsers for ArgAction::SetTrue / ArgAction::SetFalse (#4092)From<&OsStr>, From<OsString>, From<&str>, and From<String> to value_parser! (#4257)Command, Arg, ArgGroup, PossibleValue, etc without managing lifetimes with the string feature flag (#2150, #4223)error-context, help and usage feature flags that can be turned off for smaller binaries (#4236)StyledStr::ansi() to Display with ANSI escape codes (#4248)Error::apply for changing the formatter for dropping binary size (#4111)Error::renderfor formatting the error into a StyledStrPossibleValue::help in long help (--help) (#3312){tab} variable for Command::help_template (#4161)Command::render_help and Command::render_long_help for formatting the error into a StyledStr (#3873, #4248)Command::render_usage now returns a StyledStr (#4248)required is not used with conditional required settings (#3660)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)OsStrs for Arg::{required_if_eq,required_if_eq_any,required_if_eq_all} (#4084)wrap_help feature, if the terminal size cannot be determined, LINES and COLUMNS variables are used (#4186)Command::display_name in the help title rather than Command::bin_nameArgAction::Count by adding an ... (#4003)cmd help help (#4131)[positional] in list when relevant (#4144)[positional] in usage (#4151)-h / --help when applicable (#4132, #4159)next_line_help, don't add blank lines (#4132, #4190)Command::display_name rather than Command::bin_name (#3966)"" argument for external subcommands (#3263)Arg::allow_hyphen_values, like Command::allow_hyphen_values (#4187)InvalidSubcommand over UnknownArgument in more cases (#4219)Arg::id as verbatim casing (#3282)#[clap(value_parser, action)] instead of #[clap(parse)] (#3827)Nothing published for this version
Nothing published for this version
Nothing published for this version
*(help)* Command::print_help now respects Command::colored_help
Command::print_help now respects Command::colored_help*(derive)* Expose #[clap(id = ...)] attribute to match Arg's latest API
#[clap(id = ...)] attribute to match Arg's latest API*(derive)* New default_values_t and default_values_os_t attributes
default_values_t and default_values_os_t attributesGlobal arguments should override env-sourced arguments
### Fixes - Don't panic when parsing --=
--=*(derive)* Fix regression with #[clap(default_value_os_t ...)] introduced in v3.2.3
#[clap(default_value_os_t ...)] introduced in v3.2.3*(derive)* Provide more clearer deprecation messages for #[clap(parse)] attribute
#[clap(parse)] attribute (#3832)Moved deprecations to be behind the deprecated Cargo.toml feature
deprecated Cargo.toml feature (#3830)
*(derive)* Improve the highlighted code for deprecation warnings
gated behind unstable-v4
#[clap(value_parser, action)] instead of #[clap(parse)] (#3827)Your coding agent can read these notes before it upgrades. Set up the MCP server →