mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-25 02:20:58 -05:00
chore: Upgrade structopt
This commit is contained in:
parent
948eb0e281
commit
5e6e4b9ad7
3 changed files with 51 additions and 102 deletions
47
Cargo.lock
generated
47
Cargo.lock
generated
|
@ -118,13 +118,11 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "clap-verbosity-flag"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"structopt 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"structopt 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -206,18 +204,6 @@ name = "either"
|
|||
version = "1.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.5.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.6.2"
|
||||
|
@ -757,15 +743,6 @@ name = "strsim"
|
|||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "structopt"
|
||||
version = "0.2.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"structopt-derive 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "structopt"
|
||||
version = "0.3.2"
|
||||
|
@ -775,17 +752,6 @@ dependencies = [
|
|||
"structopt-derive 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "structopt-derive"
|
||||
version = "0.2.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "structopt-derive"
|
||||
version = "0.3.2"
|
||||
|
@ -902,13 +868,13 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"assert_fs 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"clap-verbosity-flag 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"clap-verbosity-flag 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ignore 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"structopt 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"structopt 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"typos 0.1.0",
|
||||
"typos-dict 0.1.0",
|
||||
|
@ -1040,7 +1006,7 @@ dependencies = [
|
|||
"checksum cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)" = "4fc9a35e1f4290eb9e5fc54ba6cf40671ed2a2514c3eeb2b2a908dda2ea5a1be"
|
||||
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
||||
"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
|
||||
"checksum clap-verbosity-flag 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bda14f5323b2b747f52908c5b7b8af7790784088bc7c2957a11695e39ad476dc"
|
||||
"checksum clap-verbosity-flag 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "177e9a28add9de161079047d67bcaab629bdfb542c6908f838bfc4cecb3d7f63"
|
||||
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
|
||||
"checksum codegenrs 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "71084cba3c8e4a3f9bc1a838ce259570fca6f2e360da3657c1b8c1185786329d"
|
||||
"checksum crossbeam-channel 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c8ec7fcd21571dc78f96cc96243cab8d8f035247c3efd16c687be154c3fa9efa"
|
||||
|
@ -1050,7 +1016,6 @@ dependencies = [
|
|||
"checksum derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a141330240c921ec6d074a3e188a7c7ef95668bb95e7d44fa0e5778ec2a7afe"
|
||||
"checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
|
||||
"checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
|
||||
"checksum env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)" = "15b0a4d2e39f8420210be8b27eeda28029729e2fd4291019455016c348240c38"
|
||||
"checksum env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aafcde04e90a5226a6443b7aabdb016ba2f8307c847d524724bd9b346dd1a2d3"
|
||||
"checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2"
|
||||
"checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1"
|
||||
|
@ -1117,9 +1082,7 @@ dependencies = [
|
|||
"checksum serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)" = "2f72eb2a68a7dc3f9a691bfda9305a1c017a6215e5a4545c258500d2099a37c2"
|
||||
"checksum siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac"
|
||||
"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
||||
"checksum structopt 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "16c2cdbf9cc375f15d1b4141bc48aeef444806655cd0e904207edc8d68d86ed7"
|
||||
"checksum structopt 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe8d3289b63ef2f196d89e7701f986583c0895e764b78f052a55b9b5d34d84a"
|
||||
"checksum structopt-derive 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "53010261a84b37689f9ed7d395165029f9cc7abb9f56bbfe86bee2597ed25107"
|
||||
"checksum structopt-derive 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f3add731f5b4fb85931d362a3c92deb1ad7113649a8d51701fb257673705f122"
|
||||
"checksum syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)" = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5"
|
||||
"checksum syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "66850e97125af79138385e9b88339cbcd037e3f28ceab8c5ad98e64f0f1f80bf"
|
||||
|
|
|
@ -25,9 +25,9 @@ iterate_unstable = []
|
|||
typos = { version = "0.1", path = "typos" }
|
||||
typos-dict = { version = "0.1", path = "typos-dict" }
|
||||
failure = "0.1"
|
||||
structopt = "0.2"
|
||||
structopt = "0.3"
|
||||
clap = "2"
|
||||
clap-verbosity-flag = "0.2.0"
|
||||
clap-verbosity-flag = "0.3"
|
||||
ignore = "0.4"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
toml = "0.4"
|
||||
|
|
102
src/main.rs
102
src/main.rs
|
@ -46,7 +46,7 @@ struct Args {
|
|||
/// Custom config file
|
||||
custom_config: Option<std::path::PathBuf>,
|
||||
|
||||
#[structopt(long = "isolated")]
|
||||
#[structopt(long)]
|
||||
/// Ignore implicit configuration files.
|
||||
isolated: bool,
|
||||
|
||||
|
@ -54,9 +54,10 @@ struct Args {
|
|||
overrides: FileArgs,
|
||||
|
||||
#[structopt(
|
||||
long = "format",
|
||||
raw(possible_values = "&Format::variants()", case_insensitive = "true"),
|
||||
default_value = "long"
|
||||
long,
|
||||
possible_values(&Format::variants()),
|
||||
case_insensitive(true),
|
||||
default_value("long")
|
||||
)]
|
||||
pub format: Format,
|
||||
|
||||
|
@ -70,30 +71,22 @@ struct Args {
|
|||
#[derive(Debug, StructOpt)]
|
||||
#[structopt(rename_all = "kebab-case")]
|
||||
pub struct FileArgs {
|
||||
#[structopt(long, raw(overrides_with = r#""check-filenames""#))]
|
||||
#[structopt(long, overrides_with("check-filenames"))]
|
||||
/// Skip verifying spelling in file names.
|
||||
no_check_filenames: bool,
|
||||
#[structopt(
|
||||
long,
|
||||
raw(overrides_with = r#""no-check-filenames""#),
|
||||
raw(hidden = "true")
|
||||
)]
|
||||
#[structopt(long, overrides_with("no-check-filenames"), hidden(true))]
|
||||
check_filenames: bool,
|
||||
|
||||
#[structopt(long, raw(overrides_with = r#""check-files""#))]
|
||||
#[structopt(long, overrides_with("check-files"))]
|
||||
/// Skip verifying spelling in filess.
|
||||
no_check_files: bool,
|
||||
#[structopt(
|
||||
long,
|
||||
raw(overrides_with = r#""no-check-files""#),
|
||||
raw(hidden = "true")
|
||||
)]
|
||||
#[structopt(long, overrides_with("no-check-files"), hidden(true))]
|
||||
check_files: bool,
|
||||
|
||||
#[structopt(long, raw(overrides_with = r#""hex""#))]
|
||||
#[structopt(long, overrides_with("hex"))]
|
||||
/// Don't try to detect that an identifier looks like hex
|
||||
no_hex: bool,
|
||||
#[structopt(long, raw(overrides_with = r#""no-hex""#), raw(hidden = "true"))]
|
||||
#[structopt(long, overrides_with("no-hex"), hidden(true))]
|
||||
hex: bool,
|
||||
}
|
||||
|
||||
|
@ -142,54 +135,46 @@ impl config::ConfigSource for ConfigArgs {
|
|||
#[derive(Debug, StructOpt)]
|
||||
#[structopt(rename_all = "kebab-case")]
|
||||
struct WalkArgs {
|
||||
#[structopt(long, raw(overrides_with = r#""no-binary""#))]
|
||||
#[structopt(long, overrides_with("no-binary"))]
|
||||
/// Search binary files.
|
||||
binary: bool,
|
||||
#[structopt(long, raw(overrides_with = r#""binary""#), raw(hidden = "true"))]
|
||||
#[structopt(long, overrides_with("binary"), hidden(true))]
|
||||
no_binary: bool,
|
||||
|
||||
#[structopt(long, raw(overrides_with = r#""no-hidden""#))]
|
||||
#[structopt(long, overrides_with("no-hidden"))]
|
||||
/// Search hidden files and directories.
|
||||
hidden: bool,
|
||||
#[structopt(long, raw(overrides_with = r#""hidden""#), raw(hidden = "true"))]
|
||||
#[structopt(long, overrides_with("hidden"), hidden(true))]
|
||||
no_hidden: bool,
|
||||
|
||||
#[structopt(long, raw(overrides_with = r#""ignore""#))]
|
||||
#[structopt(long, overrides_with("ignore"))]
|
||||
/// Don't respect ignore files.
|
||||
no_ignore: bool,
|
||||
#[structopt(long, raw(overrides_with = r#""no-ignore""#), raw(hidden = "true"))]
|
||||
#[structopt(long, overrides_with("no-ignore"), hidden(true))]
|
||||
ignore: bool,
|
||||
|
||||
#[structopt(long, raw(overrides_with = r#""ignore-dot""#))]
|
||||
#[structopt(long, overrides_with("ignore-dot"))]
|
||||
/// Don't respect .ignore files.
|
||||
no_ignore_dot: bool,
|
||||
#[structopt(long, raw(overrides_with = r#""no-ignore-dot""#), raw(hidden = "true"))]
|
||||
#[structopt(long, overrides_with("no-ignore-dot"), hidden(true))]
|
||||
ignore_dot: bool,
|
||||
|
||||
#[structopt(long, raw(overrides_with = r#""ignore-global""#))]
|
||||
#[structopt(long, overrides_with("ignore-global"))]
|
||||
/// Don't respect global ignore files.
|
||||
no_ignore_global: bool,
|
||||
#[structopt(
|
||||
long,
|
||||
raw(overrides_with = r#""no-ignore-global""#),
|
||||
raw(hidden = "true")
|
||||
)]
|
||||
#[structopt(long, overrides_with("no-ignore-global"), hidden(true))]
|
||||
ignore_global: bool,
|
||||
|
||||
#[structopt(long, raw(overrides_with = r#""ignore-parent""#))]
|
||||
#[structopt(long, overrides_with("ignore-parent"))]
|
||||
/// Don't respect ignore files in parent directories.
|
||||
no_ignore_parent: bool,
|
||||
#[structopt(
|
||||
long,
|
||||
raw(overrides_with = r#""no-ignore-parent""#),
|
||||
raw(hidden = "true")
|
||||
)]
|
||||
#[structopt(long, overrides_with("no-ignore-parent"), hidden(true))]
|
||||
ignore_parent: bool,
|
||||
|
||||
#[structopt(long, raw(overrides_with = r#""ignore-vcs""#))]
|
||||
#[structopt(long, overrides_with("ignore-vcs"))]
|
||||
/// Don't respect ignore files in vcs directories.
|
||||
no_ignore_vcs: bool,
|
||||
#[structopt(long, raw(overrides_with = r#""no-ignore-vcs""#), raw(hidden = "true"))]
|
||||
#[structopt(long, overrides_with("no-ignore-vcs"), hidden(true))]
|
||||
ignore_vcs: bool,
|
||||
}
|
||||
|
||||
|
@ -258,32 +243,33 @@ impl config::WalkSource for WalkArgs {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_logging(level: log::Level) -> env_logger::Builder {
|
||||
let mut builder = env_logger::Builder::new();
|
||||
pub fn init_logging(level: Option<log::Level>) {
|
||||
if let Some(level) = level {
|
||||
let mut builder = env_logger::Builder::new();
|
||||
|
||||
builder.filter(None, level.to_level_filter());
|
||||
builder.filter(None, level.to_level_filter());
|
||||
|
||||
if level == log::LevelFilter::Trace {
|
||||
builder.default_format_timestamp(false);
|
||||
} else {
|
||||
builder.format(|f, record| {
|
||||
writeln!(
|
||||
f,
|
||||
"[{}] {}",
|
||||
record.level().to_string().to_lowercase(),
|
||||
record.args()
|
||||
)
|
||||
});
|
||||
if level == log::LevelFilter::Trace {
|
||||
builder.default_format_timestamp(false);
|
||||
} else {
|
||||
builder.format(|f, record| {
|
||||
writeln!(
|
||||
f,
|
||||
"[{}] {}",
|
||||
record.level().to_string().to_lowercase(),
|
||||
record.args()
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
builder.init();
|
||||
}
|
||||
|
||||
builder
|
||||
}
|
||||
|
||||
fn run() -> Result<i32, failure::Error> {
|
||||
let args = Args::from_args();
|
||||
|
||||
let mut builder = get_logging(args.verbose.log_level());
|
||||
builder.init();
|
||||
init_logging(args.verbose.log_level());
|
||||
|
||||
let mut config = config::Config::default();
|
||||
if let Some(path) = args.custom_config.as_ref() {
|
||||
|
|
Loading…
Reference in a new issue