diff --git a/Cargo.toml b/Cargo.toml index d43ed3c..6b6b2a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,19 +15,22 @@ toml = "0.8" clap = { version = "4.5", features = ["derive", "usage", "help"] } thiserror = "1.0.61" colored = { version = "2.1.0", optional = true } -serde_json = { version = "1.0.120", features = [ + +[dependencies.serde_json] +version = "1.0.120" +features = [ "indexmap", "preserve_order", "raw_value", "unbounded_depth", -], optional = true } +] +optional = true [features] default = ["json"] color = ["colored"] json = ["dep:serde_json"] - [lib] name = "tq" path = "src/lib.rs" @@ -36,12 +39,10 @@ doctest = false [[bin]] name = "tq" -path = "src/main.rs" test = false [[bin]] name = "tomlq" -path = "src/legacy.rs" test = false [package.metadata.binstall] diff --git a/src/legacy.rs b/src/bin/tomlq.rs similarity index 98% rename from src/legacy.rs rename to src/bin/tomlq.rs index 972c2df..bc63a17 100644 --- a/src/legacy.rs +++ b/src/bin/tomlq.rs @@ -1,3 +1,5 @@ +//! Legacy tomlq binary. + use clap::Parser; #[cfg(feature = "color")] use colored::Colorize; diff --git a/src/main.rs b/src/bin/tq.rs similarity index 80% rename from src/main.rs rename to src/bin/tq.rs index 43d9f9c..a85c18e 100644 --- a/src/main.rs +++ b/src/bin/tq.rs @@ -1,8 +1,8 @@ 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); @@ -10,12 +10,12 @@ fn main() { 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('"')), @@ -23,11 +23,11 @@ fn main() { OutputType::Json => println!("{}", serde_json::to_string(&needle).unwrap()), } - 0 + ExitCode::SUCCESS } Err(e) => { eprintln!("{}", e); - -1 + ExitCode::FAILURE } - }); + } }