#![forbid(unsafe_code)]
mod commands;
mod error;
mod input;
use std::process::ExitCode;
use clap::{Parser, Subcommand};
const LONG_VERSION: &str = concat!(
env!("CARGO_PKG_VERSION"),
"\ncommit: ",
env!("GAMUT_GIT_HASH"),
" (",
env!("GAMUT_GIT_DIRTY"),
")",
"\nprofile: ",
env!("GAMUT_BUILD_PROFILE"),
"\ntarget: ",
env!("GAMUT_BUILD_TARGET"),
"\nrustc: ",
env!("GAMUT_RUSTC_VERSION"),
"\ncommit date: ",
env!("GAMUT_COMMIT_DATE"),
"\nbuilt: ",
env!("GAMUT_BUILD_TIMESTAMP"),
);
#[derive(Parser)]
#[command(name = "gamut", version = LONG_VERSION, about)]
struct Cli {
#[arg(short, long, action = clap::ArgAction::Count, global = true)]
verbose: u8,
#[command(subcommand)]
command: Command,
}
#[derive(Subcommand)]
enum Command {
Convert(commands::convert::ConvertArgs),
#[command(subcommand)]
Av1(commands::av1::Av1Command),
#[command(subcommand)]
Color(commands::color::ColorCommand),
#[command(subcommand)]
Dsp(commands::dsp::DspCommand),
#[command(subcommand)]
Bitstream(commands::bitstream::BitstreamCommand),
}
fn main() -> ExitCode {
let cli = Cli::parse();
init_tracing(cli.verbose);
let result = match cli.command {
Command::Convert(args) => commands::convert::run(&args),
Command::Av1(cmd) => commands::av1::run(&cmd),
Command::Color(cmd) => commands::color::run(&cmd),
Command::Dsp(cmd) => commands::dsp::run(&cmd),
Command::Bitstream(cmd) => commands::bitstream::run(&cmd),
};
match result {
Ok(()) => ExitCode::SUCCESS,
Err(e) => {
eprintln!("error: {e}");
ExitCode::FAILURE
}
}
}
fn init_tracing(verbose: u8) {
use tracing_subscriber::EnvFilter;
let filter = match std::env::var("RUST_LOG") {
Ok(directives) if !directives.is_empty() => EnvFilter::new(directives),
_ => EnvFilter::new(match verbose {
0 => "warn",
1 => "info",
_ => "debug",
}),
};
let _ = tracing_subscriber::fmt()
.with_env_filter(filter)
.with_writer(std::io::stderr)
.try_init();
}