Skip to content

Commit

Permalink
Update clap deprecated api (#547)
Browse files Browse the repository at this point in the history
This pull request updates `clap`'s deprecated API.
  • Loading branch information
tottoto committed Aug 18, 2023
1 parent 2f22b00 commit 76ca38b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 41 deletions.
24 changes: 12 additions & 12 deletions src/cargo-deny/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CodeOrLevel>,
/// Set lint allowed
#[clap(long, short = 'A')]
#[arg(long, short = 'A')]
allow: Vec<CodeOrLevel>,
/// Set lint denied
#[clap(long, short = 'D')]
#[arg(long, short = 'D')]
deny: Vec<CodeOrLevel>,
}

Expand All @@ -76,38 +76,38 @@ pub struct Args {
/// Path to the config to use
///
/// Defaults to <cwd>/deny.toml if not specified
#[clap(short, long, action)]
#[arg(short, long)]
pub config: Option<PathBuf>,
/// 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 <dir>/graph_output/<crate_name>.dot. <dir>/graph_output/* is deleted and recreated each run.
#[clap(short, long, action)]
#[arg(short, long)]
pub graph: Option<PathBuf>,
/// 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<u32>,
/// The check(s) to perform
#[clap(value_enum, action)]
#[arg(value_enum)]
pub which: Vec<WhichCheck>,
}

Expand Down
4 changes: 2 additions & 2 deletions src/cargo-deny/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ pub struct Args {
/// Path to the config to use
///
/// Defaults to <cwd>/deny.toml if not specified
#[clap(short, long, action)]
#[arg(short, long)]
config: Option<PathBuf>,
/// The sources to fetch
#[clap(value_enum, action)]
#[arg(value_enum)]
sources: Vec<FetchSource>,
}

Expand Down
1 change: 0 additions & 1 deletion src/cargo-deny/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pub struct Args {
/// The path to create
///
/// Defaults to <cwd>/deny.toml
#[clap(action)]
config: Option<PathBuf>,
}

Expand Down
8 changes: 4 additions & 4 deletions src/cargo-deny/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,
/// 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,
}

Expand Down
43 changes: 21 additions & 22 deletions src/cargo-deny/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}

Expand All @@ -46,63 +46,63 @@ fn parse_level(s: &str) -> Result<log::LevelFilter, Error> {
}

#[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<PathBuf>,
/// 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<String>,
/// 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<String>,
/// 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<String>,
/// 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",
Expand All @@ -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)]
Expand Down

0 comments on commit 76ca38b

Please sign in to comment.