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::venv_cmd::VenvCommand;
5use clap::{Parser, Subcommand};
6
7#[derive(Parser)]
8#[command(name = "vx")]
9#[command(about = "Universal version executor for development tools")]
10#[command(version)]
11pub struct Cli {
12    #[command(subcommand)]
13    pub command: Option<Commands>,
14
15    /// Use system PATH to find tools instead of vx-managed versions
16    #[arg(long, global = true)]
17    pub use_system_path: bool,
18
19    /// Enable verbose output with detailed logging
20    #[arg(short, long, global = true)]
21    pub verbose: bool,
22
23    /// Tool and arguments to execute
24    #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
25    pub args: Vec<String>,
26}
27
28#[derive(Subcommand, Clone)]
29pub enum Commands {
30    /// Show version information
31    Version,
32
33    /// List supported tools
34    List {
35        /// Tool name to show details for (optional)
36        tool: Option<String>,
37        /// Show installation status for tools
38        #[arg(long)]
39        status: bool,
40    },
41
42    /// Install a specific tool version
43    Install {
44        /// Tool name (e.g., uv, node, go, rust)
45        tool: String,
46        /// Version to install (e.g., 1.0.0, latest, lts)
47        version: Option<String>,
48        /// Force reinstallation even if already installed
49        #[arg(long)]
50        force: bool,
51    },
52
53    /// Update tools to latest versions
54    Update {
55        /// Tool name (optional, updates all if not specified)
56        tool: Option<String>,
57        /// Apply updates automatically
58        #[arg(long)]
59        apply: bool,
60    },
61
62    /// Remove installed tool versions
63    Remove {
64        /// Tool name
65        tool: String,
66        /// Version to remove (optional, removes all if not specified)
67        version: Option<String>,
68        /// Force removal without confirmation
69        #[arg(long)]
70        force: bool,
71    },
72
73    /// Show where a tool is installed
74    Where {
75        /// Tool name
76        tool: String,
77        /// Show all installed versions
78        #[arg(long)]
79        all: bool,
80    },
81
82    /// Fetch and display available versions for a tool
83    Fetch {
84        /// Tool name
85        tool: String,
86        /// Show only latest versions (limit results)
87        #[arg(long)]
88        latest: Option<usize>,
89        /// Include pre-release versions
90        #[arg(long)]
91        prerelease: bool,
92        /// Show detailed version information
93        #[arg(long)]
94        detailed: bool,
95        /// Interactive mode for version selection
96        #[arg(short, long)]
97        interactive: bool,
98    },
99
100    /// Set default version for a tool (deprecated, use switch)
101    Use {
102        /// Tool and version (e.g., uv@1.0.0, node@18.0.0)
103        tool_version: String,
104    },
105
106    /// Switch to a different version of a tool
107    Switch {
108        /// Tool and version (e.g., go@1.21.6, node@18.0.0)
109        tool_version: String,
110        /// Make this the global default
111        #[arg(long)]
112        global: bool,
113    },
114
115    /// Show configuration
116    Config,
117
118    /// Initialize vx configuration for current project
119    Init,
120
121    /// Clean up orphaned packages and cache
122    Cleanup,
123
124    /// Show package statistics and disk usage
125    Stats,
126
127    /// Plugin management commands
128    Plugin {
129        #[command(subcommand)]
130        command: PluginCommand,
131    },
132
133    /// Virtual environment management
134    Venv {
135        #[command(subcommand)]
136        command: VenvCommand,
137    },
138}
139
140#[derive(Subcommand, Clone)]
141pub enum ConfigCommand {
142    /// Show current configuration
143    Show,
144    /// Set configuration value
145    Set {
146        /// Configuration key (e.g., defaults.auto_install)
147        key: String,
148        /// Configuration value
149        value: String,
150    },
151    /// Get configuration value
152    Get {
153        /// Configuration key
154        key: String,
155    },
156    /// Reset configuration to defaults
157    Reset {
158        /// Reset specific key only
159        key: Option<String>,
160    },
161    /// Edit configuration file
162    Edit,
163}
164
165#[derive(Subcommand, Clone)]
166pub enum PluginCommand {
167    /// List all plugins
168    List {
169        /// Show only enabled plugins
170        #[arg(long)]
171        enabled: bool,
172        /// Filter by category
173        #[arg(long)]
174        category: Option<String>,
175    },
176    /// Show plugin information
177    Info {
178        /// Plugin name
179        name: String,
180    },
181    /// Enable a plugin
182    Enable {
183        /// Plugin name
184        name: String,
185    },
186    /// Disable a plugin
187    Disable {
188        /// Plugin name
189        name: String,
190    },
191    /// Search plugins
192    Search {
193        /// Search query
194        query: String,
195    },
196    /// Show plugin statistics
197    Stats,
198}