refactor: Upgrade to clap v4

This commit is contained in:
Ed Page 2022-09-28 15:53:45 -05:00
parent fd5abef1a7
commit 5998342bb2
3 changed files with 90 additions and 55 deletions

57
Cargo.lock generated
View file

@ -157,8 +157,8 @@ checksum = "68d43934757334b5c0519ff882e1ab9647ac0258b47c24c4f490d78e42697fd5"
dependencies = [ dependencies = [
"atty", "atty",
"bitflags", "bitflags",
"clap_derive", "clap_derive 3.2.18",
"clap_lex", "clap_lex 0.2.4",
"indexmap", "indexmap",
"once_cell", "once_cell",
"strsim 0.10.0", "strsim 0.10.0",
@ -167,12 +167,27 @@ dependencies = [
] ]
[[package]] [[package]]
name = "clap-verbosity-flag" name = "clap"
version = "1.0.1" version = "4.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0636f9c040082f8e161555a305f8cec1a1c2828b3d981c812b8c39f4ac00c42c" checksum = "dd03107d0f87139c1774a15f3db2165b0652b5460c58c27e561f89c20c599eaf"
dependencies = [ dependencies = [
"clap 3.2.19", "atty",
"bitflags",
"clap_derive 4.0.1",
"clap_lex 0.3.0",
"once_cell",
"strsim 0.10.0",
"termcolor",
]
[[package]]
name = "clap-verbosity-flag"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23e2b6c3dcdb73299f48ae05b294da14e2f560b3ed2c09e742269eb1b22af231"
dependencies = [
"clap 4.0.1",
"log", "log",
] ]
@ -189,6 +204,19 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "clap_derive"
version = "4.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca689d7434ce44517a12a89456b2be4d1ea1cafcd8f581978c03d45f5a5c12a7"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "clap_lex" name = "clap_lex"
version = "0.2.4" version = "0.2.4"
@ -198,6 +226,15 @@ dependencies = [
"os_str_bytes", "os_str_bytes",
] ]
[[package]]
name = "clap_lex"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8"
dependencies = [
"os_str_bytes",
]
[[package]] [[package]]
name = "codegenrs" name = "codegenrs"
version = "2.0.0" version = "2.0.0"
@ -244,11 +281,11 @@ dependencies = [
[[package]] [[package]]
name = "concolor-clap" name = "concolor-clap"
version = "0.0.10" version = "0.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b35b55e880d42d4626e6a1aa5b4e63a4df61cf024472a31495ecbbb712402985" checksum = "95a363283eeb30dc209fca344607b1b40135bfcca5172aa90fb72d912b992bbf"
dependencies = [ dependencies = [
"clap 3.2.19", "clap 4.0.1",
"concolor", "concolor",
] ]
@ -1491,7 +1528,7 @@ dependencies = [
"assert_fs", "assert_fs",
"atty", "atty",
"bstr", "bstr",
"clap 3.2.19", "clap 4.0.1",
"clap-verbosity-flag", "clap-verbosity-flag",
"concolor", "concolor",
"concolor-clap", "concolor-clap",

View file

@ -58,8 +58,8 @@ typos-dict = { version = "^0.9", path = "crates/typos-dict", optional = true }
typos-vars = { version = "^0.8", path = "crates/typos-vars", optional = true } typos-vars = { version = "^0.8", path = "crates/typos-vars", optional = true }
unicase = "2.6" unicase = "2.6"
anyhow = "1.0" anyhow = "1.0"
clap = "3.2" clap = { version = "4.0.0", features = ["derive"] }
clap-verbosity-flag = "1.0" clap-verbosity-flag = "2.0"
ignore = "0.4" ignore = "0.4"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
toml_edit = { version = "0.14.4", features = ["easy"] } toml_edit = { version = "0.14.4", features = ["easy"] }
@ -68,7 +68,7 @@ env_logger = { version = "0.9", default-features = false, features = ["termcolor
atty = "0.2.14" atty = "0.2.14"
yansi = "0.5.1" yansi = "0.5.1"
concolor = { version = "0.0.8" } concolor = { version = "0.0.8" }
concolor-clap = { version = "0.0.10", features = ["api_unstable"] } concolor-clap = { version = "0.0.11", features = ["api_unstable"] }
bstr = "0.2" bstr = "0.2"
once_cell = "1.13.1" once_cell = "1.13.1"
ahash = "0.8" ahash = "0.8"

View file

@ -2,7 +2,7 @@ use clap::Parser;
use typos_cli::config; use typos_cli::config;
#[derive(Debug, Copy, Clone, PartialEq, Eq, clap::ArgEnum)] #[derive(Debug, Copy, Clone, PartialEq, Eq, clap::ValueEnum)]
pub enum Format { pub enum Format {
Silent, Silent,
Brief, Brief,
@ -38,100 +38,98 @@ impl Default for Format {
} }
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
#[clap(rename_all = "kebab-case")] #[command(rename_all = "kebab-case")]
#[clap(about, author, version)] #[command(about, author, version)]
#[clap( #[command(
setting = clap::AppSettings::DeriveDisplayOrder,
dont_collapse_args_in_usage = true,
color = concolor_clap::color_choice(), color = concolor_clap::color_choice(),
)] )]
#[clap(group = clap::ArgGroup::new("mode").multiple(false))] #[command(group = clap::ArgGroup::new("mode").multiple(false))]
pub(crate) struct Args { pub(crate) struct Args {
#[clap(parse(from_os_str), default_value = ".")] #[arg(default_value = ".")]
/// Paths to check with `-` for stdin /// Paths to check with `-` for stdin
pub(crate) path: Vec<std::path::PathBuf>, pub(crate) path: Vec<std::path::PathBuf>,
#[clap(short = 'c', long = "config", parse(from_os_str))] #[arg(short = 'c', long = "config")]
/// Custom config file /// Custom config file
pub(crate) custom_config: Option<std::path::PathBuf>, pub(crate) custom_config: Option<std::path::PathBuf>,
#[clap(long)] #[arg(long)]
/// Ignore implicit configuration files. /// Ignore implicit configuration files.
pub(crate) isolated: bool, pub(crate) isolated: bool,
#[clap(long, group = "mode")] #[arg(long, group = "mode")]
/// Print a diff of what would change /// Print a diff of what would change
pub(crate) diff: bool, pub(crate) diff: bool,
#[clap(long, short = 'w', group = "mode")] #[arg(long, short = 'w', group = "mode")]
/// Write fixes out /// Write fixes out
pub(crate) write_changes: bool, pub(crate) write_changes: bool,
#[clap(long, group = "mode")] #[arg(long, group = "mode")]
/// Debug: Print each file that would be spellchecked. /// Debug: Print each file that would be spellchecked.
pub(crate) files: bool, pub(crate) files: bool,
#[clap(long, group = "mode")] #[arg(long, group = "mode")]
/// Debug: Print each identifier that would be spellchecked. /// Debug: Print each identifier that would be spellchecked.
pub(crate) identifiers: bool, pub(crate) identifiers: bool,
#[clap(long, group = "mode")] #[arg(long, group = "mode")]
/// Debug: Print each word that would be spellchecked. /// Debug: Print each word that would be spellchecked.
pub(crate) words: bool, pub(crate) words: bool,
#[clap(long, parse(from_os_str), group = "mode")] #[arg(long, group = "mode")]
/// Write the current configuration to file with `-` for stdout /// Write the current configuration to file with `-` for stdout
pub(crate) dump_config: Option<std::path::PathBuf>, pub(crate) dump_config: Option<std::path::PathBuf>,
#[clap(long, group = "mode")] #[arg(long, group = "mode")]
/// Show all supported file types. /// Show all supported file types.
pub(crate) type_list: bool, pub(crate) type_list: bool,
#[clap(long, arg_enum, ignore_case = true, default_value("long"))] #[arg(long, value_enum, ignore_case = true, default_value("long"))]
pub(crate) format: Format, pub(crate) format: Format,
#[clap(short = 'j', long = "threads", default_value = "0")] #[arg(short = 'j', long = "threads", default_value = "0")]
/// The approximate number of threads to use. /// The approximate number of threads to use.
pub(crate) threads: usize, pub(crate) threads: usize,
#[clap(flatten)] #[command(flatten)]
pub(crate) config: ConfigArgs, pub(crate) config: ConfigArgs,
#[clap(flatten)] #[command(flatten)]
pub(crate) color: concolor_clap::Color, pub(crate) color: concolor_clap::Color,
#[clap(flatten)] #[command(flatten)]
pub(crate) verbose: clap_verbosity_flag::Verbosity, pub(crate) verbose: clap_verbosity_flag::Verbosity,
} }
#[derive(Debug, Clone, clap::Args)] #[derive(Debug, Clone, clap::Args)]
#[clap(rename_all = "kebab-case")] #[command(rename_all = "kebab-case")]
pub(crate) struct FileArgs { pub(crate) struct FileArgs {
#[clap(long, overrides_with("no-binary"))] #[arg(long, overrides_with("no_binary"))]
/// Search binary files. /// Search binary files.
binary: bool, binary: bool,
#[clap(long, overrides_with("binary"), hide = true)] #[arg(long, overrides_with("binary"), hide = true)]
no_binary: bool, no_binary: bool,
#[clap(long, overrides_with("check-filenames"))] #[arg(long, overrides_with("check_filenames"))]
/// Skip verifying spelling in file names. /// Skip verifying spelling in file names.
no_check_filenames: bool, no_check_filenames: bool,
#[clap(long, overrides_with("no-check-filenames"), hide = true)] #[arg(long, overrides_with("no_check_filenames"), hide = true)]
check_filenames: bool, check_filenames: bool,
#[clap(long, overrides_with("check-files"))] #[arg(long, overrides_with("check_files"))]
/// Skip verifying spelling in files. /// Skip verifying spelling in files.
no_check_files: bool, no_check_files: bool,
#[clap(long, overrides_with("no-check-files"), hide = true)] #[arg(long, overrides_with("no_check_files"), hide = true)]
check_files: bool, check_files: bool,
#[clap(long, overrides_with("no-unicode"), hide = true)] #[arg(long, overrides_with("no_unicode"), hide = true)]
unicode: bool, unicode: bool,
#[clap(long, overrides_with("unicode"))] #[arg(long, overrides_with("unicode"))]
/// Only allow ASCII characters in identifiers /// Only allow ASCII characters in identifiers
no_unicode: bool, no_unicode: bool,
#[clap(long, possible_values(config::Locale::variants()))] #[arg(long, value_parser = clap::builder::PossibleValuesParser::new(config::Locale::variants()))]
pub(crate) locale: Option<config::Locale>, pub(crate) locale: Option<config::Locale>,
} }
@ -195,7 +193,7 @@ pub(crate) struct WalkArgs {
/// Ignore files & directories matching the glob. /// Ignore files & directories matching the glob.
exclude: Vec<String>, exclude: Vec<String>,
#[clap(long, overrides_with("no-hidden"))] #[clap(long, overrides_with("no_hidden"))]
/// Search hidden files and directories. /// Search hidden files and directories.
hidden: bool, hidden: bool,
#[clap(long, overrides_with("hidden"), hide = true)] #[clap(long, overrides_with("hidden"), hide = true)]
@ -204,31 +202,31 @@ pub(crate) struct WalkArgs {
#[clap(long, overrides_with("ignore"))] #[clap(long, overrides_with("ignore"))]
/// Don't respect ignore files. /// Don't respect ignore files.
no_ignore: bool, no_ignore: bool,
#[clap(long, overrides_with("no-ignore"), hide = true)] #[clap(long, overrides_with("no_ignore"), hide = true)]
ignore: bool, ignore: bool,
#[clap(long, overrides_with("ignore-dot"))] #[clap(long, overrides_with("ignore_dot"))]
/// Don't respect .ignore files. /// Don't respect .ignore files.
no_ignore_dot: bool, no_ignore_dot: bool,
#[clap(long, overrides_with("no-ignore-dot"), hide = true)] #[clap(long, overrides_with("no_ignore_dot"), hide = true)]
ignore_dot: bool, ignore_dot: bool,
#[clap(long, overrides_with("ignore-global"))] #[clap(long, overrides_with("ignore_global"))]
/// Don't respect global ignore files. /// Don't respect global ignore files.
no_ignore_global: bool, no_ignore_global: bool,
#[clap(long, overrides_with("no-ignore-global"), hide = true)] #[clap(long, overrides_with("no_ignore_global"), hide = true)]
ignore_global: bool, ignore_global: bool,
#[clap(long, overrides_with("ignore-parent"))] #[clap(long, overrides_with("ignore_parent"))]
/// Don't respect ignore files in parent directories. /// Don't respect ignore files in parent directories.
no_ignore_parent: bool, no_ignore_parent: bool,
#[clap(long, overrides_with("no-ignore-parent"), hide = true)] #[clap(long, overrides_with("no_ignore_parent"), hide = true)]
ignore_parent: bool, ignore_parent: bool,
#[clap(long, overrides_with("ignore-vcs"))] #[clap(long, overrides_with("ignore_vcs"))]
/// Don't respect ignore files in vcs directories. /// Don't respect ignore files in vcs directories.
no_ignore_vcs: bool, no_ignore_vcs: bool,
#[clap(long, overrides_with("no-ignore-vcs"), hide = true)] #[clap(long, overrides_with("no_ignore_vcs"), hide = true)]
ignore_vcs: bool, ignore_vcs: bool,
} }