1use crate::cli::commands::{Build, Clean, Execute, New, Run, Update};
16
17use anstyle::{AnsiColor, Color, Style};
18use anyhow::Result;
19use clap::{builder::Styles, Parser};
20
21const HEADER_COLOR: Option<Color> = Some(Color::Ansi(AnsiColor::Yellow));
22const LITERAL_COLOR: Option<Color> = Some(Color::Ansi(AnsiColor::Green));
23const STYLES: Styles = Styles::plain()
24 .header(Style::new().bold().fg_color(HEADER_COLOR))
25 .usage(Style::new().bold().fg_color(HEADER_COLOR))
26 .literal(Style::new().bold().fg_color(LITERAL_COLOR));
27
28#[derive(Debug, Parser)]
29#[clap(name = "snarkVM", author = "The Aleo Team <hello@aleo.org>", styles = STYLES)]
30pub struct CLI {
31 #[clap(default_value = "2", short, long)]
33 pub verbosity: u8,
34 #[clap(subcommand)]
36 pub command: Command,
37}
38
39#[derive(Debug, Parser)]
40pub enum Command {
41 #[clap(name = "build")]
42 Build(Build),
43 #[clap(name = "clean")]
44 Clean(Clean),
45 #[clap(name = "execute")]
46 Execute(Execute),
47 #[clap(name = "new")]
48 New(New),
49 #[clap(name = "run")]
50 Run(Run),
51 #[clap(name = "update")]
52 Update(Update),
53}
54
55impl Command {
56 pub fn parse(self) -> Result<String> {
58 match self {
59 Self::Build(command) => command.parse(),
60 Self::Clean(command) => command.parse(),
61 Self::Execute(command) => command.parse(),
62 Self::New(command) => command.parse(),
63 Self::Run(command) => command.parse(),
64 Self::Update(command) => command.parse(),
65 }
66 }
67}
68
69#[cfg(test)]
70mod tests {
71 use super::*;
72
73 #[test]
75 fn verify_cli() {
76 use clap::CommandFactory;
77 CLI::command().debug_assert()
78 }
79}