Class: Rubycritic::Cli

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

Constant Summary collapse

STATUS_SUCCESS =
0

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Cli

Returns a new instance of Cli.



10
11
12
13
14
# File 'lib/rubycritic/cli.rb', line 10

def initialize(argv)
  @argv = argv
  @argv << "." if @argv.empty?
  @main_command = true
end

Instance Method Details

#executeObject



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

def execute
  OptionParser.new do |opts|
    opts.banner = "Usage: rubycritic [options] [paths]"

    opts.on("-p", "--path [PATH]", "Set path where report will be saved (tmp/rubycritic by default)") do |path|
      ::Rubycritic.configuration.root = path
    end

    opts.on_tail("-v", "--version", "Show gem's version") do
      require "rubycritic/version"
      puts "RubyCritic #{VERSION}"
      @main_command = false
    end

    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      @main_command = false
    end
  end.parse!(@argv)

  if @main_command
    analysed_modules = Orchestrator.new.critique(@argv)
    report_location = Reporter::Main.new(analysed_modules).generate_report
    puts "New critique at #{report_location}"
  end

  STATUS_SUCCESS
end