Skip to main content

ubt_cli/commands/
info.rs

1use crate::cli::Cli;
2use crate::config::UbtConfig;
3use crate::detect::detect_tool;
4use crate::error::UbtError;
5use crate::plugin::PluginRegistry;
6
7pub fn cmd_info(
8    cli: &Cli,
9    config: Option<&UbtConfig>,
10    project_root: &std::path::Path,
11    registry: &PluginRegistry,
12) -> Result<(), UbtError> {
13    let config_tool = config.and_then(|c| c.project.as_ref()?.tool.as_deref());
14    let detection = detect_tool(cli.tool.as_deref(), config_tool, project_root, registry)?;
15
16    if cli.verbose && !cli.quiet {
17        eprintln!(
18            "ubt: detected {} (variant: {}) at {}",
19            detection.plugin_name,
20            detection.variant_name,
21            detection.project_root.display()
22        );
23    }
24
25    if cli.quiet {
26        return Ok(());
27    }
28
29    let (plugin, _) = registry
30        .get(&detection.plugin_name)
31        .ok_or(UbtError::NoPluginMatch)?;
32
33    println!("Plugin:       {}", detection.plugin_name);
34    println!("Variant:      {}", detection.variant_name);
35    println!("Description:  {}", plugin.description);
36    if let Some(hp) = &plugin.homepage {
37        println!("Homepage:     {hp}");
38    }
39    println!("Project root: {}", detection.project_root.display());
40    if let Some(binary) = plugin.variants.get(&detection.variant_name) {
41        println!("Binary:       {}", binary.binary);
42        match which::which(&binary.binary) {
43            Ok(path) => println!("Binary path:  {}", path.display()),
44            Err(_) => println!("Binary path:  (not found in PATH)"),
45        }
46    }
47
48    Ok(())
49}