From ebfdb1dafa430786db10dad2ef7d5467c1bdbed1 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 2 Jul 2023 19:59:52 +0200 Subject: Move everything into `crates/` directory --- cli/src/main.rs | 79 --------------------------------------------------------- 1 file changed, 79 deletions(-) delete mode 100644 cli/src/main.rs (limited to 'cli/src/main.rs') diff --git a/cli/src/main.rs b/cli/src/main.rs deleted file mode 100644 index 425d05fd..00000000 --- a/cli/src/main.rs +++ /dev/null @@ -1,79 +0,0 @@ -mod args; -mod compile; -mod fonts; -mod package; -mod tracing; -mod watch; -mod world; - -use std::cell::Cell; -use std::env; -use std::io::{self, IsTerminal, Write}; -use std::process::ExitCode; - -use clap::Parser; -use codespan_reporting::term::{self, termcolor}; -use termcolor::{ColorChoice, WriteColor}; - -use crate::args::{CliArguments, Command}; - -thread_local! { - /// The CLI's exit code. - static EXIT: Cell = Cell::new(ExitCode::SUCCESS); -} - -/// Entry point. -fn main() -> ExitCode { - let arguments = CliArguments::parse(); - let _guard = match crate::tracing::setup_tracing(&arguments) { - Ok(guard) => guard, - Err(err) => { - eprintln!("failed to initialize tracing {}", err); - None - } - }; - - let res = match arguments.command { - Command::Compile(command) => crate::compile::compile(command), - Command::Watch(command) => crate::watch::watch(command), - Command::Fonts(command) => crate::fonts::fonts(command), - }; - - if let Err(msg) = res { - set_failed(); - print_error(&msg).expect("failed to print error"); - } - - EXIT.with(|cell| cell.get()) -} - -/// Ensure a failure exit code. -fn set_failed() { - EXIT.with(|cell| cell.set(ExitCode::FAILURE)); -} - -/// Print an application-level error (independent from a source file). -fn print_error(msg: &str) -> io::Result<()> { - let mut w = color_stream(); - let styles = term::Styles::default(); - - w.set_color(&styles.header_error)?; - write!(w, "error")?; - - w.reset()?; - writeln!(w, ": {msg}.") -} - -/// Get stderr with color support if desirable. -fn color_stream() -> termcolor::StandardStream { - termcolor::StandardStream::stderr(if std::io::stderr().is_terminal() { - ColorChoice::Auto - } else { - ColorChoice::Never - }) -} - -/// Used by `args.rs`. -fn typst_version() -> &'static str { - env!("TYPST_VERSION") -} -- cgit v1.2.3