Skip to main content

lab_ops/
cli.rs

1use std::path::PathBuf;
2
3use clap::Parser;
4use clap::Subcommand;
5use clap::ValueEnum;
6
7use crate::consts::CMD_AUTO_DISCOVER;
8use crate::consts::CMD_CF2ANSIBLE;
9use crate::consts::CMD_CF2TERRA;
10use crate::consts::CMD_COMPLETIONS;
11use crate::consts::CMD_DOCKERNET;
12use crate::consts::CMD_NATMAP;
13
14/// Top-level CLI argument parser for `lab-ops`.
15#[derive(Parser)]
16#[command(version = env!("CARGO_PKG_VERSION"))]
17#[command(name = crate::consts::CMD, about = "Lab operations toolkit")]
18pub struct Cli {
19    #[command(subcommand)]
20    pub command: Command,
21
22    /// Verbosity level (-v, -vv, -vvv, -vvvv)
23    #[arg(short, long, global = true, action = clap::ArgAction::Count)]
24    pub verbose: u8,
25
26    /// Color output mode [auto|always|never]
27    #[arg(
28        long,
29        global = true,
30        default_value = "auto",
31        value_enum,
32        hide_possible_values = true
33    )]
34    pub color: ColorMode,
35}
36
37/// Controls ANSI color output in logs and error formatting.
38#[derive(Clone, Debug, Default, ValueEnum)]
39pub enum ColorMode {
40    #[default]
41    Auto,
42    Always,
43    Never,
44}
45
46/// All supported subcommands of lab-ops.
47#[derive(Subcommand)]
48pub enum Command {
49    /// Converts BIND DNS zone files to Ansible YAML tasks.
50    #[command(name = CMD_CF2ANSIBLE)]
51    Cf2Ansible {
52        /// Path to the DNS zone file to parse.
53        zone_file: PathBuf,
54        /// Zone name override; defaults to the name extracted from the SOA record.
55        zone_name: Option<String>,
56    },
57    /// Converts BIND DNS zone files to Terraform Cloudflare DNS resources.
58    #[command(name = CMD_CF2TERRA)]
59    Cf2Terra {
60        /// Path to the DNS zone file to parse.
61        zone_file: PathBuf,
62        /// Zone name override; defaults to the name extracted from the SOA record.
63        zone_name: Option<String>,
64        /// Terraform variable for the Cloudflare Zone ID.
65        #[arg(long, default_value = "var.cloudflare_zone_id")]
66        zone_id_var: String,
67    },
68    /// Displays IP addresses and port bindings of Docker containers.
69    #[command(name = CMD_DOCKERNET)]
70    DockerNet,
71    /// Manages iptables NAT rules for static VMs and dynamic Docker containers.
72    #[command(name = CMD_NATMAP)]
73    NatMap {
74        #[command(flatten)]
75        args: lab_ops_natmap::cli::Cli,
76    },
77    /// Service discovery daemon: watches Docker events, manages port forwarding,
78    /// registers services with Consul, and generates nginx configs.
79    #[command(name = CMD_AUTO_DISCOVER)]
80    AutoDiscover {
81        #[command(flatten)]
82        args: lab_ops_auto_discover::cli::Cli,
83    },
84    /// Generate shell completion scripts.
85    #[command(name = CMD_COMPLETIONS)]
86    Completions {
87        /// Target shell [bash, elvish, fish, powershell, zsh]
88        #[arg(value_enum, hide_possible_values = true)]
89        shell: clap_complete::Shell,
90        /// Output directory (e.g., ~/.zfunc)
91        #[arg(long)]
92        dir: Option<PathBuf>,
93    },
94}