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
59#[derive(Debug, Parser)]
61pub enum Command {
62 #[clap(subcommand)]
63 Account(Account),
64 #[clap(name = "clean")]
65 Clean(Clean),
66 #[clap(subcommand)]
67 Developer(Developer),
68 #[clap(name = "start")]
69 Start(Box<Start>),
70 #[clap(name = "update")]
71 Update(Update),
72}
73
74impl Command {
75 pub fn parse(self) -> Result<String> {
77 match self {
78 Self::Account(command) => command.parse(),
79 Self::Clean(command) => command.parse(),
80 Self::Developer(command) => command.parse(),
81 Self::Start(command) => command.parse(),
82 Self::Update(command) => command.parse(),
83 }
84 }
85}
86
87#[cfg(test)]
88mod tests {
89 use super::*;
90
91 #[test]
93 fn verify_cli() {
94 use clap::CommandFactory;
95 CLI::command().debug_assert()
96 }
97}