#![deny(missing_docs)]
#![warn(clippy::all)]
mod app;
mod cli;
mod commands;
mod config;
mod debug;
mod detect_types;
mod error;
mod runtime;
mod selfupdate;
mod style;
use clap::Parser;
fn main() -> std::process::ExitCode {
debug::mark_start();
let t = debug::now();
selfupdate::cleanup_stale_old();
debug::done("self-update", t, || "stale .old cleanup");
let t = debug::now();
let args = cli::Cli::parse();
if args.debug {
debug::enable();
debug::header();
}
debug::done("cli.parse", t, || "argv -> Cli");
runtime::set_json(args.json);
let code = dispatch(&args);
debug::total(code);
std::process::ExitCode::from(code)
}
fn dispatch(args: &cli::Cli) -> u8 {
if (args.json || args.explain)
&& !matches!(
args.command,
None | Some(
cli::Command::Install { .. }
| cli::Command::Remove { .. }
| cli::Command::Run { .. }
| cli::Command::Build { .. }
| cli::Command::Test { .. }
| cli::Command::Update { .. }
| cli::Command::Exec { .. }
)
)
{
error::error_line(error::PmpxError::Usage(
"`--json` is not supported by this command yet".to_string(),
));
return error::EXIT_USAGE;
}
if args.explain {
return match app::explain(args) {
Ok(code) => code,
Err(e) => {
error::error_line(&e);
e.exit_code()
}
};
}
match commands::dispatch(args) {
Ok(code) => code,
Err(e) => {
error::error_line(&e);
e.exit_code()
}
}
}