retch_cli/cli.rs
1// SPDX-FileCopyrightText: 2026 Ken Tobias
2// SPDX-License-Identifier: GPL-3.0-or-later
3
4//! Command-line interface definitions.
5//!
6//! Defines the CLI arguments, flags, and options using the `clap` crate.
7
8use clap::{Parser, ValueEnum};
9
10/// Command-line arguments for retch.
11#[derive(Parser, Debug)]
12#[command(name = "retch", author, version, about, long_about = None)]
13pub struct Cli {
14 /// Output mode: short, long, or custom
15 #[arg(short, long)]
16 pub mode: Option<String>,
17
18 /// Use a specific theme
19 #[arg(short, long)]
20 pub theme: Option<String>,
21
22 /// Path to custom config file
23 #[arg(short, long)]
24 pub config: Option<String>,
25
26 /// Force a specific distribution logo by name/ID
27 #[arg(long)]
28 pub logo: Option<String>,
29
30 /// Disable logo
31 #[arg(long)]
32 pub no_logo: bool,
33
34 /// Show only ASCII logo (even if graphics are supported)
35 #[arg(long)]
36 pub ascii_logo: bool,
37
38 /// Force Chafa symbols output (even if graphics are supported)
39 #[arg(long)]
40 pub chafa_logo: bool,
41
42 /// Short output mode (Host, OS, Kernel, CPU, GPU, Memory, Disk)
43 #[arg(short, long)]
44 pub short: bool,
45
46 /// Long output mode (show all fields)
47 #[arg(short, long)]
48 pub long: bool,
49
50 /// Full output mode (all fields including cosmetic and slow queries)
51 #[arg(short, long)]
52 pub full: bool,
53
54 /// List available themes
55 #[arg(long)]
56 pub list_themes: bool,
57
58 /// Print an example custom theme template
59 #[arg(long)]
60 pub print_theme_template: bool,
61
62 /// List known distros
63 #[arg(long)]
64 pub list_distros: bool,
65
66 /// Print logos for known distros
67 #[arg(long)]
68 pub print_logos: bool,
69
70 /// Print default config (commented) to stdout
71 #[arg(long)]
72 pub generate_config: bool,
73
74 /// Write default config to a file (uses default location if no path given)
75 #[arg(long)]
76 pub write_config: bool,
77
78 /// Path(s) to write the config file to. Only the first value is used.
79 #[arg(trailing_var_arg = true, num_args = 0..)]
80 pub write_config_path: Vec<String>,
81
82 /// Merge default settings (as comments) into existing config
83 #[arg(long)]
84 pub merge_config: bool,
85
86 /// Fields to display (comma separated). Overrides config
87 #[arg(long)]
88 pub fields: Option<String>,
89
90 /// Location for weather lookup (city name, ZIP code, airport code, or coordinates). Overrides config
91 #[arg(long)]
92 pub weather_location: Option<String>,
93
94 /// Temperature unit for weather: "fahrenheit" or "celsius". Overrides config
95 #[arg(long)]
96 pub weather_unit: Option<String>,
97
98 /// Generate shell completions
99 #[arg(long, value_enum)]
100 pub completions: Option<CompletionShell>,
101
102 /// When to use colour: "auto" (a terminal, and NO_COLOR unset), "always" or "never"
103 #[arg(long, value_enum, value_name = "WHEN")]
104 pub color: Option<ColorChoice>,
105}
106
107/// When to emit ANSI colour, from `--color`.
108///
109/// Omitting the flag is the same as `auto`. Only `always` and `never` override the
110/// `NO_COLOR` environment variable, because `auto` means "decide from the environment".
111#[derive(ValueEnum, Clone, Copy, Debug, PartialEq, Eq)]
112pub enum ColorChoice {
113 /// Colour when stdout is a terminal and `NO_COLOR` is unset or empty.
114 Auto,
115 /// Always colour, even when piped or when `NO_COLOR` is set.
116 Always,
117 /// Never colour.
118 Never,
119}
120
121/// Supported shells for completion generation.
122#[derive(ValueEnum, Clone, Debug)]
123pub enum CompletionShell {
124 Bash,
125 Elvish,
126 Fish,
127 #[clap(name = "power-shell")]
128 PowerShell,
129 Zsh,
130 Nushell,
131}