1use std::path::PathBuf;
2
3use log::error;
4
5use clap::{Parser, Subcommand, command, crate_authors};
6use clap_verbosity_flag::{InfoLevel, Verbosity};
7
8use crate::shadow;
9
10pub mod bug_report;
11pub mod build;
12pub mod completions;
13pub mod generate;
14pub mod generate_iso;
15pub mod init;
16pub mod login;
17pub mod prune;
18pub mod switch;
19pub mod validate;
20
21pub trait BlueBuildCommand {
22 fn try_run(&mut self) -> miette::Result<()>;
28
29 fn run(&mut self) {
31 if let Err(e) = self.try_run() {
32 error!("Failed:\n{e:?}");
33 std::process::exit(1);
34 }
35 std::process::exit(0);
36 }
37}
38
39#[derive(Parser, Debug)]
40#[clap(
41 name = "BlueBuild",
42 about,
43 long_about = None,
44 author=crate_authors!(),
45 version=shadow::PKG_VERSION,
46 long_version=shadow::CLAP_LONG_VERSION,
47)]
48pub struct BlueBuildArgs {
49 #[command(subcommand)]
50 pub command: CommandArgs,
51
52 #[arg(long)]
54 pub log_out: Option<PathBuf>,
55
56 #[clap(flatten)]
57 pub verbosity: Verbosity<InfoLevel>,
58}
59
60#[derive(Debug, Subcommand)]
61pub enum CommandArgs {
62 Build(build::BuildCommand),
64
65 #[clap(visible_alias = "template")]
67 Generate(generate::GenerateCommand),
68
69 GenerateIso(generate_iso::GenerateIsoCommand),
71
72 #[command(
82 visible_alias("update"),
83 visible_alias("upgrade"),
84 visible_alias("rebase")
85 )]
86 Switch(switch::SwitchCommand),
87
88 Login(login::LoginCommand),
90
91 New(init::NewCommand),
93
94 Init(init::InitCommand),
96
97 Validate(Box<validate::ValidateCommand>),
100
101 Prune(prune::PruneCommand),
103
104 BugReport(bug_report::BugReportCommand),
106
107 Completions(completions::CompletionsCommand),
109}
110
111#[cfg(test)]
112mod test {
113 use clap::CommandFactory;
114
115 use super::BlueBuildArgs;
116
117 #[test]
118 fn test_cli() {
119 BlueBuildArgs::command().debug_assert();
120 }
121}