2026-01-27 17:20:04 +01:00
|
|
|
use std::io::{self, IsTerminal};
|
2026-01-27 11:29:10 +01:00
|
|
|
use std::process::ExitCode;
|
2026-01-28 19:30:59 +01:00
|
|
|
use std::{error::Error as StdError, sync::Arc};
|
2026-01-27 11:29:10 +01:00
|
|
|
|
|
|
|
|
use clap::{ColorChoice, Parser as _};
|
2026-02-02 17:43:44 +01:00
|
|
|
use tracing_human_layer::HumanLayer;
|
|
|
|
|
use tracing_subscriber::util::SubscriberInitExt;
|
|
|
|
|
use tracing_subscriber::{EnvFilter, layer::SubscriberExt};
|
2026-01-27 11:29:10 +01:00
|
|
|
|
|
|
|
|
fn main_wrapped() -> Result<(), Box<dyn StdError + Send + Sync + 'static>> {
|
2026-02-02 13:42:07 +01:00
|
|
|
let args = Arc::new(dynix::Args::parse());
|
2026-01-27 11:29:10 +01:00
|
|
|
|
2026-02-02 17:43:44 +01:00
|
|
|
let success = dynix::_CLI_ENABLE_COLOR.set(match args.color {
|
2026-01-27 11:29:10 +01:00
|
|
|
ColorChoice::Always => true,
|
2026-01-27 17:20:04 +01:00
|
|
|
ColorChoice::Auto => io::stdin().is_terminal(),
|
2026-01-27 11:29:10 +01:00
|
|
|
ColorChoice::Never => false,
|
|
|
|
|
});
|
|
|
|
|
if cfg!(debug_assertions) {
|
|
|
|
|
success.expect("logic error in CLI_ENABLE_COLOR");
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-02 17:43:44 +01:00
|
|
|
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:?}");
|
|
|
|
|
|
2026-02-03 16:19:33 +01:00
|
|
|
{
|
|
|
|
|
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())?,
|
|
|
|
|
};
|
|
|
|
|
}
|
2026-01-27 11:29:10 +01:00
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn main() -> ExitCode {
|
|
|
|
|
match main_wrapped() {
|
|
|
|
|
Ok(_) => ExitCode::SUCCESS,
|
|
|
|
|
Err(e) => {
|
2026-02-02 11:34:52 +01:00
|
|
|
eprintln!("dynix: error: {}", e);
|
2026-01-27 11:29:10 +01:00
|
|
|
ExitCode::FAILURE
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|