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

Constant Summary collapse

PHASE_1 =
'Phase 1 of 2: run Metrics/LineLength cop'
PHASE_2 =
'Phase 2 of 2: run all cops'
PHASE_1_OVERRIDDEN =
'(skipped because the default Metrics/LineLength:Max' \
' is overridden)'
PHASE_1_DISABLED =
'(skipped because Metrics/LineLength is ' \
'disabled)'
STATUS_SUCCESS =
0
STATUS_OFFENSES =
1
STATUS_ERROR =
2
STATUS_INTERRUPTED =
128 + Signal.list['INT']

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Formatter::TextUtil

pluralize

Constructor Details

#initializeCLI

Returns a new instance of CLI


27
28
29
30
# File 'lib/rubocop/cli.rb', line 27

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

Instance Attribute Details

#config_storeObject (readonly)

Returns the value of attribute config_store


25
26
27
# File 'lib/rubocop/cli.rb', line 25

def config_store
  @config_store
end

#optionsObject (readonly)

Returns the value of attribute options


25
26
27
# File 'lib/rubocop/cli.rb', line 25

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.

rubocop:disable Metrics/MethodLength, Metrics/AbcSize

Parameters:

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

    command line arguments

Returns:

  • (Integer)

    UNIX exit code


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rubocop/cli.rb', line 42

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

  if @options[:init]
    init_dotfile
  else
    validate_options_vs_config
    act_on_options
    apply_default_formatter
    execute_runners(paths)
  end
rescue ConfigNotFoundError, IncorrectCopNameError, OptionArgumentError => e
  warn e.message
  STATUS_ERROR
rescue RuboCop::Error => e
  warn Rainbow("Error: #{e.message}").red
  STATUS_ERROR
rescue Finished
  STATUS_SUCCESS
rescue OptionParser::InvalidOption => e
  warn e.message
  warn 'For usage information, use --help'
  STATUS_ERROR
rescue StandardError, SyntaxError, LoadError => e
  warn e.message
  warn e.backtrace
  STATUS_ERROR
end