diff options
| author | PgBiel <9021226+PgBiel@users.noreply.github.com> | 2024-06-04 12:24:39 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-04 15:24:39 +0000 |
| commit | 9adcd9a1f894b212e2757277781955a7d5b8bba8 (patch) | |
| tree | 6e8b67d8ec9482fca04a87793b8d7c7698d78e12 /crates/typst-cli/src/main.rs | |
| parent | d360e753bccf996819392539aaaa031f458559e9 (diff) | |
Refactor casts to use `HintedStrResult` (#4229)
Diffstat (limited to 'crates/typst-cli/src/main.rs')
| -rw-r--r-- | crates/typst-cli/src/main.rs | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/crates/typst-cli/src/main.rs b/crates/typst-cli/src/main.rs index c8bd3914..bc1c30a6 100644 --- a/crates/typst-cli/src/main.rs +++ b/crates/typst-cli/src/main.rs @@ -20,6 +20,7 @@ use clap::Parser; use codespan_reporting::term; use codespan_reporting::term::termcolor::WriteColor; use once_cell::sync::Lazy; +use typst::diag::HintedStrResult; use crate::args::{CliArguments, Command}; use crate::timings::Timer; @@ -34,25 +35,32 @@ static ARGS: Lazy<CliArguments> = Lazy::new(CliArguments::parse); /// Entry point. fn main() -> ExitCode { - let timer = Timer::new(&ARGS); - - let res = match &ARGS.command { - Command::Compile(command) => crate::compile::compile(timer, command.clone()), - Command::Watch(command) => crate::watch::watch(timer, command.clone()), - Command::Init(command) => crate::init::init(command), - Command::Query(command) => crate::query::query(command), - Command::Fonts(command) => crate::fonts::fonts(command), - Command::Update(command) => crate::update::update(command), - }; + let res = dispatch(); if let Err(msg) = res { set_failed(); - print_error(&msg).expect("failed to print error"); + print_error(msg.message()).expect("failed to print error"); } EXIT.with(|cell| cell.get()) } +/// Execute the requested command. +fn dispatch() -> HintedStrResult<()> { + let timer = Timer::new(&ARGS); + + match &ARGS.command { + Command::Compile(command) => crate::compile::compile(timer, command.clone())?, + Command::Watch(command) => crate::watch::watch(timer, command.clone())?, + Command::Init(command) => crate::init::init(command)?, + Command::Query(command) => crate::query::query(command)?, + Command::Fonts(command) => crate::fonts::fonts(command)?, + Command::Update(command) => crate::update::update(command)?, + } + + Ok(()) +} + /// Ensure a failure exit code. fn set_failed() { EXIT.with(|cell| cell.set(ExitCode::FAILURE)); |
