diff --git a/docs/about.md b/docs/about.md index 88340ead0..72a6cdfda 100644 --- a/docs/about.md +++ b/docs/about.md @@ -47,6 +47,7 @@ Whitelist: A confidence rating is given for how close a word is to one in the wh | Ignores hidden | Yes | Yes | ? | Yes | No | | Respect gitignore | Yes | Yes | ? | No | No | | Checks filenames | Yes | No | ? | Yes | No | +| Status via exit code | Yes | No | Yes | Yes | Yes | | API | Rust / [JSON Lines] | Rust | ? | Python | None | | License | MIT or Apache | AGPL | MIT | GPLv2 | GPLv2 | diff --git a/src/lib.rs b/src/lib.rs index 0463a3312..7ef5ea5df 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,9 @@ pub fn process_file( ignore_hex: bool, binary: bool, report: report::Report, -) -> Result<(), failure::Error> { +) -> Result { + let mut typos_found = false; + if check_filenames { for part in path.components().filter_map(|c| c.as_os_str().to_str()) { for ident in tokens::Identifier::parse(part) { @@ -37,6 +39,7 @@ pub fn process_file( non_exhaustive: (), }; report(msg.into()); + typos_found = true; } for word in ident.split() { if let Some(correction) = dictionary.correct_word(word) { @@ -47,6 +50,7 @@ pub fn process_file( non_exhaustive: (), }; report(msg.into()); + typos_found = true; } } } @@ -62,7 +66,7 @@ pub fn process_file( non_exhaustive: (), }; report(msg.into()); - return Ok(()); + return Ok(typos_found); } for (line_idx, line) in buffer.lines().enumerate() { @@ -82,6 +86,7 @@ pub fn process_file( correction, non_exhaustive: (), }; + typos_found = true; report(msg.into()); } for word in ident.split() { @@ -96,6 +101,7 @@ pub fn process_file( correction, non_exhaustive: (), }; + typos_found = true; report(msg.into()); } } @@ -103,7 +109,7 @@ pub fn process_file( } } - Ok(()) + Ok(typos_found) } fn is_hex(ident: &str) -> bool { diff --git a/src/main.rs b/src/main.rs index f25b9d567..2e662a7b7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -249,7 +249,7 @@ pub fn get_logging(level: log::Level) -> env_logger::Builder { builder } -fn run() -> Result<(), failure::Error> { +fn run() -> Result { let options = Options::from_args().infer(); let mut builder = get_logging(options.verbose.log_level()); @@ -275,11 +275,11 @@ fn run() -> Result<(), failure::Error> { .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 + let mut typos_found = false; for entry in walk.build() { let entry = entry?; if entry.file_type().map(|t| t.is_file()).unwrap_or(true) { - typos::process_file( + if typos::process_file( entry.path(), &dictionary, check_filenames, @@ -287,13 +287,20 @@ fn run() -> Result<(), failure::Error> { ignore_hex, binary, options.format.report(), - )?; + )? { + typos_found = true; + } } } - Ok(()) + if typos_found { + Ok(1) + } else { + Ok(0) + } } fn main() { - run().unwrap(); + let code = run().unwrap(); + std::process::exit(code); }