-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use exitcodes instead of exit method in tq binary entrypoint (#14)
* Use `std::process::ExitCode` rather than `std::process::exit` in `tq` binary `main` function * Reformat `serde` dependency in `Cargo.toml`
- Loading branch information
Showing
3 changed files
with
15 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
//! Legacy tomlq binary. | ||
use clap::Parser; | ||
#[cfg(feature = "color")] | ||
use colored::Colorize; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
use clap::Parser; | ||
use std::process::exit; | ||
use std::process::ExitCode; | ||
use tq::OutputType; | ||
|
||
fn main() { | ||
fn main() -> ExitCode { | ||
let app = tq::Cli::parse(); | ||
|
||
let toml_file = tq::load_toml_from_file(&app.file); | ||
|
||
let Ok(toml_file) = toml_file else { | ||
let e = toml_file.unwrap_err(); | ||
eprintln!("{}", e); | ||
exit(-1); | ||
return ExitCode::FAILURE; | ||
}; | ||
|
||
let x = tq::extract_pattern(&toml_file, &app.pattern); | ||
|
||
exit(match x { | ||
match x { | ||
Ok(needle) => { | ||
match app.output { | ||
OutputType::Toml => println!("{}", format!("{}", needle).trim_matches('"')), | ||
#[cfg(feature = "json")] | ||
OutputType::Json => println!("{}", serde_json::to_string(&needle).unwrap()), | ||
} | ||
|
||
0 | ||
ExitCode::SUCCESS | ||
} | ||
Err(e) => { | ||
eprintln!("{}", e); | ||
-1 | ||
ExitCode::FAILURE | ||
} | ||
}); | ||
} | ||
} |