class RuboCop::Git::CLI

Public Instance Methods

run(args = ARGV) click to toggle source
# File lib/rubocop/git/cli.rb, line 7
def run(args = ARGV)
  @options = Options.new
  parse_arguments(args)
  Runner.new.run(@options)
end

Private Instance Methods

option_parser() click to toggle source
# File lib/rubocop/git/cli.rb, line 24
def option_parser
  @option_parser ||= OptionParser.new do |opt|
    opt.banner << ' [[commit] commit]'

    opt.on('-c', '--config FILE',
           'Specify configuration file') do |config|
      @options.config = config
    end

    opt.on('-r', '--require FILE',
           'Require Ruby file') do |file|
      require file
    end

    opt.on('-a', '--auto-correct', 'Auto-correct offenses.') do
      @options.rubocop[:auto_correct] = true
    end

    opt.on('-d', '--debug', 'Display debug info') do
      @options.rubocop[:debug] = true
    end

    opt.on('-D', '--display-cop-names',
           'Display cop names in offense messages') do
      @options.rubocop[:display_cop_names] = true
    end

    opt.on('--cached', 'git diff --cached') do
      @options.cached = true
    end

    opt.on('--staged', 'synonym of --cached') do
      @options.cached = true
    end

    opt.on('--hound', 'Hound compatibility mode') do
      @options.hound = true
    end

    opt.on('--version', 'Display version') do
      puts RuboCop::Git::VERSION
      exit 0
    end
  end
end
parse_arguments(args) click to toggle source
# File lib/rubocop/git/cli.rb, line 15
def parse_arguments(args)
  @options.commits = option_parser.parse(args)
rescue OptionParser::InvalidOption, Options::Invalid => ex
  warn "ERROR: #{ex.message}"
  $stderr.puts
  warn option_parser
  exit 1
end