48 lines
1.4 KiB
Rust
48 lines
1.4 KiB
Rust
use std::io::{self, IsTerminal};
|
|
use std::process::ExitCode;
|
|
use std::{error::Error as StdError, sync::Arc};
|
|
|
|
use clap::{ColorChoice, Parser as _};
|
|
use tracing_human_layer::HumanLayer;
|
|
use tracing_subscriber::util::SubscriberInitExt;
|
|
use tracing_subscriber::{EnvFilter, layer::SubscriberExt};
|
|
|
|
fn main_wrapped() -> Result<(), Box<dyn StdError + Send + Sync + 'static>> {
|
|
let args = Arc::new(dynix::Args::parse());
|
|
|
|
let success = dynix::_CLI_ENABLE_COLOR.set(match args.color {
|
|
ColorChoice::Always => true,
|
|
ColorChoice::Auto => io::stdin().is_terminal(),
|
|
ColorChoice::Never => false,
|
|
});
|
|
if cfg!(debug_assertions) {
|
|
success.expect("logic error in CLI_ENABLE_COLOR");
|
|
}
|
|
|
|
tracing_subscriber::registry()
|
|
.with(HumanLayer::new().with_color_output(*dynix::SHOULD_COLOR))
|
|
.with(EnvFilter::from_default_env())
|
|
.init();
|
|
|
|
tracing::debug!("Parsed command-line arguments: {args:?}");
|
|
|
|
{
|
|
use dynix::args::Subcommand::*;
|
|
match &args.subcommand {
|
|
Append(append_args) => dynix::do_append(args.clone(), append_args.clone())?,
|
|
Delta(delta_args) => dynix::do_delta(args.clone(), delta_args.clone())?,
|
|
};
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
fn main() -> ExitCode {
|
|
match main_wrapped() {
|
|
Ok(_) => ExitCode::SUCCESS,
|
|
Err(e) => {
|
|
eprintln!("dynix: error: {}", e);
|
|
ExitCode::FAILURE
|
|
}
|
|
}
|
|
}
|