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 /// Update vx itself to the latest version
79 #[command(name = "self-update")]
80 SelfUpdate {
81 /// Only check for updates, don't install
82 #[arg(long)]
83 check: bool,
84 /// Specific version to install
85 version: Option<String>,
86 /// GitHub token for authenticated API requests (avoids rate limits)
87 #[arg(long)]
88 token: Option<String>,
89 /// Include pre-release versions
90 #[arg(long)]
91 prerelease: bool,
92 /// Force update even if already up to date
93 #[arg(long)]
94 force: bool,
95 },
96
97 /// Uninstall tool versions (preferred over remove)
98 #[command(alias = "rm")]
99 Uninstall {
100 /// Tool name
101 tool: String,
102 /// Version to uninstall (optional, removes all if not specified)
103 version: Option<String>,
104 /// Force removal without confirmation
105 #[arg(long)]
106 force: bool,
107 },
108
109 /// Show which tool version is being used (preferred over where)
110 Which {
111 /// Tool name
112 tool: String,
113 /// Show all installed versions
114 #[arg(long)]
115 all: bool,
116 },
117
118 /// Show available versions for a tool (preferred over fetch)
119 Versions {
120 /// Tool name
121 tool: String,
122 /// Show only latest versions (limit results)
123 #[arg(long)]
124 latest: Option<usize>,
125 /// Include pre-release versions
126 #[arg(long)]
127 prerelease: bool,
128 /// Show detailed version information
129 #[arg(long)]
130 detailed: bool,
131 /// Interactive mode for version selection
132 #[arg(short, long)]
133 interactive: bool,
134 },
135
136 /// Switch to a different version of a tool
137 Switch {
138 /// Tool and version (e.g., go@1.21.6, node@18.0.0)
139 tool_version: String,
140 /// Make this the global default
141 #[arg(long)]
142 global: bool,
143 },
144
145 /// Configuration management
146 #[command(alias = "cfg")]
147 Config {
148 #[command(subcommand)]
149 command: Option<ConfigCommand>,
150 },
151
152 /// Search available tools
153 Search {
154 /// Search query
155 query: Option<String>,
156 /// Filter by category
157 #[arg(long)]
158 category: Option<String>,
159 /// Show only installed tools
160 #[arg(long)]
161 installed_only: bool,
162 /// Show only available (not installed) tools
163 #[arg(long)]
164 available_only: bool,
165 /// Output format
166 #[arg(long, value_enum, default_value = "table")]
167 format: OutputFormat,
168 /// Show verbose information
169 #[arg(short, long)]
170 verbose: bool,
171 },
172
173 /// Sync project tools from .vx.toml
174 Sync {
175 /// Only check, don't install
176 #[arg(long)]
177 check: bool,
178 /// Force reinstall all tools
179 #[arg(long)]
180 force: bool,
181 /// Preview operations without executing
182 #[arg(long)]
183 dry_run: bool,
184 /// Show verbose output
185 #[arg(short, long)]
186 verbose: bool,
187 /// Disable parallel installation
188 #[arg(long)]
189 no_parallel: bool,
190 /// Disable auto-install
191 #[arg(long)]
192 no_auto_install: bool,
193 },
194
195 /// Initialize vx configuration for current project
196 Init {
197 /// Interactive initialization
198 #[arg(long)]
199 interactive: bool,
200 /// Use predefined template
201 #[arg(long)]
202 template: Option<String>,
203 /// Specify tools to include (comma-separated)
204 #[arg(long)]
205 tools: Option<String>,
206 /// Force overwrite existing configuration
207 #[arg(long)]
208 force: bool,
209 /// Preview configuration without creating file
210 #[arg(long)]
211 dry_run: bool,
212 /// List available templates
213 #[arg(long)]
214 list_templates: bool,
215 },
216
217 /// Clean up system (preferred over cleanup)
218 Clean {
219 /// Preview cleanup operations without executing
220 #[arg(long)]
221 dry_run: bool,
222 /// Only clean cache files
223 #[arg(long)]
224 cache: bool,
225 /// Only clean orphaned tool versions
226 #[arg(long)]
227 orphaned: bool,
228 /// Clean all (cache + orphaned)
229 #[arg(long)]
230 all: bool,
231 /// Force cleanup without confirmation
232 #[arg(long)]
233 force: bool,
234 /// Clean files older than specified days
235 #[arg(long)]
236 older_than: Option<u32>,
237 /// Show verbose output
238 #[arg(short, long)]
239 verbose: bool,
240 },
241
242 /// Show package statistics and disk usage
243 Stats,
244
245 /// Plugin management commands
246 Plugin {
247 #[command(subcommand)]
248 command: PluginCommand,
249 },
250
251 /// Shell integration commands
252 Shell {
253 #[command(subcommand)]
254 command: ShellCommand,
255 },
256
257 /// Virtual environment management
258 Venv {
259 #[command(subcommand)]
260 command: VenvCommand,
261 },
262
263 /// Global tool management
264 Global {
265 #[command(subcommand)]
266 command: GlobalCommand,
267 },
268}
269
270#[derive(Subcommand, Clone)]
271pub enum ConfigCommand {
272 /// Show current configuration
273 Show,
274 /// Set configuration value
275 Set {
276 /// Configuration key (e.g., defaults.auto_install)
277 key: String,
278 /// Configuration value
279 value: String,
280 },
281 /// Get configuration value
282 Get {
283 /// Configuration key
284 key: String,
285 },
286 /// Reset configuration to defaults
287 Reset {
288 /// Reset specific key only
289 key: Option<String>,
290 },
291 /// Edit configuration file
292 Edit,
293}
294
295#[derive(Subcommand, Clone)]
296pub enum PluginCommand {
297 /// List all plugins
298 List {
299 /// Show only enabled plugins
300 #[arg(long)]
301 enabled: bool,
302 /// Filter by category
303 #[arg(long)]
304 category: Option<String>,
305 },
306 /// Show plugin information
307 Info {
308 /// Plugin name
309 name: String,
310 },
311 /// Enable a plugin
312 Enable {
313 /// Plugin name
314 name: String,
315 },
316 /// Disable a plugin
317 Disable {
318 /// Plugin name
319 name: String,
320 },
321 /// Search plugins
322 Search {
323 /// Search query
324 query: String,
325 },
326 /// Show plugin statistics
327 Stats,
328}
329
330#[derive(Subcommand, Clone)]
331pub enum ShellCommand {
332 /// Generate shell initialization script
333 Init {
334 /// Shell type (auto-detected if not specified)
335 shell: Option<String>,
336 },
337 /// Generate shell completion script
338 Completions {
339 /// Shell type
340 shell: String,
341 },
342}