Class: RuboCop::CLI

Inherits:
Object
  • Object
show all
Includes:
Formatter::TextUtil
Defined in:
lib/rubocop/cli.rb

Overview

The CLI is a class responsible of handling all the command line interface logic.

Defined Under Namespace

Classes: Finished

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Formatter::TextUtil

pluralize

Constructor Details

#initializeCLI

Returns a new instance of CLI.



13
14
15
16
# File 'lib/rubocop/cli.rb', line 13

def initialize
  @options = {}
  @config_store = ConfigStore.new
end

Instance Attribute Details

#config_storeObject (readonly)

Returns the value of attribute config_store.



11
12
13
# File 'lib/rubocop/cli.rb', line 11

def config_store
  @config_store
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/rubocop/cli.rb', line 11

def options
  @options
end

Instance Method Details

#run(args = ARGV) ⇒ Integer

Entry point for the application logic. Here we do the command line arguments processing and inspect the target files.

Parameters:

  • args (Array<String>) (defaults to: ARGV)

    command line arguments

Returns:

  • (Integer)

    UNIX exit code



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rubocop/cli.rb', line 26

def run(args = ARGV)
  @options, paths = Options.new.parse(args)
  validate_options_vs_config
  act_on_options
  apply_default_formatter

  execute_runner(paths)
rescue RuboCop::Error => e
  $stderr.puts Rainbow("Error: #{e.message}").red
  return 2
rescue Finished
  return 0
rescue StandardError, SyntaxError => e
  $stderr.puts e.message
  $stderr.puts e.backtrace
  return 2
end

#trap_interrupt(runner) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/rubocop/cli.rb', line 44

def trap_interrupt(runner)
  Signal.trap('INT') do
    exit!(1) if runner.aborting?
    runner.abort
    $stderr.puts
    $stderr.puts 'Exiting... Interrupt again to exit immediately.'
  end
end