# Change Log All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] - ReleaseDate ## [4.0.24] - 2022-11-14 ### Fixes - Avoid panic when printing an argument that isn't built ## [4.0.23] - 2022-11-11 ### Fixes - Don't panic on reporting invalid-long errors when followed by invalid UTF8 - *(help)* Clarified argument to `help` subcommand ## [4.0.22] - 2022-11-07 ### Fixes - *(help)* Don't overflow into next-line-help early due to stale (pre-v4) padding calculations ## [4.0.21] - 2022-11-07 ### 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) ## [4.0.20] - 2022-11-07 ### Fixes - *(derive)* Allow defaulted value parser for '()' fields ## [4.0.19] - 2022-11-04 ### Features - `ColorChoice` now implements `ValueEnum` ## [4.0.18] - 2022-10-20 ### Fixes - *(derive)* Allow `#[command(skip)]` to also work with enum variants with a value ## [4.0.17] - 2022-10-18 ### Fixes - Allow using `Arg::last(true)` with `Arg::value_hint(ValueHint::CommandWithArguments)` ## [4.0.16] - 2022-10-18 ### Fixes - `Arg::exclusive(true)` should not be exclusive with the argument's own `ArgGroup` ## [4.0.15] - 2022-10-13 ### Fixes - *(error)* Don't suggest `--` when it doesn't help - *(error)* Be more consistent in quoting, punctuation, and indentation in errors ## [4.0.14] - 2022-10-12 ### Fixes - Only put `ArgGroup` in `ArgMatches` when explicitly specified, fixing derives handling of option-flattened fields (#4375) ## [4.0.13] - 2022-10-11 ### Features - *(derive)* Allow `()` for fields to mean "don't read" (#4371) ## [4.0.12] - 2022-10-10 ### 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` ## [4.0.11] - 2022-10-09 ### Fixes - *(help)* Fix wrapping calculations with ANSI escape codes ## [4.0.10] - 2022-10-05 ### Features - *(derive)* Support `#[arg(flatten)]` on `Option` types (#4211, #4350) ## [4.0.9] - 2022-10-03 ### Fixes - *(derive)* Process doc comments for `#[command(subcommand)]` like in clap v3 ## [4.0.8] - 2022-10-01 ### Fixes - *(derive)* Remove a low-value assert preventing defaulting `Help` and `Version` actions ## [4.0.7] - 2022-09-30 ### 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 ## [4.0.6] - 2022-09-30 ### Features - *(derive)* Support `#[group(skip)]` (#4279, #4301) ## [4.0.5] - 2022-09-30 ## [4.0.4] - 2022-09-29 ### Fixes - *(error)* Specialize the self-conflict error to look like clap v3 ## [4.0.3] - 2022-09-29 ### Fixes - *(error)* Quote literals consistently - *(error)* Stylize escape (`--`) suggestions - *(error)* Format help flag as a literal ## [4.0.2] - 2022-09-28 ### Fixes - *(parser)* `SetFalse` should conflict with itself like `SetTrue` and `Set` - *(parser)* Allow one-off overrides ## [4.0.1] - 2022-09-28 ### Fixes - *(derive)* Ensure `#[clap(...)]` attribute still works ## [4.0.0] - 2022-09-28 ### 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](https://github.com/clap-rs/clap/issues/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 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 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](https://github.com/clap-rs/clap/issues/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` 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: 0. [Upgrade to v3](https://github.com/clap-rs/clap/blob/v3-master/CHANGELOG.md#migrating) if you haven't already 1. Add CLI tests (including example below), `-h` and `--help` output at a minimum (recommendation: [trycmd](https://docs.rs/trycmd/) for snapshot testing) 2. *If using Builder API*: Explicitly set the `arg.action(ArgAction::...)` on each argument (`StoreValue` for options and `IncOccurrences` for flags) 3. Run `cargo check --features clap/deprecated` and resolve all deprecation warnings 4. Upgrade to v4 5. 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 6. Resolve compiler errors 7. Resolve behavior changes (see "subtle changes" under BREAKING CHANGES) 8. *At your leisure:* resolve new deprecation notices Example test (derive): ```rust #[derive(clap::Parser)] struct Cli { ... } #[test] fn verify_cli() { use clap::CommandFactory; Cli::command().debug_assert() } ``` Example test (builder): ```rust 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 ```rust .arg(Arg::new("flag").long("flag")) # --flag .arg(Arg::new("option").long("option").takes_value(true)) # --option