vx_cli/commands/
switch.rs

1//! Switch command implementation
2
3use crate::ui::UI;
4use anyhow::Result;
5use vx_plugin::PluginRegistry;
6
7pub async fn handle(_registry: &PluginRegistry, tool_version: &str, global: bool) -> Result<()> {
8    // Parse tool@version format
9    let (tool_name, version) = parse_tool_version(tool_version)?;
10
11    UI::info(&format!("Switching {} to version {}", tool_name, version));
12
13    // Simplified implementation - switch command not fully implemented yet
14    UI::warning("Switch command not yet fully implemented in new architecture");
15    UI::hint(&format!(
16        "Would switch {} to version {} (global: {})",
17        tool_name, version, global
18    ));
19
20    Ok(())
21}
22
23/// Parse tool@version format
24pub fn parse_tool_version(tool_version: &str) -> Result<(String, String)> {
25    if let Some((tool, version)) = tool_version.split_once('@') {
26        if tool.is_empty() || version.is_empty() {
27            return Err(anyhow::anyhow!(
28                "Invalid tool@version format: {}",
29                tool_version
30            ));
31        }
32        Ok((tool.to_string(), version.to_string()))
33    } else {
34        Err(anyhow::anyhow!(
35            "Invalid format: {}. Expected format: tool@version (e.g., node@20.10.0)",
36            tool_version
37        ))
38    }
39}
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44
45    #[test]
46    fn test_parse_tool_version() {
47        // Valid cases
48        assert_eq!(
49            parse_tool_version("node@20.10.0").unwrap(),
50            ("node".to_string(), "20.10.0".to_string())
51        );
52        assert_eq!(
53            parse_tool_version("python@3.11.0").unwrap(),
54            ("python".to_string(), "3.11.0".to_string())
55        );
56
57        // Invalid cases
58        assert!(parse_tool_version("node").is_err());
59        assert!(parse_tool_version("@20.10.0").is_err());
60        assert!(parse_tool_version("node@").is_err());
61        assert!(parse_tool_version("").is_err());
62    }
63}