snarkos_cli/commands/
mod.rs1mod account;
17pub use account::*;
18
19mod clean;
20pub use clean::*;
21
22mod developer;
23pub use developer::*;
24
25mod start;
26pub use start::*;
27
28mod update;
29pub use update::*;
30
31use anstyle::{AnsiColor, Color, Style};
32use anyhow::Result;
33use clap::{Parser, builder::Styles};
34
35const HEADER_COLOR: Option<Color> = Some(Color::Ansi(AnsiColor::Yellow));
36const LITERAL_COLOR: Option<Color> = Some(Color::Ansi(AnsiColor::Green));
37const ERROR_COLOR: Option<Color> = Some(Color::Ansi(AnsiColor::Red));
38const INVALID_COLOR: Option<Color> = Some(Color::Ansi(AnsiColor::Magenta));
39
40const STYLES: Styles = Styles::plain()
41 .header(Style::new().bold().fg_color(HEADER_COLOR))
42 .usage(Style::new().bold().fg_color(HEADER_COLOR))
43 .error(Style::new().bold().fg_color(ERROR_COLOR))
44 .invalid(Style::new().fg_color(INVALID_COLOR))
45 .valid(Style::new().bold().fg_color(LITERAL_COLOR))
46 .literal(Style::new().bold().fg_color(LITERAL_COLOR));
47
48#[derive(Debug, Parser)]
52#[clap(name = "snarkOS", author, about, styles = STYLES, version)]
53pub struct CLI {
54 #[clap(subcommand)]
56 pub command: Command,
57
58 #[clap(long, global = true)]
60 pub noupdater: bool,
61}
62
63#[derive(Debug, Parser)]
65pub enum Command {
66 #[clap(subcommand)]
67 Account(Account),
68 #[clap(name = "clean")]
69 Clean(Clean),
70 #[clap(name = "developer", alias = "dev")]
71 Developer(Box<Developer>),
72 #[clap(name = "start")]
73 Start(Box<Start>),
74 #[clap(name = "update")]
75 Update(Update),
76}
77
78impl Command {
79 pub fn parse(self) -> Result<String> {
81 match self {
82 Self::Account(command) => command.parse(),
83 Self::Clean(command) => command.parse(),
84 Self::Developer(command) => command.parse(),
85 Self::Start(command) => command.parse(),
86 Self::Update(command) => command.parse(),
87 }
88 }
89}
90
91#[cfg(test)]
92mod tests {
93 use super::*;
94
95 #[test]
97 fn verify_cli() {
98 use clap::CommandFactory;
99 CLI::command().debug_assert()
100 }
101}