diff --git a/Cargo.lock b/Cargo.lock index 31e783b6..0dab8fef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -316,9 +316,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "3.1.18" +version = "3.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2dbdf4bdacb33466e854ce889eee8dfd5729abf7ccd7664d0a2d60cd384440b" +checksum = "a836566fa5f52f7ddf909a8a2f9029b9f78ca584cd95cf7e87f8073110f4c5c9" dependencies = [ "atty", "bitflags", @@ -333,9 +333,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "3.1.18" +version = "3.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25320346e922cffe59c0bbc5410c8d8784509efb321488971081313cb1e1a33c" +checksum = "986fd75d1dfd2c34eb8c9275ae38ad87ea9478c9b79e87f1801f7d866dfb1e37" dependencies = [ "heck", "proc-macro-error", @@ -346,9 +346,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.2.0" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a37c35f1112dad5e6e0b1adaff798507497a18fceeb30cceb3bae7d1427b9213" +checksum = "5538cd660450ebeb4234cfecf8f2284b844ffc4c50531e66d584ad5b91293613" dependencies = [ "os_str_bytes", ] diff --git a/Cargo.toml b/Cargo.toml index 994a2b26..0b7220f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,7 +48,7 @@ bitvec = { version = "1.0", features = ["alloc"] } # Allows us to do eg cargo metadata operations without relying on an external cargo cargo = { version = "0.61", optional = true } # Argument parsing -clap = { version = "3.1", features = ["derive", "env"] } +clap = { version = "3.2.1", features = ["derive", "env"] } # Used for diagnostic reporting codespan = "0.11" codespan-reporting = "0.11" diff --git a/src/cargo-deny/check.rs b/src/cargo-deny/check.rs index b0c809ab..a75f9f68 100644 --- a/src/cargo-deny/check.rs +++ b/src/cargo-deny/check.rs @@ -9,7 +9,7 @@ use log::error; use serde::Deserialize; use std::{path::PathBuf, time::Instant}; -#[derive(clap::ArgEnum, Debug, PartialEq, Copy, Clone)] +#[derive(clap::ValueEnum, Debug, PartialEq, Copy, Clone)] pub enum WhichCheck { Advisories, Ban, @@ -25,33 +25,33 @@ pub struct Args { /// Path to the config to use /// /// Defaults to /deny.toml if not specified - #[clap(short, long, parse(from_os_str))] + #[clap(short, long, action)] 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, parse(from_os_str))] + #[clap(short, long, action)] pub graph: Option, /// Hides the inclusion graph when printing out info for a crate - #[clap(long)] + #[clap(long, action)] 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)] + #[clap(short, long, action)] 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)] + #[clap(long, action)] pub audit_compatible_output: bool, /// Show stats for all the checks, regardless of the log-level - #[clap(short, long = "show-stats")] + #[clap(short, long, action)] pub show_stats: bool, /// The check(s) to perform - #[clap(arg_enum)] + #[clap(value_enum, action)] pub which: Vec, } diff --git a/src/cargo-deny/fetch.rs b/src/cargo-deny/fetch.rs index a08b5486..0d4bda30 100644 --- a/src/cargo-deny/fetch.rs +++ b/src/cargo-deny/fetch.rs @@ -5,7 +5,7 @@ use cargo_deny::{ }; use std::path::PathBuf; -#[derive(clap::ArgEnum, Debug, PartialEq, Copy, Clone)] +#[derive(clap::ValueEnum, Debug, PartialEq, Copy, Clone)] pub enum FetchSource { Db, Index, @@ -17,10 +17,10 @@ pub struct Args { /// Path to the config to use /// /// Defaults to /deny.toml if not specified - #[clap(short, long, parse(from_os_str))] + #[clap(short, long, action)] config: Option, /// The sources to fetch - #[clap(arg_enum)] + #[clap(value_enum, action)] sources: Vec, } diff --git a/src/cargo-deny/init.rs b/src/cargo-deny/init.rs index a3a35b14..5a045bc0 100644 --- a/src/cargo-deny/init.rs +++ b/src/cargo-deny/init.rs @@ -6,7 +6,7 @@ pub struct Args { /// The path to create /// /// Defaults to /deny.toml - #[clap(parse(from_os_str))] + #[clap(action)] config: Option, } diff --git a/src/cargo-deny/list.rs b/src/cargo-deny/list.rs index 49ed7102..c2c11593 100644 --- a/src/cargo-deny/list.rs +++ b/src/cargo-deny/list.rs @@ -4,13 +4,13 @@ use cargo_deny::{diag::Files, licenses, Kid}; use serde::Serialize; use std::path::PathBuf; -#[derive(clap::ArgEnum, Copy, Clone, Debug)] +#[derive(clap::ValueEnum, Copy, Clone, Debug)] pub enum Layout { Crate, License, } -#[derive(clap::ArgEnum, Copy, Clone, Debug)] +#[derive(clap::ValueEnum, Copy, Clone, Debug)] pub enum OutputFormat { Human, Json, @@ -22,20 +22,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, parse(from_os_str))] + #[clap(short, long, action)] 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")] + #[clap(short, long, default_value = "0.8", action)] threshold: f32, /// The format of the output - #[clap(short, long, default_value = "human", arg_enum)] + #[clap(short, long, default_value = "human", value_enum, action)] format: OutputFormat, /// The layout for the output, does not apply to TSV - #[clap(short, long, default_value = "license", arg_enum)] + #[clap(short, long, default_value = "license", value_enum, action)] layout: Layout, } diff --git a/src/cargo-deny/main.rs b/src/cargo-deny/main.rs index cad16eab..7eb25a97 100644 --- a/src/cargo-deny/main.rs +++ b/src/cargo-deny/main.rs @@ -80,7 +80,7 @@ #![allow(clippy::exit, clippy::single_match_else)] use anyhow::{bail, Context, Error}; -use clap::{Parser, Subcommand}; +use clap::{Parser, Subcommand, ValueEnum}; use std::path::PathBuf; mod check; @@ -106,60 +106,19 @@ enum Command { List(list::Args), } -#[derive(Parser, Copy, Clone, Debug, PartialEq)] +#[derive(ValueEnum, Copy, Clone, Debug, PartialEq)] pub enum Format { Human, Json, } -impl Format { - fn variants() -> &'static [&'static str] { - &["human", "json"] - } -} - -impl std::str::FromStr for Format { - type Err = Error; - - fn from_str(s: &str) -> Result { - let lower = s.to_ascii_lowercase(); - - Ok(match lower.as_str() { - "human" => Self::Human, - "json" => Self::Json, - _ => bail!("unknown output format '{}' specified", s), - }) - } -} - -#[derive(Parser, Copy, Clone, Debug)] +#[derive(ValueEnum, Copy, Clone, Debug)] pub enum Color { Auto, Always, Never, } -impl Color { - fn variants() -> &'static [&'static str] { - &["auto", "always", "never"] - } -} - -impl std::str::FromStr for Color { - type Err = Error; - - fn from_str(s: &str) -> Result { - let lower = s.to_ascii_lowercase(); - - Ok(match lower.as_str() { - "auto" => Self::Auto, - "always" => Self::Always, - "never" => Self::Never, - _ => bail!("unknown color option '{}' specified", s), - }) - } -} - fn parse_level(s: &str) -> Result { s.parse::() .with_context(|| format!("failed to parse level '{}'", s)) @@ -171,42 +130,42 @@ 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, parse(from_os_str))] + #[clap(long, action)] 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)] + #[clap(long, action)] 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)] + #[clap(long, action)] 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)] + #[clap(short, long, action)] pub(crate) target: Vec, /// Activate all available features - #[clap(long)] + #[clap(long, action)] pub(crate) all_features: bool, /// Do not activate the `default` feature - #[clap(long)] + #[clap(long, action)] pub(crate) no_default_features: bool, /// Space or comma separated list of features to activate - #[clap(long, use_value_delimiter = true)] + #[clap(long, use_value_delimiter = true, action)] pub(crate) features: Vec, /// Require Cargo.lock and cache are up to date - #[clap(long)] + #[clap(long, action)] pub(crate) frozen: bool, /// Require Cargo.lock is up to date - #[clap(long)] + #[clap(long, action)] pub(crate) locked: bool, /// Run without accessing the network. If used with the `check` subcommand, this also disables advisory database fetching. - #[clap(long)] + #[clap(long, action)] pub(crate) offline: bool, } @@ -219,7 +178,7 @@ struct Opts { short = 'L', long = "log-level", default_value = "warn", - parse(try_from_str = parse_level), + value_parser = parse_level, long_help = "The log level for messages Only log messages at or above the level will be emitted. @@ -234,9 +193,16 @@ Possible values: ")] log_level: log::LevelFilter, /// Specify the format of cargo-deny's output - #[clap(short, long, default_value = "human", possible_values = Format::variants())] + #[clap(short, long, default_value = "human", value_enum, action)] format: Format, - #[clap(short, long, default_value = "auto", possible_values = Color::variants(), env = "CARGO_TERM_COLOR")] + #[clap( + short, + long, + default_value = "auto", + value_enum, + env = "CARGO_TERM_COLOR", + action + )] color: Color, #[clap(flatten)] ctx: GraphContext,