vx_cli/commands/
where_cmd.rs

1//! Where command implementation
2
3use crate::ui::UI;
4use vx_core::{PluginRegistry, Result, VxEnvironment, VxError};
5
6pub async fn handle(registry: &PluginRegistry, tool: &str, all: bool) -> Result<()> {
7    // Get the tool from registry
8    let vx_tool = registry
9        .get_tool(tool)
10        .ok_or_else(|| VxError::ToolNotFound {
11            tool_name: tool.to_string(),
12        })?;
13
14    // Create environment manager
15    let env = VxEnvironment::new().map_err(|e| VxError::Other {
16        message: format!("Failed to create VX environment: {}", e),
17    })?;
18
19    // Get installed versions
20    let installed_versions = vx_tool.get_installed_versions().await.unwrap_or_default();
21
22    if installed_versions.is_empty() {
23        UI::warn(&format!("Tool '{}' is not installed", tool));
24        UI::hint(&format!("Use 'vx install {}' to install it", tool));
25        UI::hint("Run 'vx list' to see available tools");
26        return Ok(());
27    }
28
29    // Get active version
30    let active_version = vx_tool.get_active_version().await.ok();
31
32    UI::info(&format!("Tool: {}", tool));
33    UI::detail(&format!("Description: {}", vx_tool.description()));
34
35    if let Some(active_version) = &active_version {
36        UI::success(&format!("Active version: {}", active_version));
37
38        // Show active version details
39        if let Ok(Some(installation)) = env.get_installation_info(tool, active_version) {
40            UI::detail(&format!(
41                "Install directory: {}",
42                installation.install_dir.display()
43            ));
44            UI::detail(&format!(
45                "Executable path: {}",
46                installation.executable_path.display()
47            ));
48            UI::detail(&format!(
49                "Installed at: {}",
50                installation.installed_at.format("%Y-%m-%d %H:%M:%S UTC")
51            ));
52        }
53    } else {
54        UI::warn("No active version set");
55    }
56
57    // Show all versions if requested or if there are multiple versions
58    if all || installed_versions.len() > 1 {
59        UI::info(&format!(
60            "\nAll installed versions ({}):",
61            installed_versions.len()
62        ));
63
64        for version in &installed_versions {
65            let is_active = active_version.as_ref() == Some(version);
66            let status_icon = if is_active { "✅" } else { "📦" };
67
68            UI::item(&format!("{} {}", status_icon, version));
69
70            // Show installation details for each version
71            if let Ok(Some(installation)) = env.get_installation_info(tool, version) {
72                UI::detail(&format!("   Path: {}", installation.install_dir.display()));
73                if is_active {
74                    UI::detail(&format!(
75                        "   Executable: {}",
76                        installation.executable_path.display()
77                    ));
78                }
79            }
80        }
81
82        if !all && installed_versions.len() > 1 {
83            UI::hint("Use --all to see details for all versions");
84        }
85    }
86
87    Ok(())
88}