From fbd9ab1cb30de5efbce1a29a8f9c9b280dc374a1 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Amiel Date: Fri, 26 Apr 2024 16:01:56 +0200 Subject: [PATCH] Micro cleans on hurlfmt main. --- packages/hurlfmt/src/main.rs | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/packages/hurlfmt/src/main.rs b/packages/hurlfmt/src/main.rs index 4cc2c98448c..555963f1b89 100644 --- a/packages/hurlfmt/src/main.rs +++ b/packages/hurlfmt/src/main.rs @@ -23,32 +23,26 @@ use hurl_core::parser; use hurlfmt::cli::options::{InputFormat, OptionsError, OutputFormat}; use hurlfmt::{cli, curl, format, linter}; -#[cfg(target_family = "unix")] -pub fn init_colored() { - colored::control::set_override(true); -} - -#[cfg(target_family = "windows")] -pub fn init_colored() { - colored::control::set_override(true); - colored::control::set_virtual_terminal(true).expect("set virtual terminal"); -} +const EXIT_OK: i32 = 0; +const EXIT_ERROR: i32 = 1; +/// Executes `hurlfmt` entry point. fn main() { + init_colored(); + let opts = match cli::options::parse() { Ok(v) => v, Err(e) => match e { OptionsError::Info(message) => { print!("{message}"); - process::exit(0); + process::exit(EXIT_OK); } OptionsError::Error(message) => { eprintln!("{message}"); - process::exit(1); + process::exit(EXIT_ERROR); } }, }; - init_colored(); let log_error_message = cli::make_logger_error_message(opts.color); let mut output_all = String::new(); @@ -126,6 +120,17 @@ fn main() { } } +#[cfg(target_family = "unix")] +pub fn init_colored() { + colored::control::set_override(true); +} + +#[cfg(target_family = "windows")] +pub fn init_colored() { + colored::control::set_override(true); + colored::control::set_virtual_terminal(true).expect("set virtual terminal"); +} + fn write_output(content: &str, filename: Option) { let content = if !content.ends_with('\n') { format!("{content}\n")