Skip to main content

xianyun_cli/
lib.rs

1//! Library crate for the `caproni` CLI.
2//!
3//! This mirrors the command tree wired up by Go's `cmd/factory.go`
4//! (`urfave/cli/v3`) using `clap`'s derive API.
5//!
6//! Exposed as a library (in addition to the `caproni` binary) so
7//! integration tests can exercise pure CLI-layer logic (clap parsing,
8//! command-tree structure, argument-independent helper functions like
9//! `commands::update::build_repo_filter`) directly, without spawning a
10//! subprocess for every assertion.
11
12pub mod buildinfo;
13pub mod commands;
14pub mod drivers;
15pub mod exitcode;
16pub mod hooks;
17
18use clap::{Parser, Subcommand};
19
20/// GitLab Kubernetes Development Kit.
21///
22/// Caproni is a command-line tool that orchestrates local Kubernetes
23/// development environments for GitLab. It provides a simple interface for
24/// running GitLab's Cloud Native deployment locally, with first-class
25/// support for hot-reload development workflows.
26#[derive(Parser, Debug)]
27#[command(name = "xianyun", version, about, long_about = None)]
28pub struct Cli {
29    /// Path to configuration file.
30    /// If omitted, caproni will perform a search through the parent
31    /// directories for caproni.yaml.
32    #[arg(short = 'c', long = "config-file", global = true)]
33    pub config_file: Option<String>,
34
35    /// Disables remote config fragment caching. `XIANYUN_NO_CACHE` is the
36    /// primary env var; `CAPRONI_NO_CACHE` is still recognized as a
37    /// compatibility alias (see `hooks::before_hook`, which checks it
38    /// since `clap`'s `env` attribute only supports one name).
39    #[arg(long = "no-cache", env = "XIANYUN_NO_CACHE", global = true)]
40    pub no_cache: bool,
41
42    /// Log output format (text or json).
43    #[arg(long = "log-format", global = true)]
44    pub log_format: Option<String>,
45
46    /// Log level (debug, info, warn, error).
47    #[arg(long = "log-level", global = true)]
48    pub log_level: Option<String>,
49
50    /// Enable/disable colored log output.
51    #[arg(long = "log-color", global = true)]
52    pub log_color: Option<bool>,
53
54    /// Where to write logs (stderr, or a file path).
55    #[arg(long = "log-output", global = true)]
56    pub log_output: Option<String>,
57
58    /// Include the source location in log lines.
59    #[arg(long = "log-source", global = true)]
60    pub log_source: bool,
61
62    /// Shorthand for --log-level=debug.
63    #[arg(long = "debug", global = true)]
64    pub debug: bool,
65
66    #[command(subcommand)]
67    pub command: Commands,
68}
69
70/// Top-level subcommands, matching `cmd/factory.go`'s `app.Commands` slice.
71#[derive(Subcommand, Debug)]
72pub enum Commands {
73    /// Start the Caproni cluster and deploy all deployers.
74    #[command(alias = "start")]
75    Up(commands::up::UpArgs),
76
77    /// Stop the Caproni cluster.
78    #[command(alias = "stop")]
79    Down(commands::down::DownArgs),
80
81    /// Destroy the Caproni cluster and delete all its data.
82    Destroy(commands::destroy::DestroyArgs),
83
84    /// Show the status of all services.
85    Status(commands::status::StatusArgs),
86
87    /// Update all repository source code.
88    Update(commands::update::UpdateArgs),
89
90    /// Deploy or update Helm charts to the cluster.
91    Deploy(commands::deploy::DeployArgs),
92
93    /// Update /etc/hosts file with cluster hostnames.
94    #[command(name = "update-etc-hosts")]
95    UpdateEtcHosts(commands::updateetchosts::UpdateEtcHostsArgs),
96
97    /// Add the cluster's context to your kubeconfig.
98    #[command(name = "set-kube-context")]
99    SetKubeContext(commands::setkubecontext::SetKubeContextArgs),
100
101    /// Run reloaders in edit mode until interrupted.
102    Run(commands::run::RunArgs),
103
104    /// Configuration management commands.
105    Config(commands::config::ConfigArgs),
106
107    /// Print version information.
108    #[command(name = commands::version::COMMAND_NAME)]
109    Version(commands::version::VersionArgs),
110
111    /// Supervise and restart edit mode processes.
112    ///
113    /// Hidden internal command started by `caproni run` for each reloader.
114    #[command(name = commands::editmodeprocesssupervisor::COMMAND_NAME, hide = true)]
115    EditModeProcessSupervisor(commands::editmodeprocesssupervisor::EditModeProcessSupervisorArgs),
116
117    /// Manage the Caproni Dev CA certificate.
118    Ca(commands::ca::CaArgs),
119
120    /// Run kubectl in the context of the cluster.
121    #[command(disable_help_flag = true)]
122    Kubectl(commands::kubectl::KubectlArgs),
123
124    /// Browse the cluster with k9s.
125    #[command(disable_help_flag = true)]
126    K9s(commands::k9s::K9sArgs),
127
128    /// Tail logs from multiple pods with stern.
129    #[command(disable_help_flag = true)]
130    Stern(commands::stern::SternArgs),
131
132    /// Manage caproni's host-side registry cache.
133    Registry(commands::registry::RegistryArgs),
134
135    /// View edit mode reloader logs.
136    Logs(commands::logs::LogsArgs),
137
138    /// Run built-in diagnostics to help troubleshoot Caproni.
139    Doctor(commands::doctor::DoctorArgs),
140
141    /// Run an executable on PATH with access to the cluster.
142    #[command(disable_help_flag = true)]
143    Tool(commands::tool::ToolArgs),
144}