Update the diff program to use exit code 1 for non-matching diff.
This commit is contained in:
@@ -54,6 +54,13 @@ impl DiffResult {
|
||||
.iter()
|
||||
.any(|child| child.status == DiffStatus::Bad || child.has_bad_children())
|
||||
}
|
||||
|
||||
pub fn is_bad(&self) -> bool {
|
||||
match self.status {
|
||||
DiffStatus::Good => !self.has_bad_children(),
|
||||
DiffStatus::Bad => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn compare_document<'s>(
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#![feature(round_char_boundary)]
|
||||
#![feature(exit_status_error)]
|
||||
use std::process::ExitCode;
|
||||
|
||||
use crate::compare::compare_document;
|
||||
use crate::init_tracing::init_telemetry;
|
||||
use crate::init_tracing::shutdown_telemetry;
|
||||
@@ -10,7 +12,13 @@ mod compare;
|
||||
mod init_tracing;
|
||||
mod parser;
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
fn main() -> ExitCode {
|
||||
let result = _main().expect("Ran into an error comparing the parses.");
|
||||
ExitCode::from(result)
|
||||
}
|
||||
|
||||
fn _main() -> Result<u8, Box<dyn std::error::Error>> {
|
||||
let mut ran_into_problems: bool = false;
|
||||
init_telemetry()?;
|
||||
for org_path in std::env::args().skip(1) {
|
||||
let org_contents = std::fs::read_to_string(&org_path)?;
|
||||
@@ -21,8 +29,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("{:#?}", rust_parsed);
|
||||
let diff_result = compare_document(&parsed_sexp, &rust_parsed)?;
|
||||
diff_result.print()?;
|
||||
if diff_result.is_bad() {
|
||||
ran_into_problems = true;
|
||||
}
|
||||
}
|
||||
println!("Done.");
|
||||
shutdown_telemetry()?;
|
||||
Ok(())
|
||||
if ran_into_problems {
|
||||
Ok(1)
|
||||
} else {
|
||||
Ok(0)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user