class RuboCop::Options

This class handles command line options.

def add_boolean_flags(opts)

def add_boolean_flags(opts)
  option(opts, '-F', '--fail-fast')
  option(opts, '-d', '--debug')
  option(opts, '-D', '--display-cop-names')
  option(opts, '-R', '--rails')
  option(opts, '-l', '--lint')
  option(opts, '-a', '--auto-correct')
  @options[:color] = true
  option(opts, '-n', '--no-color') { @options[:color] = false }
  option(opts, '-v', '--version')
  option(opts, '-V', '--verbose-version')
end

def add_configuration_options(opts, args)

def add_configuration_options(opts, args)
  option(opts, '-c', '--config FILE')
  option(opts, '--auto-gen-config') do
    validate_auto_gen_config_option(args)
    @options[:formatters] = [[DEFAULT_FORMATTER],
                             [Formatter::DisabledConfigFormatter,
                              ConfigLoader::AUTO_GENERATED_FILE]]
  end
  option(opts, '--force-exclusion')
end

def add_flags_with_optional_args(opts)

def add_flags_with_optional_args(opts)
  option(opts, '--show-cops [COP1,COP2,...]') do |list|
    @options[:show_cops] = list.nil? ? [] : list.split(',')
  end
end

def add_formatting_options(opts)

def add_formatting_options(opts)
  option(opts, '-f', '--format FORMATTER') do |key|
    @options[:formatters] ||= []
    @options[:formatters] << [key]
  end
  option(opts, '-o', '--out FILE') do |path|
    @options[:formatters] ||= [[DEFAULT_FORMATTER]]
    @options[:formatters].last << path
  end
end

def add_severity_option(opts)

def add_severity_option(opts)
  option(opts, '--fail-level SEVERITY',
         RuboCop::Cop::Severity::NAMES,
         RuboCop::Cop::Severity::CODE_TABLE) do |severity|
    @options[:fail_level] = severity
  end
end

def convert_deprecated_options(args)

def convert_deprecated_options(args)
  args.map! do |arg|
    case arg
    when '-e', '--emacs'
      deprecate("#{arg} option", '--format emacs', '1.0.0')
      %w(--format emacs)
    else
      arg
    end
  end.flatten!
end

def deprecate(subject, alternative = nil, version = nil)

def deprecate(subject, alternative = nil, version = nil)
  message =  "#{subject} is deprecated"
  message << " and will be removed in RuboCop #{version}" if version
  message << '.'
  message << " Please use #{alternative} instead." if alternative
  warn message
end

def ignore_dropped_options(args)

def ignore_dropped_options(args)
  # Currently we don't make -s/--silent option raise error
  # since those are mostly used by external tools.
  rejected = args.reject! { |a| %w(-s --silent).include?(a) }
  return unless rejected
  warn '-s/--silent options is dropped. ' \
       '`emacs` and `files` formatters no longer display summary.'
end

def initialize

def initialize
  @options = {}
end

def long_opt_symbol(args)

e.g. [..., '--auto-correct', ...] to :auto_correct.
Finds the option in `args` starting with -- and converts it to a symbol,
def long_opt_symbol(args)
  long_opt = args.find { |arg| arg.start_with?('--') }
  long_opt[2..-1].sub(/ .*/, '').gsub(/-/, '_').to_sym
end

def option(opts, *args)

value, in addition to calling the block if a block is given.
Sets a value in the @options hash, based on the given long option and its
def option(opts, *args)
  long_opt_symbol = long_opt_symbol(args)
  args += Array(OptionsHelp::TEXT[long_opt_symbol])
  opts.on(*args) do |arg|
    @options[long_opt_symbol] = arg
    yield arg if block_given?
  end
end

def parse(args)

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

def validate_auto_gen_config_option(args)

def validate_auto_gen_config_option(args)
  return unless args.any?
  warn '--auto-gen-config can not be combined with any other arguments.'
  exit(1)
end