mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-22 00:51:11 -05:00
Merge pull request #28 from epage/ignore
Control over what files are ignored
This commit is contained in:
commit
28eae239a0
1 changed files with 111 additions and 1 deletions
112
src/main.rs
112
src/main.rs
|
@ -32,6 +32,7 @@ impl Default for Format {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, StructOpt)]
|
#[derive(Debug, StructOpt)]
|
||||||
|
#[structopt(rename_all = "kebab-case")]
|
||||||
struct Options {
|
struct Options {
|
||||||
#[structopt(parse(from_os_str), default_value = ".")]
|
#[structopt(parse(from_os_str), default_value = ".")]
|
||||||
/// Paths to check
|
/// Paths to check
|
||||||
|
@ -47,6 +48,50 @@ struct Options {
|
||||||
#[structopt(short = "j", long = "threads", default_value = "0")]
|
#[structopt(short = "j", long = "threads", default_value = "0")]
|
||||||
/// The approximate number of threads to use.
|
/// The approximate number of threads to use.
|
||||||
threads: usize,
|
threads: usize,
|
||||||
|
|
||||||
|
#[structopt(long, raw(overrides_with = r#""no-hidden""#))]
|
||||||
|
/// Search hidden files and directories.
|
||||||
|
hidden: bool,
|
||||||
|
#[structopt(long, raw(overrides_with = r#""hidden""#), raw(hidden = "true"))]
|
||||||
|
no_hidden: bool,
|
||||||
|
|
||||||
|
#[structopt(long, raw(overrides_with = r#""ignore""#))]
|
||||||
|
/// Don't respect ignore files.
|
||||||
|
no_ignore: bool,
|
||||||
|
#[structopt(long, raw(overrides_with = r#""no-ignore""#), raw(hidden = "true"))]
|
||||||
|
ignore: bool,
|
||||||
|
|
||||||
|
#[structopt(long, raw(overrides_with = r#""ignore-dot""#))]
|
||||||
|
/// Don't respect .ignore files.
|
||||||
|
no_ignore_dot: bool,
|
||||||
|
#[structopt(long, raw(overrides_with = r#""no-ignore-dot""#), raw(hidden = "true"))]
|
||||||
|
ignore_dot: bool,
|
||||||
|
|
||||||
|
#[structopt(long, raw(overrides_with = r#""ignore-global""#))]
|
||||||
|
/// Don't respect global ignore files.
|
||||||
|
no_ignore_global: bool,
|
||||||
|
#[structopt(
|
||||||
|
long,
|
||||||
|
raw(overrides_with = r#""no-ignore-global""#),
|
||||||
|
raw(hidden = "true")
|
||||||
|
)]
|
||||||
|
ignore_global: bool,
|
||||||
|
|
||||||
|
#[structopt(long, raw(overrides_with = r#""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")
|
||||||
|
)]
|
||||||
|
ignore_parent: bool,
|
||||||
|
|
||||||
|
#[structopt(long, raw(overrides_with = r#""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"))]
|
||||||
|
ignore_vcs: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Options {
|
impl Options {
|
||||||
|
@ -57,6 +102,65 @@ impl Options {
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn ignore_hidden(&self) -> Option<bool> {
|
||||||
|
match (self.hidden, self.no_hidden) {
|
||||||
|
(true, false) => Some(false),
|
||||||
|
(false, true) => Some(true),
|
||||||
|
(false, false) => None,
|
||||||
|
(_, _) => unreachable!("StructOpt should make this impossible"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn ignore_dot(&self) -> Option<bool> {
|
||||||
|
match (self.no_ignore_dot, self.ignore_dot) {
|
||||||
|
(true, false) => Some(false),
|
||||||
|
(false, true) => Some(true),
|
||||||
|
(false, false) => None,
|
||||||
|
(_, _) => unreachable!("StructOpt should make this impossible"),
|
||||||
|
}
|
||||||
|
.or_else(|| self.ignore_files())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn ignore_global(&self) -> Option<bool> {
|
||||||
|
match (self.no_ignore_global, self.ignore_global) {
|
||||||
|
(true, false) => Some(false),
|
||||||
|
(false, true) => Some(true),
|
||||||
|
(false, false) => None,
|
||||||
|
(_, _) => unreachable!("StructOpt should make this impossible"),
|
||||||
|
}
|
||||||
|
.or_else(|| self.ignore_vcs())
|
||||||
|
.or_else(|| self.ignore_files())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn ignore_parent(&self) -> Option<bool> {
|
||||||
|
match (self.no_ignore_parent, self.ignore_parent) {
|
||||||
|
(true, false) => Some(false),
|
||||||
|
(false, true) => Some(true),
|
||||||
|
(false, false) => None,
|
||||||
|
(_, _) => unreachable!("StructOpt should make this impossible"),
|
||||||
|
}
|
||||||
|
.or_else(|| self.ignore_files())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn ignore_vcs(&self) -> Option<bool> {
|
||||||
|
match (self.no_ignore_vcs, self.ignore_vcs) {
|
||||||
|
(true, false) => Some(false),
|
||||||
|
(false, true) => Some(true),
|
||||||
|
(false, false) => None,
|
||||||
|
(_, _) => unreachable!("StructOpt should make this impossible"),
|
||||||
|
}
|
||||||
|
.or_else(|| self.ignore_files())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ignore_files(&self) -> Option<bool> {
|
||||||
|
match (self.no_ignore, self.ignore) {
|
||||||
|
(true, false) => Some(false),
|
||||||
|
(false, true) => Some(true),
|
||||||
|
(false, false) => None,
|
||||||
|
(_, _) => unreachable!("StructOpt should make this impossible"),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run() -> Result<(), failure::Error> {
|
fn run() -> Result<(), failure::Error> {
|
||||||
|
@ -72,7 +176,13 @@ fn run() -> Result<(), failure::Error> {
|
||||||
for path in &options.path[1..] {
|
for path in &options.path[1..] {
|
||||||
walk.add(path);
|
walk.add(path);
|
||||||
}
|
}
|
||||||
walk.threads(options.threads);
|
walk.threads(options.threads)
|
||||||
|
.hidden(options.ignore_hidden().unwrap_or(true))
|
||||||
|
.ignore(options.ignore_dot().unwrap_or(true))
|
||||||
|
.git_global(options.ignore_global().unwrap_or(true))
|
||||||
|
.git_ignore(options.ignore_vcs().unwrap_or(true))
|
||||||
|
.git_exclude(options.ignore_vcs().unwrap_or(true))
|
||||||
|
.parents(options.ignore_parent().unwrap_or(true));
|
||||||
// TODO Add build_parallel for options.threads != 1
|
// TODO Add build_parallel for options.threads != 1
|
||||||
for entry in walk.build() {
|
for entry in walk.build() {
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
|
|
Loading…
Reference in a new issue