Class: SentinelRb::CLI

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

Overview

Command Line Interface for SentinelRb

Instance Method Summary collapse

Instance Method Details

#analyzeObject



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
# File 'lib/sentinel_rb/cli.rb', line 21

def analyze
  # Load configuration
  config = load_config(options[:config])
  analyzer = SentinelRb::Analyzer.new(config)

  # Determine files to analyze
  files_to_analyze = determine_files(options)
  error_exit("No files found to analyze. Use --glob or --files to specify files.") if files_to_analyze.empty?

  say("Analyzing #{files_to_analyze.length} files...") unless options[:quiet]

  # Run analysis
  results = files_to_analyze.map do |file|
    say("  Analyzing #{file}...") if options[:verbose]
    analyzer.analyze_file(file, analyzer_ids: options[:analyzers])
  end

  # Format and output results
  formatted_output = SentinelRb::Report::Formatter.format(
    results,
    format: options[:format],
    show_summary: !options[:no_summary],
    colorize: !options[:no_color] && $stdout.tty?
  )

  output_results(formatted_output, options[:output])

  # Exit with appropriate code
  summary = analyzer.summarize_results(results)
  exit_code = summary[:total_findings].positive? ? 1 : 0
  exit(exit_code)
rescue StandardError => e
  error_exit("Analysis failed: #{e.message}")
end

#configObject



63
64
65
66
67
68
69
70
71
# File 'lib/sentinel_rb/cli.rb', line 63

def config
  config = load_config(options[:config])
  say("Configuration loaded from: #{options[:config]}")
  say("")

  config.to_h.each do |key, value|
    say("#{key}: #{value}")
  end
end

#test_connectionObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/sentinel_rb/cli.rb', line 75

def test_connection
  config = load_config(options[:config])
  client = SentinelRb::Client::Factory.create(config)

  say("Testing connection to #{config.provider}...")

  begin
    # Test with a simple analysis
    result = client.analyze_content("This is a test prompt for connection verification.")

    if result[:relevance_score]
      say("✅ Connection successful!")
      say("Test analysis score: #{result[:relevance_score].round(3)}")
    else
      error_exit("❌ Connection failed: No response received")
    end
  rescue StandardError => e
    error_exit("❌ Connection failed: #{e.message}")
  end
end

#versionObject



57
58
59
# File 'lib/sentinel_rb/cli.rb', line 57

def version
  say("SentinelRb #{SentinelRb::VERSION}")
end