Skip to main content

wireman_config/
cli.rs

1use crate::{install::install, setup::setup};
2use clap::{CommandFactory, FromArgMatches};
3use clap::{Parser, Subcommand};
4
5#[derive(Debug, Parser)]
6#[clap(name = "wireman")]
7pub struct Args {
8    #[clap(subcommand)]
9    pub command: Option<Command>,
10
11    /// Optional path to the configuration file
12    #[arg(short, long)]
13    pub config: Option<String>,
14
15    /// Use local protobuf files
16    #[arg(short, long)]
17    pub local_protos: bool,
18}
19
20#[derive(Debug, Subcommand)]
21pub enum Command {
22    /// Runs a health check and prompts configuration details.
23    Check,
24    /// Setup wireman and create a default configuration file.
25    #[command(aliases = ["setup", "install"])]
26    Init,
27}
28
29#[must_use]
30pub fn parse(version: &'static str) -> Args {
31    let matches = Args::command().version(version).get_matches();
32    let args = Args::from_arg_matches(&matches).unwrap();
33    match args.command {
34        Some(Command::Check) => {
35            let _ = setup(true, &args);
36        }
37        Some(Command::Init) => {
38            install();
39        }
40        None => {}
41    }
42    args
43}