vx_cli/commands/
where_cmd.rs

1//! Which command implementation - Find vx-managed tools
2
3use crate::ui::UI;
4use anyhow::Result;
5use vx_paths::{PathManager, PathResolver};
6use vx_plugin::PluginRegistry;
7
8pub async fn handle(_registry: &PluginRegistry, tool: &str, all: bool) -> Result<()> {
9    UI::debug(&format!("Looking for vx-managed tool: {}", tool));
10
11    // Create path manager and resolver
12    let path_manager = PathManager::new()
13        .map_err(|e| anyhow::anyhow!("Failed to initialize path manager: {}", e))?;
14    let resolver = PathResolver::new(path_manager);
15
16    let locations = if all {
17        // Find all versions
18        resolver.find_tool_executables(tool)?
19    } else {
20        // Find only the latest version
21        match resolver.find_latest_executable(tool)? {
22            Some(path) => vec![path],
23            None => vec![],
24        }
25    };
26
27    if locations.is_empty() {
28        UI::error(&format!(
29            "Tool '{}' not found in vx-managed installations",
30            tool
31        ));
32        UI::hint("Use 'vx list' to see installed tools");
33        UI::hint(&format!("Use 'vx install {}' to install this tool", tool));
34        std::process::exit(1);
35    }
36
37    for location in locations {
38        println!("{}", location.display());
39    }
40
41    Ok(())
42}