Class: Legion::CLI::Detect

Inherits:
Thor
  • Object
show all
Defined in:
lib/legion/cli/detect_command.rb

Constant Summary collapse

CORE_RECOMMENDATIONS =
{
  'legion-gaia' => 'Cognitive coordination (GAIA + agentic extensions)',
  'legion-llm'  => 'LLM routing and provider integration'
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/legion/cli/detect_command.rb', line 12

def self.exit_on_failure?
  true
end

Instance Method Details

#catalogObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/legion/cli/detect_command.rb', line 53

def catalog
  out = formatter
  require_detect_gem

  catalog = Legion::Extensions::Detect.catalog

  if options[:json]
    catalog_data = catalog.map do |rule|
      { name: rule[:name], extensions: rule[:extensions],
        signals: rule[:signals].map { |s| "#{s[:type]}:#{s[:match]}" } }
    end
    out.json(catalog: catalog_data)
  else
    out.header('Detection Catalog')
    out.spacer
    catalog.each do |rule|
      signals = rule[:signals].map { |s| "#{s[:type]}:#{s[:match]}" }.join(', ')
      extensions = rule[:extensions].join(', ')
      puts "  #{out.colorize(rule[:name].ljust(20), :label)} #{extensions.ljust(30)} #{signals}"
    end
    out.spacer
    puts "  #{catalog.size} detection rules"
  end
end

#missingObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/legion/cli/detect_command.rb', line 79

def missing
  out = formatter
  require_detect_gem

  missing_gems = Legion::Extensions::Detect.missing

  if options[:json]
    out.json(missing: missing_gems)
  elsif missing_gems.empty?
    out.success('All detected extensions are installed')
  else
    out.header('Missing Extensions')
    missing_gems.each { |name| puts "  gem install #{name}" }
    out.spacer
    puts "  #{missing_gems.size} extension(s) recommended"
    puts "  Run 'legionio detect --install' to install them"
  end
end

#scanObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/legion/cli/detect_command.rb', line 31

def scan
  out = formatter
  require_detect_gem

  results = Legion::Extensions::Detect.scan

  if options[:format]
    output = Legion::Extensions::Detect.format_results(format: options[:format], detections: results)
    puts output.is_a?(String) ? output : ::JSON.pretty_generate(output)
  elsif options[:json]
    out.json(detections: results)
  else
    display_detections(out, results)
    if options[:install]
      interactive_install(out, results)
    elsif options[:install_all]
      install_missing(out)
    end
  end
end