mod clever;
mod cli;
mod commands;
mod interpolate;
mod issues;
mod model;
mod state;
use anyhow::Result;
use clap::Parser;
use tracing_subscriber::EnvFilter;
fn main() -> Result<()> {
let args = cli::Cli::parse();
let format = command_format(&args.command);
init_tracing(args.verbose, format);
match args.command {
cli::Command::Read(args) => commands::read::run(args),
cli::Command::Apply(args) => commands::apply::run(args),
cli::Command::Delete(args) => commands::delete::run(args),
cli::Command::Check(args) => commands::check::run(args),
cli::Command::Status(args) => commands::status::run(args),
cli::Command::Init(args) => commands::init::run(args),
}
}
fn command_format(cmd: &cli::Command) -> cli::OutputFormat {
match cmd {
cli::Command::Read(a) => a.format,
cli::Command::Apply(a) => a.format,
cli::Command::Delete(a) => a.format,
cli::Command::Check(a) => a.format,
cli::Command::Status(a) => a.format,
cli::Command::Init(a) => a.format,
}
}
fn init_tracing(verbose: bool, format: cli::OutputFormat) {
let default_level = if verbose {
"debug"
} else if format.is_json() {
"warn"
} else {
"info"
};
let filter =
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(default_level));
tracing_subscriber::fmt()
.with_env_filter(filter)
.with_target(false)
.without_time()
.with_writer(std::io::stderr)
.init();
}