wireman_config/
cli.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use crate::{install::install, setup::setup};
use clap::{Parser, Subcommand};

#[derive(Debug, Parser)]
#[clap(name = "wireman", version)]
pub struct Args {
    #[clap(subcommand)]
    pub command: Option<Command>,

    /// Optional path to the configuration file
    #[arg(short, long)]
    pub config: Option<String>,

    /// Use local protobuf files
    #[arg(short, long)]
    pub local_protos: bool,
}

#[derive(Debug, Subcommand)]
pub enum Command {
    /// Runs a health check and prompts configuration details.
    Check,
    /// Setup wireman and create a default configuration file.
    #[command(aliases = ["setup", "install"])]
    Init,
}

#[must_use]
pub fn parse() -> Args {
    let args = Args::parse();
    match args.command {
        Some(Command::Check) => {
            let _ = setup(true, &args);
        }
        Some(Command::Init) => {
            install();
        }
        None => {}
    }
    args
}