summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-03-28 14:54:23 +0200
committerLaurenz <laurmaedje@gmail.com>2023-03-28 14:54:23 +0200
commit6fa33fda6ee94b6f38bcbb4e805a33893bda2b27 (patch)
tree8055ebe8e36a488eadd14097d53acd591ef51960
parente84df1a03690d24cb87d53fb4ed70af9c473c6fb (diff)
Return with non-zero status code in case of error
-rw-r--r--cli/src/main.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/cli/src/main.rs b/cli/src/main.rs
index eaa429c7..69bac940 100644
--- a/cli/src/main.rs
+++ b/cli/src/main.rs
@@ -199,9 +199,13 @@ fn compile(command: CompileCommand) -> StrResult<()> {
let mut world = SystemWorld::new(root, &command.font_paths);
// Perform initial compilation.
- compile_once(&mut world, &command)?;
-
+ let failed = compile_once(&mut world, &command)?;
if !command.watch {
+ // Return with non-zero exit code in case of error.
+ if failed {
+ process::exit(1);
+ }
+
return Ok(());
}
@@ -244,7 +248,7 @@ fn compile(command: CompileCommand) -> StrResult<()> {
}
/// Compile a single time.
-fn compile_once(world: &mut SystemWorld, command: &CompileCommand) -> StrResult<()> {
+fn compile_once(world: &mut SystemWorld, command: &CompileCommand) -> StrResult<bool> {
status(command, Status::Compiling).unwrap();
world.reset();
@@ -256,6 +260,7 @@ fn compile_once(world: &mut SystemWorld, command: &CompileCommand) -> StrResult<
let buffer = typst::export::pdf(&document);
fs::write(&command.output, buffer).map_err(|_| "failed to write PDF file")?;
status(command, Status::Success).unwrap();
+ Ok(false)
}
// Print diagnostics.
@@ -263,10 +268,9 @@ fn compile_once(world: &mut SystemWorld, command: &CompileCommand) -> StrResult<
status(command, Status::Error).unwrap();
print_diagnostics(&world, *errors)
.map_err(|_| "failed to print diagnostics")?;
+ Ok(true)
}
}
-
- Ok(())
}
/// Clear the terminal and render the status message.