From af694b4c13faa9a3bd1aa747cc52e2c6cd95a9dd Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 6 Feb 2019 16:17:35 -0800 Subject: [PATCH] cli: Fix exit code of parse subcommand --- cli/src/main.rs | 7 ++++++- cli/src/parse.rs | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index 3fb1890d..eb848831 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -118,6 +118,7 @@ fn run() -> error::Result<()> { .into_iter() .collect::>(); let max_path_length = paths.iter().map(|p| p.chars().count()).max().unwrap(); + let mut has_error = false; for path in paths { let path = Path::new(path); let language = @@ -129,7 +130,7 @@ fn run() -> error::Result<()> { eprintln!("No language found"); return Ok(()); }; - parse::parse_file_at_path( + has_error |= parse::parse_file_at_path( language, path, max_path_length, @@ -139,6 +140,10 @@ fn run() -> error::Result<()> { debug_graph, )?; } + + if has_error { + return Err(error::Error(String::new())); + } } Ok(()) diff --git a/cli/src/parse.rs b/cli/src/parse.rs index 4e192773..bd134457 100644 --- a/cli/src/parse.rs +++ b/cli/src/parse.rs @@ -14,7 +14,7 @@ pub fn parse_file_at_path( print_time: bool, debug: bool, debug_graph: bool, -) -> Result<()> { +) -> Result { let mut _log_session = None; let mut parser = Parser::new(); parser.set_language(language)?; @@ -126,7 +126,7 @@ pub fn parse_file_at_path( let end = node.end_position(); write!( &mut stdout, - "\t({} [{}, {}] - [{}, {}]", + "\t({} [{}, {}] - [{}, {}])", node.kind(), start.row, start.column, @@ -137,5 +137,5 @@ pub fn parse_file_at_path( write!(&mut stdout, "\n")?; } - Ok(()) + Ok(first_error.is_some()) }