use std::path::PathBuf;
use log::error;
use clap::{command, crate_authors, Parser, Subcommand};
use clap_verbosity_flag::{InfoLevel, Verbosity};
use crate::shadow;
pub mod bug_report;
pub mod build;
pub mod completions;
pub mod generate;
#[cfg(feature = "iso")]
pub mod generate_iso;
#[cfg(feature = "init")]
pub mod init;
#[cfg(feature = "login")]
pub mod login;
#[cfg(feature = "prune")]
pub mod prune;
#[cfg(feature = "switch")]
pub mod switch;
#[cfg(feature = "validate")]
pub mod validate;
pub trait BlueBuildCommand {
fn try_run(&mut self) -> miette::Result<()>;
fn run(&mut self) {
if let Err(e) = self.try_run() {
error!("Failed:\n{e:?}");
std::process::exit(1);
}
std::process::exit(0);
}
}
#[derive(Parser, Debug)]
#[clap(
name = "BlueBuild",
about,
long_about = None,
author=crate_authors!(),
version=shadow::PKG_VERSION,
long_version=shadow::CLAP_LONG_VERSION,
)]
pub struct BlueBuildArgs {
#[command(subcommand)]
pub command: CommandArgs,
#[arg(long)]
pub log_out: Option<PathBuf>,
#[clap(flatten)]
pub verbosity: Verbosity<InfoLevel>,
}
#[derive(Debug, Subcommand)]
pub enum CommandArgs {
Build(build::BuildCommand),
#[clap(visible_alias = "template")]
Generate(generate::GenerateCommand),
#[cfg(feature = "iso")]
GenerateIso(generate_iso::GenerateIsoCommand),
#[cfg(feature = "switch")]
#[command(
visible_alias("update"),
visible_alias("upgrade"),
visible_alias("rebase")
)]
Switch(switch::SwitchCommand),
#[cfg(feature = "login")]
Login(login::LoginCommand),
#[cfg(feature = "init")]
New(init::NewCommand),
#[cfg(feature = "init")]
Init(init::InitCommand),
#[cfg(feature = "validate")]
Validate(Box<validate::ValidateCommand>),
#[cfg(feature = "prune")]
Prune(prune::PruneCommand),
BugReport(bug_report::BugReportCommand),
Completions(completions::CompletionsCommand),
}
#[cfg(test)]
mod test {
use clap::CommandFactory;
use super::BlueBuildArgs;
#[test]
fn test_cli() {
BlueBuildArgs::command().debug_assert();
}
}