clap-rs/clap (clap)
Compare Source
Compare Source
Fixes
- Regression from 4.5.55 where having an argument with
.value_terminator("--") caused problems with an argument with .last(true)
Compare Source
Fixes
- On conflict error, don't show conflicting arguments in the usage
Compare Source
Fixes
- 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
Compare Source
Fixes
- (help) Move
[default] to its own paragraph when PossibleValue::help is present in --help
Compare Source
Features
- Add
default_values_if, default_values_ifs
Compare Source
Fixes
- Don't panic when
args_conflicts_with_subcommands conflicts with an ArgGroup
Compare Source
Fixes
- (help) Correctly calculate padding for short flags that take a value
- (help) Don't panic on short flags using
ArgAction::Count
Compare Source
Features
- Accept
Cow where String and &str are accepted
Compare Source
Fixes
- (help) Correctly wrap when ANSI escape codes are present
Compare Source
Documentation
- Add a new CLI Concepts document as another way of framing clap
- Expand the
typed_derive cookbook entry
Compare Source
Features
- Added
impl FromArgMatches for ()
- Added
impl Args for ()
- Added
impl Subcommand for ()
- Added
impl FromArgMatches for Infallible
- Added
impl Subcommand for Infallible
Fixes
- (derive) Update runtime error text to match
clap
Compare Source
Features
- Expose
StyledStr::push_str
Compare Source
Fixes
- (unstable-v5)
ValueEnum variants now use the full doc comment, not summary, for PossibleValue::help
Compare Source
Features
- Add
Command::mut_subcommands
Compare Source
Fixes
- (help) In long help, list Possible Values before defaults, rather than after, for a more consistent look
Compare Source
Fixes
- Include subcommand visible long aliases in
--help
Compare Source
Features
- Add
Styles::context and Styles::context_value to customize the styling of [default: value] like notes in the --help
Compare Source
Features
- Support quoted ids in
arg!() macro (e.g. arg!("check-config": ...))
Compare Source
Fixes
- (help) Show short flag aliases before long
- (help) Merge the short and long flag alias lists
Compare Source
Fixes
- (help) When showing aliases, include leading
-- or -
Compare Source
Features
- Added
ArgMatches::try_clear_id()
Compare Source
Fixes
- (help) Revert 4.5.35's "Don't leave space for shorts if there are none" for now
Compare Source
Fixes
- (help) Align positionals and flags when put in the same
help_heading
- (help) Don't leave space for shorts if there are none
Compare Source
Fixes
- (help) Don't add extra blank lines with
flatten_help(true) and subcommands without arguments
Compare Source
Fixes
- (error) When showing the usage of a suggestion for an unknown argument, don't show the group
Compare Source
Features
Documentation
- (cookbook) Switch from
humantime to jiff
- (tutorial) Better cover required vs optional
Internal
Compare Source
Features
- Add
ValueParserFactory for Saturating<T>
Compare Source
Fixes
- (assert) Allow
num_args(0..=1) to be used with SetTrue
- (assert) Clean up rendering of
takes_values assertions
Compare Source
Fixes
- Change
ArgMatches::args_present so not-present flags are considered not-present (matching the documentation)
Compare Source
Features
- (derive) Unstable support for full markdown syntax for doc comments, enabled with
unstable-markdown
Compare Source
Documentation
- Iterate on tutorials and reference based on feedback
Compare Source
Fixes
- (error) Reduce binary size with the
suggestions feature
Compare Source
Fixes
- (help) Reduce binary size
Compare Source
Fixes
- (parser) Correctly handle defaults with
ignore_errors(true) and when a suggestion is provided for an unknown argument
Compare Source
Fixes
- (parser) When check
allow_negative_numbers, allow E again
Compare Source
Fixes
- (assert) Catch bugs with arguments requiring themself
Compare Source
Fixes
- (parser) Ensure defaults are filled in on error with
ignore_errors(true)
Compare Source
Features
- (unstable) Add
CommandExt
Compare Source
Internal
Compare Source
Features
- (builder) Expose
Arg::get_display_order and Command::get_display_order
Compare Source
Fixes
- (help) Style required argument groups
- (derive) Improve error messages when unsupported fields are used
Compare Source
Fixes
- (derive) Improve error messages when
derive feature is missing
Compare Source
Compatiblity
- (unstable-ext)
Arg::remove changed return types
Fixes
- (unstable-ext) Make
Arg::remove return the removed item
Compare Source
Features
- (unstable-ext) Added
Arg::add for attaching arbitrary state, like completion hints, to Arg without Arg knowing about it
Compare Source
Fixes
- (derive) Improve error message when
#[flatten]ing an optional #[group(skip)]
- (help) Properly wrap long subcommand descriptions in help
Compare Source
Compare Source
Compare Source
Compare Source
Fixes
- (error) When defining a custom help flag, be sure to suggest it like we do the built-in one
Compare Source
Fixes
Compare Source
Fixes
- Clean up error message when too few arguments for
num_args
Compare Source
Compare Source
Fixes
- (help) Move
[default] to its own paragraph when PossibleValue::help is present in --help
Compare Source
Fixes
- (help) Correctly wrap when ANSI escape codes are present
Compare Source
Fixes
- (help) Show short flag aliases before long
- (help) Merge the short and long flag alias lists
Compare Source
Fixes
- Change
ArgMatches::args_present so not-present flags are considered not-present (matching the documentation)
Compare Source
Internal
Compare Source
Compatibility
Compare Source
Fixes
- (error) When lacking
usage feature, ensure the list of required arguments is unique
Compare Source
Fixes
- Fix
panic! when mixing args_conflicts_with_subcommands with ArgGroup (which is implicit with derive) introduced in 4.4.15
Compare Source
Fixes
- Ensure invalid escape sequences in user-defined strings are correctly stripped when terminal doesn't support color
Compare Source
Fixes
- Improve error for
args_conflicts_with_subcommands
- Ensure we error for
args_conflicts_with_subcommands when using subcommand short and long flags
Compare Source
Documentation
- Fix
find cookbook entry to allow repeats of flags/options
Features
- Allow
num_args(0) on options which allows making them emulate being a flag for position-tracking flags
Compare Source
Documentation
- Fix link to structopt migration guide
Compare Source
Performance
- Only ask
TypedValueParser for possible values if needed
Compare Source
Features
Compare Source
Documentation
- Link out to changelog
- Cross link derive's attribute reference to derive tutorial
Compare Source
Fixes
- (help) Show correct
Command::about under flattened headings
- (help) Respect
hide when flattening subcommands
Compare Source
Features
- Add
Command::flatten_help to allow git stash -h like help for subcommands
Compare Source
Performance
Compare Source
Internal
Compare Source
Fixes
- (parser) When inferring subcommand
name or long_flag, allow ambiguous-looking matches that unambiguously map back to the same command
- (parser) When inferring subcommand
long_flag, don't panic
- (assert) Clarify what action is causing a positional that doesn't set values which is especially useful for derive users
Compare Source
Internal
- Update
terminal_size to 0.3
Compare Source
Documentation
- (derive) Clarify use of attributes within the tutorial
- Split sections in the builder and derive tutorials into separate modules
Compare Source
Performance
- Improve build times by removing
once_cell dependency
Compare Source
Fixes
- (error) When lacking
usage feature, ensure the list of required arguments is unique
Compare Source
compatibility
Compare Source
Fixes
- Ensure column padding is preserved in
--help with custom templates
Compare Source
Fixes
- Fixed
UnknownArgumentValueParser to not error on flag's absence
Compare Source
Features
- Add
UnknownArgumentValueParser for injecting errors for improving the experience with errors
Compare Source
Features
- Expose
TryMapValueParser so the type can be named
Compare Source
Features
Command::mut_args for modifying all arguments en masse
Compare Source
Fixes
- (parse) Respect
value_terminator even in the presence of later multiple-value positional arguments
Compare Source
Fixes
- (parse) Suggest
-- in fewer places where it won't work
Compare Source
Fixes
- (help) Address a regression in wrapping
PossibleValue descriptions in --help
Compare Source
Fixes
- Don't assert when stateful value parsers fail on defaults (e.g. checking if a path exists)
Compare Source
Features
- (unstable-styles) Re-export
anstyle
Documentation
- (unstable-styles) Provide more examples
Compare Source
Features
ArgAction::HelpShort and ArgAction::HelpLong for explicitly specifying which style of help to display
Fixes
- Skip
[OPTIONS] in usage if a help or version ArgAction is used
Compare Source
Compare Source
Fixes
- (derive) Don't error on enum variant field attributes
Compare Source
Features
- (derive) Support fields wrapped in
num::Wrapping, Box, or Arc
- (derive) Support
Box<str>, Box<OsStr>, and Box<Path>
Compare Source
Performance
- Drop a dependency, reducing binary size by 1.3 KiB
Compare Source
Fixes
Command::ignore_errors no longer masks help/version
Compare Source
Fixes
- Error on ambiguity with
infer_long_arg, rather than arbitrarily picking one, matching the documentation and subcommand's behavior
Compare Source
Documentation
- Further clarify magic behavior in derive tutorial
- Further clarify derive API's relationship to builder within the tutorial
Compare Source
Documentation
Compare Source
ColorChoice::possible_values is added to simplify things for builder users
Fixes
ColorChoice::to_possible_value no longer includes descriptions, encouraging shorter help where possible
Compare Source
Features
Compare Source
Features
Command::defer for delayed initialization of subcommands to reduce startup times of large applications like deno
Compare Source
Fixes
- Ensure column padding is preserved in
--help with custom templates
Compare Source
Fixes
- (parse) Respect
value_terminator even in the presence of later multiple-value positional arguments
Compare Source
Fixes
- (assert) Allow multiple, value-terminated, positional arguments
- (assert) Clear up language on
last assertion
- (parser) Correctly assign values to arguments when using multiple, value-termianted, positional arguments
- (parser) Ensure
value_terminator has higher precedence than allow_hyphen_values
- (help) Only use next-line-help on subcommand list when explicitly specified, not just with
--help
- (help) Correctly align possible values list
- (help) Don't waste code, vertical space in moving possible value descriptions to next line
Compare Source
Fixes
- Correctly track remaining length for iterators provided by
ArgMatches
Compare Source
Features
impl Eq<std::any::TypeId> for clap_builder::util::AnyValueId
Compare Source
Fixes
- Improve panic when a group requires a non-existent ID
Compare Source
Documentation
- Corrected docs for
Command::style
Compare Source
Features
Command::styles for theming help/errors (behind unstable-styles)
Compare Source
Internal
Compare Source
Fixes
- Don't highlight uninteresting parts of the error message
Compare Source
Compatibility
- Removed the languishing
unstable-replace feature (open to discussion at #2836)
- Removed the stablized
unstable-grouped feature
Features
- Allow any
StyledStr to accept text styled with ANSI escape codes
- Respect
CLICOLOR, CLICOLOR_FORCE
Fixes
- Lighten the tone for "unexpected argument" errors (open to discussion at #4638)
Compare Source
Features
- (derive)
#[group] raw attribute support
Performance
- (derive)
clap_builder was pulled out of clap so it could build in parallel to clap_derive
os_str_bytes dependency was removed for faster builds and smaller binaries
Compare Source
Performance
- Reduce repeated alloc calls when building a
Command
- Reduce duplicate dependencies for faster builds
Compare Source
Internal
- (derive) Update to
syn v2
Performance
- (derive) Faster build times by dropping
proc-macro-error dependency
Compare Source
Internal
Compare Source
Fixes
- (help) On Windows, avoid underlined text artifacts
Compare Source
Fixes
- (assert) Improve the assert when using the wrong action with
get_count / get_flag
Compare Source
Fixes
- (derive) Don't
deny lints on the users behalf
Compare Source
Fixes
- (derive) Hide some nightly clippy warnings
Compare Source
Fixes
- (help) Don't show long help for
--help just because hidden possible values include a description
Compare Source
Fixes
- (help) Don't show long help for
--help just because a hidden arg has a possible value with a description
Compare Source
Fixes
- (help) Respect
disable_colored_help when using arg_required_else_help
Performance
- Speed up compiling
arg! macro
Compare Source
Fixes
- (error) Improve suggested flag/value/subcommand when two share a long preifx
- (error) When suggesting one of several subcommands, use the plural
subcommands, rather than subcommand
Compare Source
Fixes
- In documentation, refer to
get_flag, rather than get_one::<bool>
Compare Source
Features
- (derive)
#[group] raw attribute support
Performance
- (derive)
clap_builder was pulled out of clap so it could build in parallel to clap_derive
os_str_bytes dependency was removed for faster builds and smaller binaries
Compare Source
Compatibility
MSRV changed to 1.64.0
For apps with custom --help and --version flags:
- Descriptions for
--help and --version changed
When apps have errors imitating clap's error style:
- Error message style was changed, including
- Moving away from "did you mean" to tips
- Leading letter is lower case
- "For more" added some punctuation
Features
ArgMatches::get_occurrences support for argument values to be grouped by their occurrence
Fixes
- (derive) Allow
upgrade_from when arguments / subcommands are explicitly marked as required
- (help) Try be more clearer and succinct with
--help and --version (also helps with overflow)
- (error) Try to be more clearer and succinct with error messages
- (error) Officially adopt an error style guide
Compare Source
Fixes
- (parser) When overriding
required(true), consider args that conflict with its group
Compare Source
Performance
- Speed up parsing when a lot of different flags are present (100 unique flags)
Compare Source
Fixes
- (error) Improve error for
args_conflicts_with_subcommand
Compare Source
Compare Source
Fixes
- Fix wasm support which was broken in 4.0.27
Compare Source
Features
- Have
Arg::value_parser accept Vec<impl Into<PossibleValue>>
- Implement
Display and FromStr for ColorChoice
Fixes
- Remove soundness issue by switching from
atty to is-terminal
Compare Source
Fixes
- (error) Fix typos in
ContextKind::as_str
Compare Source
Features
- (error) Report available subcommands when required subcommand is missing
Compare Source
Fixes
- Avoid panic when printing an argument that isn't built
Compare Source
Fixes
- Don't panic on reporting invalid-long errors when followed by invalid UTF8
- (help) Clarified argument to
help subcommand
Compare Source
Fixes
- (help) Don't overflow into next-line-help early due to stale (pre-v4) padding calculations
Compare Source
Features
- (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)
Compare Source
Fixes
- (derive) Allow defaulted value parser for '()' fields
Compare Source
Features
ColorChoice now implements ValueEnum
Compare Source
Fixes
- (derive) Allow
#[command(skip)] to also work with enum variants with a value
Compare Source
Fixes
- Allow using
Arg::last(true) with Arg::value_hint(ValueHint::CommandWithArguments)
Compare Source
Fixes
Arg::exclusive(true) should not be exclusive with the argument's own ArgGroup
Compare Source
Fixes
- (error) Don't suggest
-- when it doesn't help
- (error) Be more consistent in quoting, punctuation, and indentation in errors
Compare Source
Fixes
- Only put
ArgGroup in ArgMatches when explicitly specified, fixing derives handling of option-flattened fields (#4375)
Compare Source
Features
- (derive) Allow
() for fields to mean "don't read" (#4371)
Compare Source
Features
- Added
TypedValueParser::try_map for when adapting an existing TypedValueParser can fail
- (error) Create errors like clap with
Error::new, Error::with_cmd, and Error::insert
Compare Source
Fixes
- (help) Fix wrapping calculations with ANSI escape codes
Compare Source
Features
- (derive) Support
#[arg(flatten)] on Option types (#4211, #4350)
Compare Source
Fixes
- (derive) Process doc comments for
#[command(subcommand)] like in clap v3
Compare Source
Fixes
- (derive) Remove a low-value assert preventing defaulting
Help and Version actions
Compare Source
Features
- (derive) Populate implicit ArgGroup (#3165)
Fixes
- (derive) Support
#[group(skip)] on Parser derive
- (derive) Tell users about implicit arg groups when running into group name conflicts
- (error) Don't report unrelated groups in conflict or requires errors
Compare Source
Features
Compare Source
Compare Source
Fixes
- (error) Specialize the self-conflict error to look like clap v3
Compare Source
Fixes
- (parser) When overriding
required(true), consider args that conflict with its group
Compare Source
Compare Source
Features
ColorChoice now implements ValueEnum
Compare 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_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:
- 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.
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:
- 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
- Clarifying terms and making them more consistent
Migrating
Steps:
- Upgrade to v3 if you haven't already
- Add CLI tests (including example below),
-h and --help output at a minimum (recommendation: trycmd for snapshot testing)
- If using Builder API: Explicitly set the
arg.action(ArgAction::...) on each argument (StoreValue for options and IncOccurrences for flags)
- Run
cargo check --features clap/deprecated and resolve all deprecation warnings
- Upgrade to v4
- Update feature flags
- If
default-features = false, run cargo add clap -F help,usage,error-context
- Run
cargo add clap -F wrap_help unless you want to hard code line wraps
- Resolve compiler errors
- Resolve behavior changes (see "subtle changes" under BREAKING CHANGES)
- At your leisure: resolve new deprecation notices
Example 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.
Breaking Changes
Subtle changes (i.e. compiler won't catch):
arg! now sets one of (#3795):
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](https://redirect.github.com/clap-rs/clap/issues/2808
Uh oh!
There was an error while loading. Please reload this page.
This PR contains the following updates:
3→4Release Notes
clap-rs/clap (clap)
v4.5.58Compare Source
v4.5.57Compare Source
Fixes
.value_terminator("--")caused problems with an argument with.last(true)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](https://redirect.github.com/clap-rs/clap/issues/2808Configuration
📅 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.