#![forbid(unsafe_code)]
mod commands;
mod error;
mod input;
use std::process::ExitCode;
use std::sync::LazyLock;
use clap::{Parser, Subcommand};
static LONG_VERSION: LazyLock<String> = LazyLock::new(|| {
format!(
"{cli}\n\
gamut library: {lib}\n\
commit: {hash} ({dirty})\n\
profile: {profile}\n\
target: {target}\n\
rustc: {rustc}\n\
commit date: {commit_date}\n\
built: {built}",
cli = env!("CARGO_PKG_VERSION"),
lib = gamut::VERSION,
hash = env!("GAMUT_GIT_HASH"),
dirty = env!("GAMUT_GIT_DIRTY"),
profile = env!("GAMUT_BUILD_PROFILE"),
target = env!("GAMUT_BUILD_TARGET"),
rustc = env!("GAMUT_RUSTC_VERSION"),
commit_date = env!("GAMUT_COMMIT_DATE"),
built = env!("GAMUT_BUILD_TIMESTAMP"),
)
});
#[derive(Parser)]
#[command(name = "gamut", version = LONG_VERSION.as_str(), 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),
Inspect(commands::inspect::InspectArgs),
Icc(commands::icc::IccArgs),
#[command(subcommand)]
Isobmff(commands::isobmff::IsobmffCommand),
#[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::Inspect(args) => commands::inspect::run(&args),
Command::Icc(args) => commands::icc::run(&args),
Command::Isobmff(cmd) => commands::isobmff::run(&cmd),
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();
}