Class: Ukiryu::CliCommands::InfoCommand

Inherits:
BaseCommand show all
Defined in:
lib/ukiryu/cli_commands/info_command.rb

Overview

Show detailed information about a tool

Instance Attribute Summary

Attributes inherited from BaseCommand

#config, #options

Instance Method Summary collapse

Methods inherited from BaseCommand

#apply_cli_options_to_config, #default_register_path, #initialize, #setup_register, #stringify_keys

Constructor Details

This class inherits a constructor from Ukiryu::CliCommands::BaseCommand

Instance Method Details

#run(tool_name) ⇒ Object

Execute the info command

Parameters:

  • tool_name (String)

    the tool name



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/ukiryu/cli_commands/info_command.rb', line 10

def run(tool_name)
  setup_register

  # Use find_by for interface-based discovery (ping -> ping_bsd/ping_gnu)
  tool = Ukiryu::Tool.find_by(tool_name.to_sym)
  error!("Tool not found: #{tool_name}\nAvailable tools: #{Ukiryu::Register.tools.sort.join(', ')}") unless tool

  profile = tool.profile
  show_all = options[:all]

  say '', :clear

  # Show interface information if queried name differs from actual tool name
  if profile.name != tool_name.to_s && profile.implements
    say "Interface: #{tool_name}", :cyan
    say "  This tool implements the '#{tool_name}' interface", :dim
    say "  Tool: #{profile.name}", :white

    # Find other implementations of this interface
    other_implementations = find_other_implementations(tool_name.to_s, profile.name)
    say "  Other implementations: #{other_implementations.join(', ')}", :dim if other_implementations.any?

    if show_all
      say '', :clear
      say "All '#{tool_name}' implementations:", :yellow
      all_implementations = [profile.name, *other_implementations].sort
      all_implementations.each do |impl|
        impl_tool = Ukiryu::Tool.get(impl)
        if impl_tool
          status = impl_tool.available? ? '[✓]' : '[✗]'
          color = impl_tool.available? ? :green : :red
          say "  #{status.ljust(4)} #{impl}", color
        else
          say "  [?] #{impl}", :white
        end
      rescue Ukiryu::Errors::ToolNotFoundError, Ukiryu::Errors::ProfileNotFoundError
        # Tool exists but no compatible profile for this platform
        say "  [ ] #{impl}", :dim
      end
    end
  else
    say "Tool: #{profile.name || tool_name}", :cyan
  end

  say "Display Name: #{profile.display_name || 'N/A'}", :white
  say "Version: #{profile.version || 'N/A'}", :white
  say "Homepage: #{profile.homepage || 'N/A'}", :white

  say "Aliases: #{profile.aliases.join(', ')}", :white if profile.aliases && !profile.aliases.empty?

  # Version detection
  if profile.version_detection
    vd = profile.version_detection
    say '', :clear
    say 'Version Detection:', :yellow
    command_display = vd.command.is_a?(Array) ? vd.command.join(' ') : vd.command
    say "  Command: #{command_display}", :white
    say "  Pattern: #{vd.pattern}", :white
    say "  Modern Threshold: #{vd.modern_threshold}", :white if vd.modern_threshold
  end

  # Profiles
  if profile.profiles
    say '', :clear
    say "Profiles (#{profile.profiles.count}):", :yellow
    profile.profiles.each do |prof|
      platforms = Array(prof.platforms || ['all']).join(', ')
      shells = Array(prof.shells || ['all']).join(', ')
      option_style = prof.option_style || 'default'
      say "  #{prof.name || 'unnamed'}:", :white
      say "    Platforms: #{platforms}", :white
      say "    Shells: #{shells}", :white
      say "    Option Style: #{option_style}", :white
      say "    Inherits: #{prof.inherits || 'none'}", :white if prof.inherits
    end
  end

  # Availability
  say '', :clear
  if tool.available?
    say 'Status: INSTALLED', :green
    say "Executable: #{tool.executable}", :white
    say "Detected Version: #{tool.version || 'unknown'}", :white
  else
    say 'Status: NOT FOUND', :red
  end
end