From ff60f2cf1a6e56b2dbb8e3d8e6b04f9009cf24ed Mon Sep 17 00:00:00 2001 From: Tad Hardesty Date: Tue, 6 Oct 2020 22:13:45 -0700 Subject: [PATCH] Exit dmdoc --dry-run with an error count --- src/dmdoc/main.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/dmdoc/main.rs b/src/dmdoc/main.rs index 5451382b..f7c8c437 100644 --- a/src/dmdoc/main.rs +++ b/src/dmdoc/main.rs @@ -161,9 +161,11 @@ fn main2() -> Result<(), Box> { } // set up crosslink error reporting + let diagnostic_count: std::cell::Cell = Default::default(); let error_entity: std::cell::Cell> = Default::default(); let error_entity_put = |string: String| error_entity.set(Some(string)); let error_entity_print = || { + diagnostic_count.set(diagnostic_count.get() + 1); if let Some(name) = error_entity.take() { eprintln!("{}:", name); } @@ -642,8 +644,12 @@ fn main2() -> Result<(), Box> { ); } - if dry_run { - return Ok(()); + { + // Ensure the diagnostic count is not increased after this point. + let exit_code = diagnostic_count.into_inner(); + if dry_run { + std::process::exit(exit_code); + } } // load tera templates