Sha256: 1db88498e68a108c97878ba17fa83359088c570cf449d68d001a3e92f32de065

Contents?: true

Size: 1.79 KB

Versions: 2

Compression:

Stored size: 1.79 KB

Contents

require_relative '../git'
require 'optparse'

class RuboCop::Git::CLI
  def run(args = ARGV.dup)
    @options = RuboCop::Git::Options.new
    parse_arguments(args)
    RuboCop::Git::Runner.new.run(@options)
  end

  private

  def parse_arguments(args)
    args << '--staged' if args.delete('--cached') # support synonymous flag
    @options.commits = option_parser.parse(args)
  rescue OptionParser::InvalidOption, Options::Invalid => e
    warn "ERROR: #{e.message}"
    $stderr.puts
    warn option_parser
    exit 1
  end

  # rubocop:disable Metrics
  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('-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('-f', '--format FORMAT',
             'Set output format (see rubocop --help)') do |format|
        @options.format = format
      end

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

      opt.on('--only COP1,COP2', Array,
             'Run only specific cops or departments') do |args|
        @options.rubocop[:only] = args
      end

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

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

      opt.on('--version', 'Display version') do
        puts RuboCop::Git::VERSION
        exit 0
      end
    end
  end
  # rubocop:enable Metrics
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-git2-0.1.6 lib/rubocop/git/cli.rb
rubocop-git2-0.1.5 lib/rubocop/git/cli.rb