class RuboCopConfigUpdater::CLI

Constants

DEFAULT_OPTIONS

Attributes

options[RW]

Public Class Methods

new() click to toggle source
# File lib/rubocop_config_updater/cli.rb, line 14
def initialize
  @options = DEFAULT_OPTIONS.dup
end

Public Instance Methods

run(args = ARGV) click to toggle source
# File lib/rubocop_config_updater/cli.rb, line 18
def run(args = ARGV)
  parse_options(args)

  command = RuboCopConfigUpdater::CLI::Command.new(@options)

  return command.run(:version) if options[:version]

  unless File.exist?(options[:config_path])
    warn "File #{options[:config_path]} doesn't exist"
    exit(1)
  end

  # a little hack to minimalize operation time and stdout length
  stderr = `#{options[:cmd]} -L Gemfile 2>&1 >/dev/null`

  command.fix_errors(stderr)
end

Private Instance Methods

parse_options(args) click to toggle source
# File lib/rubocop_config_updater/cli.rb, line 38
def parse_options(args)
  OptionParser.new do |opts|
    opts.banner = 'Usage: rubocop_config_updater [options]'

    opts.on('-c', '--config PATH', 'Rubocop config path, i.e. .rubocop.yml') do |v|
      options[:config_path] = v
    end

    opts.on('-r', '--rubocop COMMAND', 'Rubocop command, i.e. bundle exec rubocop') do |v|
      options[:cmd] = v
    end

    opts.on('-v', '--version') do |v|
      options[:version] = v
    end
  end.parse!(args)
end