bindcar/
cli.rs

1// Copyright (c) 2025 Erick Bourgeois, firestoned
2// SPDX-License-Identifier: MIT
3
4//! CLI argument parsing for the bindcar binary.
5//!
6//! bindcar supports two operating modes selected via subcommand:
7//!
8//! - **`run`** (default) — sidecar mode: runs alongside a local BIND9 instance inside a
9//!   Kubernetes pod, communicating over shared volumes and local RNDC.
10//!
11//! - **`drone`** — standalone mode: runs as an independent process on a bare-metal or VM
12//!   host, managing a remote BIND9 instance. Authentication is performed via the
13//!   Kubernetes TokenReview API using explicit credentials (`KUBE_API_SERVER`,
14//!   `KUBE_TOKEN_PATH`, `KUBE_CA_CERT_PATH`).
15//!
16//! When no subcommand is given, `run` is the default, preserving backwards compatibility
17//! for existing deployments and process supervisors that call `bindcar` directly.
18
19use clap::{Parser, Subcommand};
20
21/// bindcar — HTTP REST API for managing BIND9 zones via RNDC
22#[derive(Parser, Debug)]
23#[command(version, about, long_about = None)]
24pub struct Cli {
25    /// Enable debug-level logging (overrides RUST_LOG)
26    #[arg(long, short = 'd', global = true)]
27    pub debug: bool,
28
29    #[command(subcommand)]
30    pub command: Option<Commands>,
31}
32
33/// bindcar operating modes
34#[derive(Subcommand, Debug, PartialEq, Clone)]
35pub enum Commands {
36    /// Run as a Kubernetes sidecar alongside a local BIND9 instance (default)
37    Run,
38    /// Run standalone, managing a remote BIND9 instance from outside the cluster
39    Drone,
40}
41
42impl Cli {
43    /// Return the resolved command, defaulting to [`Commands::Run`] when no subcommand
44    /// was given. This preserves backwards compatibility: `bindcar` with no args
45    /// behaves identically to `bindcar run`.
46    pub fn resolved_command(&self) -> &Commands {
47        self.command.as_ref().unwrap_or(&Commands::Run)
48    }
49}