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.



57
58
59
# File 'lib/rubocop/options.rb', line 57

def initialize
  @options = {}
end

Instance Method Details

#parse(args) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/rubocop/options.rb', line 61

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 [COP1,COP2,...]') do |list|
      @options[:only] = list.split(',').map do |c|
        Cop::Cop.qualified_cop_name(c, '--only option')
      end
    end

    add_configuration_options(opts, args)
    add_formatting_options(opts)

    option(opts, '-r', '--require FILE') { |f| require f }

    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