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 20 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.
Nothing published for this version
Moving (old location deprecated)
MSRV is now 1.56.0 (#3732)
Behavior
required and its variants (#3793)ArgMatches::value_of and friends, debug asserts were turned into panicsMoving (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)#[clap(parse(...))] replaced with: (#3589, #3794)
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.#[clap(parse(from_flag))] replaced with #[clap(action = ArgAction::SetTrue)] (#3794)#[clap(parse(from_occurrences))] replaced with #[clap(action = ArgAction::Count)] though the field's type must be u8 (#3794)#[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).#[clap(parse(try_from_str = ...)], replace it with #[clap(value_parser = ...)]TypedValueParser will be needed and specify it with #[clap(value_parser = ...)]Arg::value_parser / ArgMatches::{get_one,get_many} (#2683, #3732)
TypedValueParsers available with an API open for expansionvalue_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 valuesArgMatches getters do not assume required arguments (#2505)ArgMatches::remove_* variants to transfer ownershipArgMatches::try_* variants to avoid panics for developer errors (#3621)get_raw to access the underlying OsStrsPathBuf value parsers imply ValueHint::AnyPath for completions (#3732)Arg::action (#3774)
ArgAction::StoreValue: existing takes_value(true) behaviorArgAction::IncOccurrences: existing takes_value(false) behaviorArgAction::Help: existing --help behaviorArgAction::Version: existing --version behaviorArgAction::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)
Arg::default_value("false") (#3786)Arg::env via Arg::value_parserArgAction::SetFalse: Treat --flag as --flag=false (#3775)
Arg::default_value("true") (#3786)Arg::env via Arg::value_parserArgAction::Count: Treat --flag --flag --flag as --flag=1 --flag=2 --flag=3 (#3775)
Arg::default_value("0") (#3786)Arg::env via Arg::value_parserArg::value_parser / Arg::action with either #[clap(value_parser)] (#3589, #3742) / #[clap(action)] attributes (#3794)
ValueParser is determined by value_parser! (#3199, #3496)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} APIdefault_value_ifs_os(#3815)parser
ArgMatches::value_source and ArgMatches::occurrences_of for external subcommands (#3732)Arg::default_missing_values (#3761, #3765)Arg::default_value / Arg::env on value delimiters independent of whether -- was used (#3765)required and its variants (#3793)Fix deprecated arg_enum! for users migrating to clap3
arg_enum! for users migrating to clap3 (#3717)required_unless_present_all arguments exist... when not enough value_names are suppliedgated behind unstable-v4
required is not used with conditional required settings (#3660)value_names than number_of_values (#2695)"" argument for external subcommands (#3263)Arg::id as verbatim casing (#3282)*(derive)* Abort, rather than ignore, when deriving ArgEnum with non-unit unskipped variants
ArgEnum with non-unit unskipped variants*(help)* Show PossibleValue::help in long help (--help) (gated behind `unstable-v4`)
PossibleValue::help in long help (--help) (gated behind unstable-v4) (#3312)*(derive)* Allow other attribute with a subcommand that has subcommands
*(help)* help subcommand shows long help like --help, rather than short help (-h), deprecated clap::AppSettings::UseLongFormatForHelpSubcommand
Changes in behavior of note that are not guaranteed to be compatible across releases:
help subcommand shows long help like --help, rather than short help (-h), deprecated clap::AppSettings::UseLongFormatForHelpSubcommand (#3440)clap::Command is now preferred over clap::App (#3089 in #3472)
clap::command! is now preferred over clap::app_from_crate (#3089 in #3474)clap::CommandFactory::command is now preferred over clap::IntoApp::into_app (#3089 in #3473)help subcommand shows long help like --help, rather than short help (-h), deprecated clap::AppSettings::UseLongFormatForHelpSubcommand (#3440)clap::AppSettings::WaitOnError, leaving it to the user to implementclap::Command::subcommand_required(true).arg_required_else_help(true) is now preferred over clap::AppSettings::SubcommandRequiredElseHelp (#3280)clap::AppSettings are nearly all deprecated and replaced with builder methods and getters (#2717)clap::ArgSettings is deprecated and replaced with builder methods and getters (#2717)clap::Arg::id and clap::ArgGroup::id are now preferred over clap::Arg::name and clap::ArgGroup::name (#3335)clap::Command::next_help_heading is now preferred over clap::Command::help_heading (#1807, #1553)clap::error::ErrorKind is now preferred over clap::ErrorKind (#3395)clap::Error::kind() is now preferred over clap::Error::kindclap::Error::context() is now preferred over clap::Error::info (#2628)Note: All items deprecated in 3.0.0 are now hidden in the documentation. (#3458)
clap::ArgMatches::value_source to determine what insert the value (#1345)clap::Command::next_display_order (#1807)clap::Error::context API to open the door for fully-custom error messages (#2628)
clap::error::ErrorKind now implements Displayclap::Command::color to override previous calls (#3449)ArgRequiredElseHelp precedence over SubcommandRequired (#3456)clap::Command::arg_required_else_help, etc (#3076, #1264)-h conflicts (#3403)--help (#1549)clap::error::Result (#3395)clap::Error (#3395)clap::Arg::validatorparse attributeAdded Error::kind() as we work to deprecate direct member access for Error
ArgMatches::args_present() to check if any args are presentError::kind() as we work to deprecate direct member access for ErrorApp::get_versionApp::get_long_versionApp::get_authorApp::get_subcommand_help_headingApp::get_subcommand_value_nameApp::get_after_helpApp::get_after_long_help*(derive)* Support for default_value_os_t
default_value_os_tEnsure conflicts work when they target a group with a default value
Don't assume user does use clap::ArgEnum
derive
use clap::ArgEnum (#3277)List correct replacement for deprecated Parser::from_clap
docs:
ArgMatches assertsParser::from_clap (#3257)Ignore Last when checking hyphen values (see #3249 for details)
Last when checking hyphen values (see #3249 for details)#[must_use]Don't panic when getting number of values
default_value_t derive attribute with a Subcommand (#3245)Documentation
name attribute to ArgEnum variant derive referenceLook over the "subtle changes" under BREAKING CHANGES
Note: clap v3 has been in development for several years and has changed hands multiple times. Unfortunately, our changelog might be incomplete, whether in changes or their motivation.
A special thanks to the maintainers, contributors, beta users, and sponsors who have helped along this journey, especially kbknapp.
StructOpt Integration
StructOpt provides a serde-like declarative approach to defining your parser. The main benefits we've seen so far from integrating are:
StructOpt traits so crates built on clap3 can be
reused not just with other derives but also people using the builder API.
People can even hand implement these so people using the builder API won't
have the pay the cost for derives.Custom Help Headings
Previously, clap automatically grouped arguments in the help as either
ARGS, FLAGS, OPTIONS, and SUBCOMMANDS.
You can now override the default group with Arg::help_heading and
App::subcommand_help_heading. To apply a heading to a series of arguments,
you can set App::help_heading.
Deprecations
While a lot of deprecations have been added to clean up the API (overloaded
meaning of Arg::multiple) or make things more consistent, some particular
highlights are:
clap_app! has been deprecated in favor of the builder API with arg! (clap-rs/clap#2835)Arg::from_usage has been deprecated in favor of arg! (clap-rs/clap#3087)
From clap v2
-h and --help output at a minimum (recommendation: trycmd for snapshot testing)no-default-features: add the std featureApp creation to a function and add a test similar to the one below, resolving any of its assertionsArgMatches asserts regarding AllowInvalidUtf8.Example test:
fn app() -> clap::App<'static> {
...
}
#[test]
fn verify_app() {
app().debug_assert();
}
From structopt 0.3.25 <a name="migrate-structopt"></a>
-h and --help output at a minimum (recommendation: trycmd for snapshot testing)structopt = "..." to clap = { version = "3.0", features = ["derive"] }
no-default-features: add the std featureuse statements from structopt and structopt::clap to clapExample test:
#[derive(clap::StructOpt)]
struct Args {
...
}
#[test]
fn verify_app() {
use clap::IntoApp;
Args::into_app().debug_assert()
}
From clap v3.0.0-beta.5
-h and --help output at a minimum (recommendation: trycmd for snapshot testing)derive, env, cargo, or unicode feature flags as neededyaml, clap_app!, or usage parser: revert any changes you made for clap3Arg::about Arg::long_about back to help and long_help and change PossibleValue::about to help (clap-rs/clap#3075)AppSettings::HelpRequired to AppSettings::HelpExpectedPossibleValue::hidden to PossibleValue::hideApp::subcommand_placeholder to App::subcommand_value_name / App::subcommand_help_headingderive: see the structopt breaking changes section for Vec changesArgMatches asserts regarding AllowInvalidUtf8.From clap 2
Subtle changes (i.e. compiler won't catch):
AppSettings::UnifiedHelpMessage is now default behaviour
{flags} and {unified} will assert if present in App::help_templateAppSettings::EnableColoredHelp is now the default behavior but can be
opted-out with AppSettings::DisableColoredHelp
(clap-rs/clap#2806)App::override_usage no longer implies a leading \t, allowing multi lined usagesArg::require_equals no longer implies ArgSettings::ForbidEmptyValues (#2233)Arg::require_delimiter no longer implies ArgSettings::TakesValue and ArgSettings::UseValueDelimiter (#2233)Arg::env, Arg::env_os, Arg::last, Arg::require_equals, Arg::allow_hyphen_values,
Arg::hide_possible_values, Arg::hide_default_value, Arg::hide_env_values,
Arg::case_insensitive and Arg::multiple_values no longer imply ArgSettings::TakesValue (#2233)ArgMatches::is_present no longer checks subcommand names...s meaning in usage parser. Before, it always meant multiple which is still true for --option [val].... Now [name]... --option [val] results in ArgSettings::MultipleOccurrences.1 to 2 (clap-rs/clap#1327)--foo=bar when takes_value(false) (clap-rs/clap#1543)- for long arguments (-----long)Easier to catch changes:
no-default-features, you now have to specify the std feature (reserved for future work)env feature flag
Arg::env, Arg::env_os, Arg::hide_env_values, ArgSettings::HideEnvValuescargo feature flag
crate_name!, crate_version!, crate_authors!, crate_description!, app_from_crate!AppSettings::StrictUtf8 is now default behaviour and asserts if
AppSettings::AllowInvalidUtf8ForExternalSubcommands and
ArgSettings::AllowInvalidUtf8 and ArgMatches::value_of_os aren't used
together
AppSettings::AllowInvalidUtf8 has been removedArg::short and Arg::value_delimiter now take a char instead of a &strArgMatches panics on unknown argumentsVersionlessSubcommands, making it the default (see clap-rs/clap#2812)ArgSettings::EmptyValues in favor of ArgSettings::ForbidEmptyValuesArg::validator now takes first argument as Fn(&str) -> Result<O, E: ToString> instead of
Fn(String) -> Result<(), String>Arg::validator_os now takes first argument as Fn(&OsStr) -> Result<O, OsString> instead of
Fn(&OsStr) -> Result<(), OsString>Arg::value_name now sets, rather than appends (see clap-rs/clap#2634)yaml-rust from 0.3 to 0.4ArgGroup::from(BTreeMap) to ArgGroup::from(yaml)ArgMatches::usage with App::generate_usageArg::settings with Arg::setting(Setting1 | Setting2)App and Arg now need only one lifetimeApp::with_defaults, replaced with app_from_crateAppSettings::PropagateGlobalValuesDown (now the default)App functions, like App::write_help now take &mut self instead of &selfError::message is now private, use Error::to_stringArg::default_value_if, Arg::default_value_if_os, Arg::default_value_ifs,
Arg::default_value_ifs_os now takes the default value parameter as an option (clap-rs/clap#1406)App::print_help & App::print_long_help to now return std::io::ResultApp::write_help & App::write_long_help to now return std::io::ResultArg::index, Arg::number_of_values, Arg::min_values, Arg::max_values to taking usize instead of u64Error::info to type Vec<String> instead of Option<Vec<String>>ArgMatches::subcommand to now return Option<(&str, &ArgMatches)>ErrorKind::MissingArgumentOrSubcommand to ErrorKind::DisplayHelpOnMissingArgumentOrSubcommandErrorKind::HelpDisplayed to ErrorKind::DisplayHelpErrorKind::VersionDisplayed to ErrorKind::DisplayVersion#[non_exhaustive] to clap::{ValueHint, ErrorKind, AppSettings, ArgSettings} (clap-rs/clap#3167)From structopt 0.3.25
App isn't initialized with crate information anymore. Now opt-in via #[clap(author)], #[clap(about)], #[clap(version)] (clap-rs/clap#3034)#[clap(default_value)] is replaced with #[clap(default_value_t)] (clap-rs/clap#1694)#[clap(subcommand)] attribute (clap-rs/clap#2587)Vec<_> and Option<Vec<_>> have changed from multiple to multiple_occurrencesOn top of the clap 2 changes
From clap 2
unicode feature flag for faster builds and smaller binaries for ASCII-only CLIs.env feature flag for faster builds and smaller binaries.From clap 2
Integration of structopt::StructOpt via clap::Parser (requires derive feature flag)
Custom help headings
App::help_heading (apply to all future args)Arg::help_heading (apply to current arg)App::subcommand_help_heading along with App::subcommand_value_name (apply to subcommands)AppSettings::UnifiedHelpMessage is now default behaviour (clap-rs/clap#2807)Deriving of ArgEnum for generating Arg::possible_values (requires derive feature flag)
Disable built-in help/version behavior with AppSettings::NoAutoHelp and AppSettings::NoAutoVersion
Change an existing arg with new builder method mut_arg (particularly helpful for --help and --version)
Provide extra context in long help messages (--help) with before_long_help and after_long_help (clap-rs/clap#1903)
Detect missing help descriptions via debug asserts by enabling AppSettings::HelpExpected
Aliases for short flags (clap-rs/clap#1896)
Validate UTF-8 values, rather than panicing during ArgMatches::value_of thanks to AppSettings::AllowInvalidUtf8ForExternalSubcommands and ArgSettings::AllowInvalidUtf8
ArgMatches calls do not match the UTF-8 setting.clap::PossibleValue to allow
Allow arguments to conflict with all others via Arg::exclusive (clap-rs/clap#1583)
Validate arguments with a regex (required regex feature flag)
Arg::default_missing_value for cases like --color[=<WHEN>] (clap-rs/clap#1587)
clap::App::color / clap::ColorChoice to specify color setting for the app
Custom error reporting with App::error
App::debug_assert test helper
Replace Arg::multiple(bool) with Arg::multiple_values / Arg::multiple_occurrences
Added support for flag subcommands like pacman (clap-rs/clap#1361)
Partial parsing via AppSettings::IgnoreErrors (clap-rs/clap#1880)
Enable cmd help to print long help (--help instead of -h) with AppSettings::UseLongFormatForHelpSubcommand (clap-rs/clap#2435)
Allow long arg abbreviations like we do with subcommands via AppSettings::InferLongArgs (clap-rs/clap#2435)
Detect subcommands among positional arguments with AppSettings::SubcommandPrecedenceOverArg
Give completion scripts hints with Arg::value_hint (clap-rs/clap#1793)
Allow unsetting defaults with
Arg::default_value_if, Arg::default_value_if_os, Arg::default_value_ifs,
Arg::default_value_ifs_os (clap-rs/clap#1406)
Interpret some env variable values as false for flags, in addition to "not-present" (clap-rs/clap#2539)
n, no, f, false, off, 0Added arg! macro for creating an Arg from a compile-time usage parser
(Experimental) Busybox-like multi-call support
AppSettings::Multicall behind unstable-multicall feature flag(Experimental) Alias an argument to anything group of arguments
App::replace behind unstable-replace feature flag(Experimental) Grouping of multiple values within multiple occurrences
ArgMatches::grouped_values_of behind unstable-grouped feature flagFrom structopt 0.3.25
default_value_t [= <expr>] attribute (clap-rs/clap#1694)update APIarg_enum attribute for integrating with ArgEnum traitOn top of the clap 2 changes
From clap 2
App::version, App::long_version are set
(see clap-rs/clap#2812)wrap_help feature is not enabledArg::multiple with Arg::multiple_values and Arg::multiple_occurrencesapp_from_crate! defaults to separating multiple authors with ", "IgnoreCase is now unicode aware (requires unicode feature flag)ColorChoice::Never, even if that means we skip colors in some casesArgMatches panics on unknown argumentsauthors field in Cargo.toml with app_from_crate--help in cmd help with DisableHelpFlag (clap-rs/clap#3169)--help in cmd help help that doesn't work (clap-rs/clap#3169)From structopt 0.3.25
SubcommandsNegateReqs by allowing required Option<_>s (clap-rs/clap#2255)AllowInvalidUtf8 based on parser (clap-rs/clap#751)authors field in Cargo.tomldefault_value_os but treat it like default_value (clap-rs/clap#3031)flatten and subcommand, ensure our doc comment always overrides the nested container's doc comment, whether it has only about or about and long_about (clap-rs/clap#3175)On top of the clap 2 changes
clap requires rustc 1.54.0 or greater.Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Your coding agent can read these notes before it upgrades. Set up the MCP server →