cli: Fix exit code of parse subcommand

This commit is contained in:
Max Brunsfeld 2019-02-06 16:17:35 -08:00
parent ccbb8c1cce
commit af694b4c13
2 changed files with 9 additions and 4 deletions

View file

@ -118,6 +118,7 @@ fn run() -> error::Result<()> {
.into_iter()
.collect::<Vec<_>>();
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(())

View file

@ -14,7 +14,7 @@ pub fn parse_file_at_path(
print_time: bool,
debug: bool,
debug_graph: bool,
) -> Result<()> {
) -> Result<bool> {
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())
}