]> git.lizzy.rs Git - rust.git/blobdiff - src/tools/clippy/lintcheck/src/config.rs
Merge commit 'd7b5cbf065b88830ca519adcb73fad4c0d24b1c7' into clippyup
[rust.git] / src / tools / clippy / lintcheck / src / config.rs
index a6f93d2a1c0a62177f8b55a59c4a2b0ae549e18f..1742cf677c0f9fefad4e3791012b4f674bd4c2f0 100644 (file)
@@ -1,50 +1,40 @@
-use clap::{Arg, ArgMatches, Command};
+use clap::{Arg, ArgAction, ArgMatches, Command};
 use std::env;
 use std::path::PathBuf;
 
 fn get_clap_config() -> ArgMatches {
     Command::new("lintcheck")
         .about("run clippy on a set of crates and check output")
-        .arg(
+        .args([
             Arg::new("only")
-                .takes_value(true)
+                .action(ArgAction::Set)
                 .value_name("CRATE")
                 .long("only")
                 .help("Only process a single crate of the list"),
-        )
-        .arg(
             Arg::new("crates-toml")
-                .takes_value(true)
+                .action(ArgAction::Set)
                 .value_name("CRATES-SOURCES-TOML-PATH")
                 .long("crates-toml")
                 .help("Set the path for a crates.toml where lintcheck should read the sources from"),
-        )
-        .arg(
             Arg::new("threads")
-                .takes_value(true)
+                .action(ArgAction::Set)
                 .value_name("N")
+                .value_parser(clap::value_parser!(usize))
                 .short('j')
                 .long("jobs")
                 .help("Number of threads to use, 0 automatic choice"),
-        )
-        .arg(
             Arg::new("fix")
-                .long("--fix")
+                .long("fix")
                 .help("Runs cargo clippy --fix and checks if all suggestions apply"),
-        )
-        .arg(
             Arg::new("filter")
-                .long("--filter")
-                .takes_value(true)
-                .multiple_occurrences(true)
+                .long("filter")
+                .action(ArgAction::Append)
                 .value_name("clippy_lint_name")
                 .help("Apply a filter to only collect specified lints, this also overrides `allow` attributes"),
-        )
-        .arg(
             Arg::new("markdown")
-                .long("--markdown")
+                .long("markdown")
                 .help("Change the reports table to use markdown links"),
-        )
+        ])
         .get_matches()
 }
 
@@ -75,13 +65,13 @@ pub fn new() -> Self {
         // if not, use the default "lintcheck/lintcheck_crates.toml"
         let sources_toml = env::var("LINTCHECK_TOML").unwrap_or_else(|_| {
             clap_config
-                .value_of("crates-toml")
-                .clone()
+                .get_one::<String>("crates-toml")
+                .map(|s| &**s)
                 .unwrap_or("lintcheck/lintcheck_crates.toml")
-                .to_string()
+                .into()
         });
 
-        let markdown = clap_config.is_present("markdown");
+        let markdown = clap_config.contains_id("markdown");
         let sources_toml_path = PathBuf::from(sources_toml);
 
         // for the path where we save the lint results, get the filename without extension (so for
@@ -96,25 +86,19 @@ pub fn new() -> Self {
         // look at the --threads arg, if 0 is passed, ask rayon rayon how many threads it would spawn and
         // use half of that for the physical core count
         // by default use a single thread
-        let max_jobs = match clap_config.value_of("threads") {
-            Some(threads) => {
-                let threads: usize = threads
-                    .parse()
-                    .unwrap_or_else(|_| panic!("Failed to parse '{}' to a digit", threads));
-                if threads == 0 {
-                    // automatic choice
-                    // Rayon seems to return thread count so half that for core count
-                    (rayon::current_num_threads() / 2) as usize
-                } else {
-                    threads
-                }
+        let max_jobs = match clap_config.get_one::<usize>("threads") {
+            Some(&0) => {
+                // automatic choice
+                // Rayon seems to return thread count so half that for core count
+                (rayon::current_num_threads() / 2) as usize
             },
+            Some(&threads) => threads,
             // no -j passed, use a single thread
             None => 1,
         };
 
         let lint_filter: Vec<String> = clap_config
-            .values_of("filter")
+            .get_many::<String>("filter")
             .map(|iter| {
                 iter.map(|lint_name| {
                     let mut filter = lint_name.replace('_', "-");
@@ -131,8 +115,8 @@ pub fn new() -> Self {
             max_jobs,
             sources_toml_path,
             lintcheck_results_path,
-            only: clap_config.value_of("only").map(String::from),
-            fix: clap_config.is_present("fix"),
+            only: clap_config.get_one::<String>("only").map(String::from),
+            fix: clap_config.contains_id("fix"),
             lint_filter,
             markdown,
         }