Skip to content

Upgrade clap from 3.2 to 4.0 #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Oct 10, 2022
Merged

Upgrade clap from 3.2 to 4.0 #225

merged 11 commits into from
Oct 10, 2022

Conversation

LingMan
Copy link
Contributor

@LingMan LingMan commented Oct 7, 2022

Supersedes #224.

LingMan added 11 commits October 7, 2022 04:04
Fixes several warnings when running `cargo check --features clap/deprecated`:
warning: use of deprecated function `<Opts as clap::Args>::augment_args::parse_from_os_str`: Replaced with `#[clap(value_parser)]` for `PathBuf` or `#[clap(value_parser = ...)]` with a custom `TypedValueParser`
   --> src/main.rs:124:15
    |
124 |         parse(from_os_str),
    |               ^^^^^^^^^^^
    |
warning: use of deprecated function `<Opts as clap::Args>::augment_args::parse_from_os_str`: Replaced with `#[clap(value_parser)]` for `PathBuf` or `#[clap(value_parser = ...)]` with a custom `TypedValueParser`
   --> src/main.rs:146:15
    |
146 |         parse(from_os_str)
    |               ^^^^^^^^^^^

warning: use of deprecated function `<Opts as clap::Args>::augment_args::parse_from_os_str`: Replaced with `#[clap(value_parser)]` for `PathBuf` or `#[clap(value_parser = ...)]` with a custom `TypedValueParser`
   --> src/main.rs:179:15
    |
179 |         parse(from_os_str)
    |               ^^^^^^^^^^^
…unt`

Fixes these warnings when running `cargo check --features clap/deprecated`:
warning: use of deprecated function `<Opts as clap::Args>::augment_args::parse_from_occurrences`: Replaced with `#[clap(action = ArgAction::Count)]` with a field type of `u8`
   --> src/main.rs:139:43
    |
139 |     #[clap(short, long = "verbose", parse(from_occurrences))]
    |                                           ^^^^^^^^^^^^^^^^
    |
    = note: `#[warn(deprecated)]` on by default

warning: use of deprecated function `<Opts as clap::Args>::augment_args_for_update::parse_from_occurrences`: Replaced with `#[clap(action = ArgAction::Count)]` with a field type of `u8`
   --> src/main.rs:139:43
    |
139 |     #[clap(short, long = "verbose", parse(from_occurrences))]
    |                                           ^^^^^^^^^^^^^^^^
Fixes this warning when running `cargo check --features clap/deprecated`:
warning: use of deprecated associated function `clap::Arg::<'help>::validator`: Replaced with `Arg::value_parser(...)`

         Derive: replace `#[clap(validator = <fn>)]` with `#[clap(value_parser = <fn>)]`

         Builder: replace `arg.validator(<fn>)` with `arg.value_parser(<fn>)` and `matches.value_of` with
         `matches.get_one::<T>` or `matches.values_of` with `matches.get_many::<T>`
   --> src/main.rs:125:9
    |
125 |         validator = validate_dir
    |         ^^^^^^^^^
    |
… output

With Clap v4 the default changes from lexicographic to WYSIWYG.
The new `wrap_help` feature gets enabled since the code it guards was unconditional before and we
want to keep relying on it.
Clap 4 changed the help headings to be title cased. Update out custom heading to stay consistent.
Easiest achieved by renaming the variants to match their CLI names and then deriving ValueEnum.
Fixes these warnings when running `cargo check --features clap/deprecated`:
warning: use of deprecated function `<Cargo as clap::Subcommand>::augment_subcommands::old_attribute`: Attribute `#[clap(...)]` has been deprecated in favor of `#[command(...)]`
  --> src/main.rs:60:3
   |
60 | #[clap(bin_name = "cargo", subcommand_required = true)]
   |   ^^^^
   |
   = note: `#[warn(deprecated)]` on by default

warning: use of deprecated function `<Opts as clap::Args>::augment_args::old_attribute`: Attribute `#[clap(...)]` has been deprecated in favor of `#[command(...)]`
  --> src/main.rs:66:3
   |
66 | #[clap(
   |   ^^^^
Fixes several warnings like this when running `cargo check --features clap/deprecated`:
warning: use of deprecated function `<Opts as clap::Args>::augment_args::old_attribute`: Attribute `#[clap(...)]` has been deprecated in favor of `#[arg(...)]`
  --> src/main.rs:85:7
   |
85 |     #[clap(
   |       ^^^^
Fixes these warnings when running `cargo check --features clap/deprecated`:
warning: use of deprecated function `<Opts as clap::Args>::augment_args::bare_value_parser`: `#[arg(value_parser)]` is now the default and is no longer needed`
   --> src/main.rs:146:9
    |
146 |         value_parser
    |         ^^^^^^^^^^^^
    |
    = note: `#[warn(deprecated)]` on by default

warning: use of deprecated function `<Opts as clap::Args>::augment_args::bare_value_parser`: `#[arg(value_parser)]` is now the default and is no longer needed`
   --> src/main.rs:179:9
    |
179 |         value_parser
    |         ^^^^^^^^^^^^
@oli-obk
Copy link
Contributor

oli-obk commented Oct 10, 2022

Thank you!

@oli-obk oli-obk merged commit 3674e38 into rust-lang:master Oct 10, 2022
@LingMan LingMan deleted the clap branch October 10, 2022 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants