NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
crates.io · #4717 most downloaded on crates.io
A generator library used with clap for Fig completion scripts
Last release 2 years ago
no release in 18 months
Ships fairly regularly
a new release about every 5 weeks
Nearly every release is documented
notes for 28 of 29 stable releases
Nothing withdrawn
no release was ever pulled
5 years old
32 releases · first in 2021
One column per quarter.
### Fixes - *(macros)* Silence a warning
*(error)* Include suggestion to add -- even if there is a "did you mean" so long as last or trailing_var_arg is used
-- even if there is a "did you mean" so long as last or trailing_var_arg is used### Compatibility - Update MSRV to 1.74
Improve build times by removing once_cell dependency
once_cell dependency### Features - Stabilize Command::styles
Command::styles### compatibility - update msrv to 1.70.0
*(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_FORCEIn documentation, refer to get_flag, rather than get_one::
get_flag, rather than get_one::<bool>*(error)* Small softening attempt for "unexpected argument" error
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)*(parser)* SetFalse should conflict with itself like SetTrue and Set
SetFalse should conflict with itself like SetTrue and Set*(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
*(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)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)### Fixes - Dependency upgrade
*(help)* Show PossibleValue::help in long help (--help) (gated behind `unstable-v4`)
PossibleValue::help in long help (--help) (gated behind unstable-v4) (#3312)Don't panic when validating delimited defaults
*(derive)* Allow other attribute with a subcommand that has subcommands
Track caller for ArgMatches assertions so the user more easily sees where they need to fix the call
ArgMatches assertions so the user more easily sees where they need to fix the call*(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 attributeIgnore 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
Your coding agent can read these notes before it upgrades. Set up the MCP server →