Class: RailsCodeHealth::CLI

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CLI

Returns a new instance of CLI.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rails_code_health/cli.rb', line 9

def initialize(args)
  @args = args
  @options = {
    path: '.',
    format: :console,
    output: nil,
    config: nil,
    verbose: false,
    fail_under: nil,
    max_critical: nil
  }
end

Class Method Details

.start(args) ⇒ Object



5
6
7
# File 'lib/rails_code_health/cli.rb', line 5

def self.start(args)
  new(args).run
end

Instance Method Details

#runObject



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

def run
  parse_options

  begin
    # Load custom config if provided
    if @options[:config]
      RailsCodeHealth.configuration.load_thresholds_from_file(@options[:config])
    end

    # Set output format
    RailsCodeHealth.configuration.output_format = @options[:format]

    puts "šŸ” Analyzing Rails project at: #{@options[:path]}" if @options[:verbose]
    puts "šŸ“Š Using format: #{@options[:format]}" if @options[:verbose]

    # Run the analysis
    results = analyze_project

    # Output the report
    output_report(results)

    puts "\nāœ… Analysis complete!" if @options[:verbose]

    # Apply CI gating thresholds (after report is emitted so the user still sees output)
    exit_code = gate_exit_code(results)
    exit exit_code unless exit_code.zero?

  rescue RailsCodeHealth::Error => e
    puts "āŒ Error: #{e.message}"
    exit 1
  rescue => e
    puts "šŸ’„ Unexpected error: #{e.message}"
    puts e.backtrace.join("\n") if @options[:verbose]
    exit 1
  end
end