mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-22 09:01:04 -05:00
refactor(cli): Rename Options struct
This commit is contained in:
parent
a923f93ec5
commit
77603daab5
1 changed files with 14 additions and 14 deletions
28
src/main.rs
28
src/main.rs
|
@ -37,7 +37,7 @@ impl Default for Format {
|
||||||
|
|
||||||
#[derive(Debug, StructOpt)]
|
#[derive(Debug, StructOpt)]
|
||||||
#[structopt(rename_all = "kebab-case")]
|
#[structopt(rename_all = "kebab-case")]
|
||||||
struct Options {
|
struct Args {
|
||||||
#[structopt(parse(from_os_str), default_value = ".")]
|
#[structopt(parse(from_os_str), default_value = ".")]
|
||||||
/// Paths to check
|
/// Paths to check
|
||||||
path: Vec<std::path::PathBuf>,
|
path: Vec<std::path::PathBuf>,
|
||||||
|
@ -96,7 +96,7 @@ struct Options {
|
||||||
verbose: clap_verbosity_flag::Verbosity,
|
verbose: clap_verbosity_flag::Verbosity,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Options {
|
impl Args {
|
||||||
pub fn infer(self) -> Self {
|
pub fn infer(self) -> Self {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -277,32 +277,32 @@ pub fn get_logging(level: log::Level) -> env_logger::Builder {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run() -> Result<i32, failure::Error> {
|
fn run() -> Result<i32, failure::Error> {
|
||||||
let options = Options::from_args().infer();
|
let args = Args::from_args().infer();
|
||||||
|
|
||||||
let mut builder = get_logging(options.verbose.log_level());
|
let mut builder = get_logging(args.verbose.log_level());
|
||||||
builder.init();
|
builder.init();
|
||||||
|
|
||||||
let dictionary = typos::BuiltIn::new();
|
let dictionary = typos::BuiltIn::new();
|
||||||
|
|
||||||
let parser = typos::tokens::ParserBuilder::new()
|
let parser = typos::tokens::ParserBuilder::new()
|
||||||
.ignore_hex(options.ignore_hex().unwrap_or(true))
|
.ignore_hex(args.ignore_hex().unwrap_or(true))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let checks = typos::checks::CheckSettings::new()
|
let checks = typos::checks::CheckSettings::new()
|
||||||
.check_filenames(options.check_filenames().unwrap_or(true))
|
.check_filenames(args.check_filenames().unwrap_or(true))
|
||||||
.check_files(options.check_files().unwrap_or(true))
|
.check_files(args.check_files().unwrap_or(true))
|
||||||
.binary(options.binary().unwrap_or(false))
|
.binary(args.binary().unwrap_or(false))
|
||||||
.build(&dictionary, &parser);
|
.build(&dictionary, &parser);
|
||||||
|
|
||||||
let mut config = config::Config::default();
|
let mut config = config::Config::default();
|
||||||
if let Some(path) = options.custom_config.as_ref() {
|
if let Some(path) = args.custom_config.as_ref() {
|
||||||
let custom = config::Config::from_file(path)?;
|
let custom = config::Config::from_file(path)?;
|
||||||
config.update(&custom);
|
config.update(&custom);
|
||||||
}
|
}
|
||||||
let config = config;
|
let config = config;
|
||||||
|
|
||||||
let mut typos_found = false;
|
let mut typos_found = false;
|
||||||
for path in options.path.iter() {
|
for path in args.path.iter() {
|
||||||
let path = path.canonicalize()?;
|
let path = path.canonicalize()?;
|
||||||
let cwd = if path.is_file() {
|
let cwd = if path.is_file() {
|
||||||
path.parent().unwrap()
|
path.parent().unwrap()
|
||||||
|
@ -311,11 +311,11 @@ fn run() -> Result<i32, failure::Error> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut config = config.clone();
|
let mut config = config.clone();
|
||||||
if !options.isolated {
|
if !args.isolated {
|
||||||
let derived = config::Config::derive(cwd)?;
|
let derived = config::Config::derive(cwd)?;
|
||||||
config.update(&derived);
|
config.update(&derived);
|
||||||
}
|
}
|
||||||
config.update(&options.config);
|
config.update(&args.config);
|
||||||
let config = config;
|
let config = config;
|
||||||
|
|
||||||
let mut walk = ignore::WalkBuilder::new(path);
|
let mut walk = ignore::WalkBuilder::new(path);
|
||||||
|
@ -329,10 +329,10 @@ fn run() -> Result<i32, failure::Error> {
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
if entry.file_type().map(|t| t.is_file()).unwrap_or(true) {
|
if entry.file_type().map(|t| t.is_file()).unwrap_or(true) {
|
||||||
let explicit = entry.depth() == 0;
|
let explicit = entry.depth() == 0;
|
||||||
if checks.check_filename(entry.path(), options.format.report())? {
|
if checks.check_filename(entry.path(), args.format.report())? {
|
||||||
typos_found = true;
|
typos_found = true;
|
||||||
}
|
}
|
||||||
if checks.check_file(entry.path(), explicit, options.format.report())? {
|
if checks.check_file(entry.path(), explicit, args.format.report())? {
|
||||||
typos_found = true;
|
typos_found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue