Skip to content

Commit

Permalink
Micro cleans on hurlfmt main.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcamiel committed Apr 26, 2024
1 parent 95a0005 commit fbd9ab1
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions packages/hurlfmt/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<PathBuf>) {
let content = if !content.ends_with('\n') {
format!("{content}\n")
Expand Down

0 comments on commit fbd9ab1

Please sign in to comment.