1use std::path::PathBuf;
2
3use blue_build_utils::constants::BB_NO_LOG_FILTER;
4use log::error;
5
6use clap::{Parser, Subcommand, crate_authors};
7use clap_verbosity_flag::{InfoLevel, Verbosity};
8
9use crate::shadow;
10
11pub mod bug_report;
12pub mod build;
13pub mod completions;
14pub mod generate;
15pub mod generate_iso;
16pub mod init;
17pub mod login;
18pub mod prune;
19pub mod switch;
20pub mod validate;
21
22pub trait BlueBuildCommand {
23 fn try_run(&mut self) -> miette::Result<()>;
29
30 fn run(&mut self) {
32 if let Err(e) = self.try_run() {
33 error!("Failed:\n{e:?}");
34 std::process::exit(1);
35 }
36 std::process::exit(0);
37 }
38}
39
40#[derive(Parser, Debug)]
41#[clap(
42 name = "BlueBuild",
43 about,
44 long_about = None,
45 author=crate_authors!(),
46 version=shadow::PKG_VERSION,
47 long_version=shadow::CLAP_LONG_VERSION,
48)]
49pub struct BlueBuildArgs {
50 #[command(subcommand)]
51 pub command: CommandArgs,
52
53 #[arg(long, env = BB_NO_LOG_FILTER)]
58 pub no_log_filter: bool,
59
60 #[arg(long)]
62 pub log_out: Option<PathBuf>,
63
64 #[clap(flatten)]
65 pub verbosity: Verbosity<InfoLevel>,
66}
67
68#[derive(Debug, Subcommand)]
69pub enum CommandArgs {
70 Build(build::BuildCommand),
72
73 #[clap(visible_alias = "template")]
75 Generate(generate::GenerateCommand),
76
77 GenerateIso(generate_iso::GenerateIsoCommand),
79
80 #[command(
90 visible_alias("update"),
91 visible_alias("upgrade"),
92 visible_alias("rebase")
93 )]
94 Switch(switch::SwitchCommand),
95
96 Login(login::LoginCommand),
98
99 New(init::NewCommand),
101
102 Init(init::InitCommand),
104
105 Validate(Box<validate::ValidateCommand>),
108
109 Prune(prune::PruneCommand),
111
112 BugReport(bug_report::BugReportCommand),
114
115 Completions(completions::CompletionsCommand),
117}
118
119#[cfg(test)]
120mod test {
121 use clap::CommandFactory;
122
123 use super::BlueBuildArgs;
124
125 #[test]
126 fn test_cli() {
127 BlueBuildArgs::command().debug_assert();
128 }
129}