vx_cli/cli.rs
1// CLI module - modular command structure
2// Each command is implemented in its own module for better maintainability
3
4use crate::commands::{global::GlobalCommand, venv_cmd::VenvCommand};
5use clap::{Parser, Subcommand, ValueEnum};
6
7#[derive(ValueEnum, Clone, Debug)]
8pub enum OutputFormat {
9 Table,
10 Json,
11 Yaml,
12}
13
14#[derive(Parser)]
15#[command(name = "vx")]
16#[command(about = "Universal version executor for development tools")]
17#[command(version)]
18pub struct Cli {
19 #[command(subcommand)]
20 pub command: Option<Commands>,
21
22 /// Use system PATH to find tools instead of vx-managed versions
23 #[arg(long, global = true)]
24 pub use_system_path: bool,
25
26 /// Enable verbose output with detailed logging
27 #[arg(short, long, global = true)]
28 pub verbose: bool,
29
30 /// Tool and arguments to execute
31 #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
32 pub args: Vec<String>,
33}
34
35#[derive(Subcommand, Clone)]
36pub enum Commands {
37 /// Show version information
38 Version,
39
40 /// List supported tools
41 #[command(alias = "ls")]
42 List {
43 /// Tool name to show details for (optional)
44 tool: Option<String>,
45 /// Show installation status for tools
46 #[arg(long)]
47 status: bool,
48 /// Show only installed tools
49 #[arg(long)]
50 installed: bool,
51 /// Show only available tools
52 #[arg(long)]
53 available: bool,
54 },
55
56 /// Install a specific tool version
57 #[command(alias = "i")]
58 Install {
59 /// Tool name (e.g., uv, node, go, rust)
60 tool: String,
61 /// Version to install (e.g., 1.0.0, latest, lts)
62 version: Option<String>,
63 /// Force reinstallation even if already installed
64 #[arg(long)]
65 force: bool,
66 },
67
68 /// Update tools to latest versions
69 #[command(alias = "up")]
70 Update {
71 /// Tool name (optional, updates all if not specified)
72 tool: Option<String>,
73 /// Apply updates automatically
74 #[arg(long)]
75 apply: bool,
76 },
77
78 /// Uninstall tool versions (preferred over remove)
79 #[command(alias = "rm")]
80 Uninstall {
81 /// Tool name
82 tool: String,
83 /// Version to uninstall (optional, removes all if not specified)
84 version: Option<String>,
85 /// Force removal without confirmation
86 #[arg(long)]
87 force: bool,
88 },
89
90 /// Show which tool version is being used (preferred over where)
91 Which {
92 /// Tool name
93 tool: String,
94 /// Show all installed versions
95 #[arg(long)]
96 all: bool,
97 },
98
99 /// Show available versions for a tool (preferred over fetch)
100 Versions {
101 /// Tool name
102 tool: String,
103 /// Show only latest versions (limit results)
104 #[arg(long)]
105 latest: Option<usize>,
106 /// Include pre-release versions
107 #[arg(long)]
108 prerelease: bool,
109 /// Show detailed version information
110 #[arg(long)]
111 detailed: bool,
112 /// Interactive mode for version selection
113 #[arg(short, long)]
114 interactive: bool,
115 },
116
117 /// Switch to a different version of a tool
118 Switch {
119 /// Tool and version (e.g., go@1.21.6, node@18.0.0)
120 tool_version: String,
121 /// Make this the global default
122 #[arg(long)]
123 global: bool,
124 },
125
126 /// Configuration management
127 #[command(alias = "cfg")]
128 Config {
129 #[command(subcommand)]
130 command: Option<ConfigCommand>,
131 },
132
133 /// Search available tools
134 Search {
135 /// Search query
136 query: Option<String>,
137 /// Filter by category
138 #[arg(long)]
139 category: Option<String>,
140 /// Show only installed tools
141 #[arg(long)]
142 installed_only: bool,
143 /// Show only available (not installed) tools
144 #[arg(long)]
145 available_only: bool,
146 /// Output format
147 #[arg(long, value_enum, default_value = "table")]
148 format: OutputFormat,
149 /// Show verbose information
150 #[arg(short, long)]
151 verbose: bool,
152 },
153
154 /// Sync project tools from .vx.toml
155 Sync {
156 /// Only check, don't install
157 #[arg(long)]
158 check: bool,
159 /// Force reinstall all tools
160 #[arg(long)]
161 force: bool,
162 /// Preview operations without executing
163 #[arg(long)]
164 dry_run: bool,
165 /// Show verbose output
166 #[arg(short, long)]
167 verbose: bool,
168 /// Disable parallel installation
169 #[arg(long)]
170 no_parallel: bool,
171 /// Disable auto-install
172 #[arg(long)]
173 no_auto_install: bool,
174 },
175
176 /// Initialize vx configuration for current project
177 Init {
178 /// Interactive initialization
179 #[arg(long)]
180 interactive: bool,
181 /// Use predefined template
182 #[arg(long)]
183 template: Option<String>,
184 /// Specify tools to include (comma-separated)
185 #[arg(long)]
186 tools: Option<String>,
187 /// Force overwrite existing configuration
188 #[arg(long)]
189 force: bool,
190 /// Preview configuration without creating file
191 #[arg(long)]
192 dry_run: bool,
193 /// List available templates
194 #[arg(long)]
195 list_templates: bool,
196 },
197
198 /// Clean up system (preferred over cleanup)
199 Clean {
200 /// Preview cleanup operations without executing
201 #[arg(long)]
202 dry_run: bool,
203 /// Only clean cache files
204 #[arg(long)]
205 cache: bool,
206 /// Only clean orphaned tool versions
207 #[arg(long)]
208 orphaned: bool,
209 /// Clean all (cache + orphaned)
210 #[arg(long)]
211 all: bool,
212 /// Force cleanup without confirmation
213 #[arg(long)]
214 force: bool,
215 /// Clean files older than specified days
216 #[arg(long)]
217 older_than: Option<u32>,
218 /// Show verbose output
219 #[arg(short, long)]
220 verbose: bool,
221 },
222
223 /// Show package statistics and disk usage
224 Stats,
225
226 /// Plugin management commands
227 Plugin {
228 #[command(subcommand)]
229 command: PluginCommand,
230 },
231
232 /// Shell integration commands
233 Shell {
234 #[command(subcommand)]
235 command: ShellCommand,
236 },
237
238 /// Virtual environment management
239 Venv {
240 #[command(subcommand)]
241 command: VenvCommand,
242 },
243
244 /// Global tool management
245 Global {
246 #[command(subcommand)]
247 command: GlobalCommand,
248 },
249}
250
251#[derive(Subcommand, Clone)]
252pub enum ConfigCommand {
253 /// Show current configuration
254 Show,
255 /// Set configuration value
256 Set {
257 /// Configuration key (e.g., defaults.auto_install)
258 key: String,
259 /// Configuration value
260 value: String,
261 },
262 /// Get configuration value
263 Get {
264 /// Configuration key
265 key: String,
266 },
267 /// Reset configuration to defaults
268 Reset {
269 /// Reset specific key only
270 key: Option<String>,
271 },
272 /// Edit configuration file
273 Edit,
274}
275
276#[derive(Subcommand, Clone)]
277pub enum PluginCommand {
278 /// List all plugins
279 List {
280 /// Show only enabled plugins
281 #[arg(long)]
282 enabled: bool,
283 /// Filter by category
284 #[arg(long)]
285 category: Option<String>,
286 },
287 /// Show plugin information
288 Info {
289 /// Plugin name
290 name: String,
291 },
292 /// Enable a plugin
293 Enable {
294 /// Plugin name
295 name: String,
296 },
297 /// Disable a plugin
298 Disable {
299 /// Plugin name
300 name: String,
301 },
302 /// Search plugins
303 Search {
304 /// Search query
305 query: String,
306 },
307 /// Show plugin statistics
308 Stats,
309}
310
311#[derive(Subcommand, Clone)]
312pub enum ShellCommand {
313 /// Generate shell initialization script
314 Init {
315 /// Shell type (auto-detected if not specified)
316 shell: Option<String>,
317 },
318 /// Generate shell completion script
319 Completions {
320 /// Shell type
321 shell: String,
322 },
323}