From 886def13bd2cfc2bfb20ad3c0e42991f5ac1e2cb Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 28 Sep 2022 14:11:57 -0700 Subject: [PATCH] Upgrade to clap 4 (#272) --- Cargo.lock | 20 ++++++-------------- Cargo.toml | 2 +- examples/print_ast.rs | 2 +- examples/print_tokens.rs | 2 +- src/main.rs | 40 ++++++++++++++++++++-------------------- src/pyproject.rs | 2 +- 6 files changed, 30 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e6148cfb0d..e931fb0261 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -382,26 +382,24 @@ checksum = "fff857943da45f546682664a79488be82e69e43c1a7a2307679ab9afb3a66d2e" [[package]] name = "clap" -version = "3.2.16" +version = "4.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3dbbb6653e7c55cc8595ad3e1f7be8f32aba4eb7ff7f0fd1163d4f3d137c0a9" +checksum = "dd03107d0f87139c1774a15f3db2165b0652b5460c58c27e561f89c20c599eaf" dependencies = [ "atty", "bitflags", "clap_derive", "clap_lex", - "indexmap", "once_cell", "strsim", "termcolor", - "textwrap", ] [[package]] name = "clap_derive" -version = "3.2.15" +version = "4.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ba52acd3b0a5c33aeada5cdaa3267cdc7c594a98731d4268cdc1532f4264cb4" +checksum = "ca689d7434ce44517a12a89456b2be4d1ea1cafcd8f581978c03d45f5a5c12a7" dependencies = [ "heck", "proc-macro-error", @@ -412,9 +410,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.2.4" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" dependencies = [ "os_str_bytes", ] @@ -2187,12 +2185,6 @@ dependencies = [ "phf_codegen 0.8.0", ] -[[package]] -name = "textwrap" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" - [[package]] name = "thiserror" version = "1.0.32" diff --git a/Cargo.toml b/Cargo.toml index 228fb3c940..a5562854e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ anyhow = { version = "1.0.60" } bincode = { version = "1.3.3" } cacache = { version = "10.0.1" } chrono = { version = "0.4.21" } -clap = { version = "3.2.16", features = ["derive"] } +clap = { version = "4.0.1", features = ["derive"] } clearscreen = { version = "1.0.10" } colored = { version = "2.0.0" } common-path = { version = "1.0.0" } diff --git a/examples/print_ast.rs b/examples/print_ast.rs index a9530afae0..45d96b542b 100644 --- a/examples/print_ast.rs +++ b/examples/print_ast.rs @@ -9,7 +9,7 @@ use ruff::fs; #[derive(Debug, Parser)] struct Cli { - #[clap(parse(from_os_str), value_hint = ValueHint::FilePath, required = true)] + #[arg(value_hint = ValueHint::FilePath, required = true)] file: PathBuf, } diff --git a/examples/print_tokens.rs b/examples/print_tokens.rs index ade8a6a565..1266ae45de 100644 --- a/examples/print_tokens.rs +++ b/examples/print_tokens.rs @@ -9,7 +9,7 @@ use ruff::fs; #[derive(Debug, Parser)] struct Cli { - #[clap(parse(from_os_str), value_hint = ValueHint::FilePath, required = true)] + #[arg(value_hint = ValueHint::FilePath, required = true)] file: PathBuf, } diff --git a/src/main.rs b/src/main.rs index 3820207119..43f45ce332 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,65 +32,65 @@ const CARGO_PKG_NAME: &str = env!("CARGO_PKG_NAME"); const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION"); #[derive(Debug, Parser)] -#[clap(name = format!("{CARGO_PKG_NAME} (v{CARGO_PKG_VERSION})"))] +#[clap(name = CARGO_PKG_NAME)] #[clap(about = "An extremely fast Python linter.", long_about = None)] #[clap(version)] struct Cli { - #[clap(parse(from_os_str), value_hint = ValueHint::AnyPath, required = true)] + #[arg(value_hint = ValueHint::AnyPath, required = true)] files: Vec, /// Enable verbose logging. - #[clap(short, long, action)] + #[arg(short, long, action)] verbose: bool, /// Disable all logging (but still exit with status code "1" upon detecting errors). - #[clap(short, long, action)] + #[arg(short, long, action)] quiet: bool, /// Exit with status code "0", even upon detecting errors. - #[clap(short, long, action)] + #[arg(short, long, action)] exit_zero: bool, /// Run in watch mode by re-running whenever files change. - #[clap(short, long, action)] + #[arg(short, long, action)] watch: bool, /// Attempt to automatically fix lint errors. - #[clap(short, long, action)] + #[arg(short, long, action)] fix: bool, /// Disable cache reads. - #[clap(short, long, action)] + #[arg(short, long, action)] no_cache: bool, /// List of error codes to enable. - #[clap(long, multiple = true)] + #[arg(long, num_args = 1..)] select: Vec, /// Like --select, but adds additional error codes on top of the selected ones. - #[clap(long, multiple = true)] + #[arg(long, num_args = 1..)] extend_select: Vec, /// List of error codes to ignore. - #[clap(long, multiple = true)] + #[arg(long, num_args = 1..)] ignore: Vec, /// Like --ignore, but adds additional error codes on top of the ignored ones. - #[clap(long, multiple = true)] + #[arg(long, num_args = 1..)] extend_ignore: Vec, /// List of paths, used to exclude files and/or directories from checks. - #[clap(long, multiple = true)] + #[arg(long, num_args = 1..)] exclude: Vec, /// Like --exclude, but adds additional files and directories on top of the excluded ones. - #[clap(long, multiple = true)] + #[arg(long, num_args = 1..)] extend_exclude: Vec, /// List of mappings from file pattern to code to exclude - #[clap(long, multiple = true)] + #[arg(long, num_args = 1..)] per_file_ignores: Vec, /// Output serialization format for error messages. - #[clap(long, arg_enum, default_value_t=SerializationFormat::Text)] + #[arg(long, value_enum, default_value_t=SerializationFormat::Text)] format: SerializationFormat, /// See the files ruff will be run against with the current settings. - #[clap(long, action)] + #[arg(long, action)] show_files: bool, /// See ruff's settings. - #[clap(long, action)] + #[arg(long, action)] show_settings: bool, /// Enable automatic additions of noqa directives to failing lines. - #[clap(long, action)] + #[arg(long, action)] add_noqa: bool, /// Regular expression matching the name of dummy variables. - #[clap(long)] + #[arg(long)] dummy_variable_rgx: Option, } diff --git a/src/pyproject.rs b/src/pyproject.rs index 59628bd39c..f9ce7a938a 100644 --- a/src/pyproject.rs +++ b/src/pyproject.rs @@ -36,7 +36,7 @@ pub struct Config { pub dummy_variable_rgx: Option, } -#[derive(Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct StrCheckCodePair { pub pattern: String, pub code: CheckCode,