amareleo_chain_cli/commands/
mod.rs1mod clean;
17pub use clean::*;
18
19mod start;
20pub use start::*;
21
22mod update;
23pub use update::*;
24
25use anstyle::{AnsiColor, Color, Style};
26use anyhow::Result;
27use clap::{Parser, builder::Styles};
28
29const HEADER_COLOR: Option<Color> = Some(Color::Ansi(AnsiColor::Yellow));
30const LITERAL_COLOR: Option<Color> = Some(Color::Ansi(AnsiColor::Green));
31const STYLES: Styles = Styles::plain()
32 .header(Style::new().bold().fg_color(HEADER_COLOR))
33 .usage(Style::new().bold().fg_color(HEADER_COLOR))
34 .literal(Style::new().bold().fg_color(LITERAL_COLOR));
35
36#[derive(Debug, Parser)]
37#[clap(styles = STYLES, version)]
38pub struct CLI {
39 #[clap(default_value = "2", short, long)]
41 pub verbosity: u8,
42 #[clap(subcommand)]
44 pub command: Command,
45}
46
47#[derive(Debug, Parser)]
48pub enum Command {
49 #[clap(name = "clean")]
50 Clean(Clean),
51 #[clap(name = "start")]
52 Start(Box<Start>),
53 #[clap(name = "update")]
54 Update(Update),
55}
56
57impl Command {
58 pub fn parse(self, repo_name: &str, bin_name: &str) -> Result<String> {
60 match self {
61 Self::Clean(command) => command.parse(),
62 Self::Start(command) => command.parse(),
63 Self::Update(command) => command.parse(repo_name, bin_name),
64 }
65 }
66}
67
68#[cfg(test)]
69mod tests {
70 use super::*;
71
72 #[test]
74 fn verify_cli() {
75 use clap::CommandFactory;
76 CLI::command().debug_assert()
77 }
78}