Sha256: 289e17de8de1e00c9c999473819ea75fd3a65a9640eeb0d72d6594e9c59c61e8

Contents?: true

Size: 1.89 KB

Versions: 1

Compression:

Stored size: 1.89 KB

Contents

require_relative '../git'
require 'optparse'

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

      private

      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

      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('-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('--only COP1,COP2', Array) do |args|
            @options.rubocop[:only] = args
          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('-f', '--format FORMAT',
                 'Choose an output formatter') do |format|
            @options.format = format
          end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-git2-0.1.4 lib/rubocop/git/cli.rb