Class: Rubocop::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/options.rb

Overview

This class handles command line options.

Constant Summary collapse

DEFAULT_FORMATTER =
'progress'
EXITING_OPTIONS =
[:version, :verbose_version, :show_cops]

Instance Method Summary collapse

Constructor Details

#initializeOptions

Returns a new instance of Options.



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

def initialize
  @options = {}
end

Instance Method Details

#parse(args) ⇒ Object



15
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/rubocop/options.rb', line 15

def parse(args)
  ignore_dropped_options(args)
  convert_deprecated_options(args)

  OptionParser.new do |opts|
    opts.banner = 'Usage: rubocop [options] [file1, file2, ...]'

    option(opts, '--only COP', 'Run just one cop.') do
      validate_only_option
    end

    add_configuration_options(opts, args)
    add_formatting_options(opts, args)

    option(opts, '-r', '--require FILE', 'Require Ruby file.') do |f|
      require f
    end

    add_severity_option(opts)
    add_flags_with_optional_args(opts)
    add_boolean_flags(opts)
  end.parse!(args)

  if (incompat = @options.keys & EXITING_OPTIONS).size > 1
    fail ArgumentError, "Incompatible cli options: #{incompat.inspect}"
  end

  [@options, args]
end