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