From bdd84af25b8e2fc05376716c8e59a054a7ad81be Mon Sep 17 00:00:00 2001 From: tottoto Date: Fri, 18 Aug 2023 20:48:42 +0900 Subject: [PATCH] Update clap deprecated api --- src/cargo-deny/check.rs | 24 +++++++++++------------ src/cargo-deny/fetch.rs | 4 ++-- src/cargo-deny/init.rs | 1 - src/cargo-deny/list.rs | 8 ++++---- src/cargo-deny/main.rs | 43 ++++++++++++++++++++--------------------- 5 files changed, 39 insertions(+), 41 deletions(-) diff --git a/src/cargo-deny/check.rs b/src/cargo-deny/check.rs index 59ef609d0..e7ee3d4f5 100644 --- a/src/cargo-deny/check.rs +++ b/src/cargo-deny/check.rs @@ -61,13 +61,13 @@ impl std::str::FromStr for CodeOrLevel { #[derive(clap::Parser, Debug)] pub struct LintLevels { /// Set lint warnings - #[clap(long, short = 'W')] + #[arg(long, short = 'W')] warn: Vec, /// Set lint allowed - #[clap(long, short = 'A')] + #[arg(long, short = 'A')] allow: Vec, /// Set lint denied - #[clap(long, short = 'D')] + #[arg(long, short = 'D')] deny: Vec, } @@ -76,38 +76,38 @@ pub struct Args { /// Path to the config to use /// /// Defaults to /deny.toml if not specified - #[clap(short, long, action)] + #[arg(short, long)] pub config: Option, /// Path to graph_output root directory /// /// If set, a dotviz graph will be created for whenever multiple versions of the same crate are detected. /// /// Each file will be created at /graph_output/.dot. /graph_output/* is deleted and recreated each run. - #[clap(short, long, action)] + #[arg(short, long)] pub graph: Option, /// Hides the inclusion graph when printing out info for a crate - #[clap(long, action)] + #[arg(long)] pub hide_inclusion_graph: bool, /// Disable fetching of the advisory database /// /// When running the `advisories` check, the configured advisory database will be fetched and opened. If this flag is passed, the database won't be fetched, but an error will occur if it doesn't already exist locally. - #[clap(short, long, action)] + #[arg(short, long)] pub disable_fetch: bool, /// To ease transition from cargo-audit to cargo-deny, this flag will tell cargo-deny to output the exact same output as cargo-audit would, to `stdout` instead of `stderr`, just as with cargo-audit. /// /// Note that this flag only applies when the output format is JSON, and note that since cargo-deny supports multiple advisory databases, instead of a single JSON object, there will be 1 for each unique advisory database. - #[clap(long, action)] + #[arg(long)] pub audit_compatible_output: bool, /// Show stats for all the checks, regardless of the log-level - #[clap(short, long, action)] + #[arg(short, long)] pub show_stats: bool, - #[clap(flatten)] + #[command(flatten)] pub lint_levels: LintLevels, /// Specifies the depth at which feature edges are added in inclusion graphs - #[clap(long, conflicts_with = "hide_inclusion_graph")] + #[arg(long, conflicts_with = "hide_inclusion_graph")] pub feature_depth: Option, /// The check(s) to perform - #[clap(value_enum, action)] + #[arg(value_enum)] pub which: Vec, } diff --git a/src/cargo-deny/fetch.rs b/src/cargo-deny/fetch.rs index 73dbb8ea5..7ad420eb1 100644 --- a/src/cargo-deny/fetch.rs +++ b/src/cargo-deny/fetch.rs @@ -17,10 +17,10 @@ pub struct Args { /// Path to the config to use /// /// Defaults to /deny.toml if not specified - #[clap(short, long, action)] + #[arg(short, long)] config: Option, /// The sources to fetch - #[clap(value_enum, action)] + #[arg(value_enum)] sources: Vec, } diff --git a/src/cargo-deny/init.rs b/src/cargo-deny/init.rs index 6a4eb3f6b..ef6c2316a 100644 --- a/src/cargo-deny/init.rs +++ b/src/cargo-deny/init.rs @@ -6,7 +6,6 @@ pub struct Args { /// The path to create /// /// Defaults to /deny.toml - #[clap(action)] config: Option, } diff --git a/src/cargo-deny/list.rs b/src/cargo-deny/list.rs index 88a975f99..b116be019 100644 --- a/src/cargo-deny/list.rs +++ b/src/cargo-deny/list.rs @@ -21,20 +21,20 @@ pub struct Args { /// Path to the config to use /// /// Defaults to a deny.toml in the same folder as the manifest path, or a deny.toml in a parent directory. - #[clap(short, long, action)] + #[arg(short, long)] config: Option, /// Minimum confidence threshold for license text /// /// When determining the license from file contents, a confidence score is assigned according to how close the contents are to the canonical license text. If the confidence score is below this threshold, they license text will ignored, which might mean the crate is treated as unlicensed. /// /// [possible values: 0.0 - 1.0] - #[clap(short, long, default_value = "0.8", action)] + #[arg(short, long, default_value = "0.8")] threshold: f32, /// The format of the output - #[clap(short, long, default_value = "human", value_enum, action)] + #[arg(short, long, default_value = "human", value_enum)] format: OutputFormat, /// The layout for the output, does not apply to TSV - #[clap(short, long, default_value = "license", value_enum, action)] + #[arg(short, long, default_value = "license", value_enum)] layout: Layout, } diff --git a/src/cargo-deny/main.rs b/src/cargo-deny/main.rs index fcf3e481f..7e19a8e16 100644 --- a/src/cargo-deny/main.rs +++ b/src/cargo-deny/main.rs @@ -14,16 +14,16 @@ mod stats; #[derive(Subcommand, Debug)] enum Command { /// Checks a project's crate graph - #[clap(name = "check")] + #[command(name = "check")] Check(check::Args), /// Fetches remote data - #[clap(name = "fetch")] + #[command(name = "fetch")] Fetch(fetch::Args), /// Creates a cargo-deny config from a template - #[clap(name = "init")] + #[command(name = "init")] Init(init::Args), /// Outputs a listing of all licenses and the crates that use them - #[clap(name = "list")] + #[command(name = "list")] List(list::Args), } @@ -46,63 +46,63 @@ fn parse_level(s: &str) -> Result { } #[derive(Parser)] -#[clap(rename_all = "kebab-case")] +#[command(rename_all = "kebab-case")] pub(crate) struct GraphContext { /// The path of a Cargo.toml to use as the context for the operation. /// /// By default, the Cargo.toml in the current working directory is used. - #[clap(long, action)] + #[arg(long)] pub(crate) manifest_path: Option, /// If passed, all workspace packages are used as roots for the crate graph. /// /// Automatically assumed if the manifest path points to a virtual manifest. /// /// Normally, if you specify a manifest path that is a member of a workspace, that crate will be the sole root of the crate graph, meaning only other workspace members that are dependencies of that workspace crate will be included in the graph. This overrides that behavior to include all workspace members. - #[clap(long, action)] + #[arg(long)] pub(crate) workspace: bool, /// One or more crates to exclude from the crate graph that is used. /// /// NOTE: Unlike cargo, this does not have to be used with the `--workspace` flag. - #[clap(long, action)] + #[arg(long)] pub(crate) exclude: Vec, /// One or more platforms to filter crates by /// /// If a dependency is target specific, it will be ignored if it does not match 1 or more of the specified targets. This option overrides the top-level `targets = []` configuration value. - #[clap(short, long, action)] + #[arg(short, long)] pub(crate) target: Vec, /// Activate all available features - #[clap(long, action)] + #[arg(long)] pub(crate) all_features: bool, /// Do not activate the `default` feature - #[clap(long, action)] + #[arg(long)] pub(crate) no_default_features: bool, /// Space or comma separated list of features to activate - #[clap(long, use_value_delimiter = true, action)] + #[arg(long, value_delimiter = ',')] pub(crate) features: Vec, /// Require Cargo.lock and cache are up to date - #[clap(long, action)] + #[arg(long)] pub(crate) frozen: bool, /// Require Cargo.lock is up to date - #[clap(long, action)] + #[arg(long)] pub(crate) locked: bool, /// Run without accessing the network. /// /// If used with the `check` subcommand, this disables advisory database /// fetching - #[clap(long, action)] + #[arg(long)] pub(crate) offline: bool, /// If set, the crates.io git index is initialized for use in fetching crate information, otherwise it is enabled /// only if using a cargo < 1.70.0 without the sparse protocol enabled - #[clap(long, action)] + #[arg(long)] pub(crate) allow_git_index: bool, } /// Lints your project's crate graph #[derive(Parser)] -#[clap(author, version, about, long_about = None, rename_all = "kebab-case", max_term_width = 80)] +#[command(author, version, about, long_about = None, rename_all = "kebab-case", max_term_width = 80)] struct Opts { /// The log level for messages - #[clap( + #[arg( short = 'L', long = "log-level", default_value = "warn", @@ -121,15 +121,14 @@ Possible values: ")] log_level: log::LevelFilter, /// Specify the format of cargo-deny's output - #[clap(short, long, default_value = "human", value_enum, action)] + #[arg(short, long, default_value = "human", value_enum)] format: Format, - #[clap( + #[arg( short, long, default_value = "auto", value_enum, - env = "CARGO_TERM_COLOR", - action + env = "CARGO_TERM_COLOR" )] color: Color, #[clap(flatten)]