class RuboCop::Daemon::CLI

Public Class Methods

new_parser() { |opts| ... } click to toggle source
# File lib/rubocop/daemon/cli.rb, line 8
def self.new_parser(&_block)
  OptionParser.new do |opts|
    opts.version = VERSION
    yield(opts)
  end
end

Public Instance Methods

parser() click to toggle source
# File lib/rubocop/daemon/cli.rb, line 28
def parser
  @parser ||= self.class.new_parser do |opts|
    opts.banner = 'usage: rubocop-daemon <command> [<args>]'
  end
end
run(argv = ARGV) click to toggle source
# File lib/rubocop/daemon/cli.rb, line 15
def run(argv = ARGV)
  parser.order!(argv)
  return if argv.empty?

  create_subcommand_instance(argv)
rescue OptionParser::InvalidOption => e
  warn "error: #{e.message}"
  exit 1
rescue UnknownClientCommandError => e
  warn "rubocop-daemon: #{e.message}. See 'rubocop-daemon --help'."
  exit 1
end

Private Instance Methods

create_subcommand_instance(argv) click to toggle source
# File lib/rubocop/daemon/cli.rb, line 36
def create_subcommand_instance(argv)
  subcommand, *args = argv
  find_subcommand_class(subcommand).new(args).run
end
find_subcommand_class(subcommand) click to toggle source
# File lib/rubocop/daemon/cli.rb, line 41
def find_subcommand_class(subcommand)
  case subcommand
  when 'exec' then ClientCommand::Exec
  when 'restart' then ClientCommand::Restart
  when 'start' then ClientCommand::Start
  when 'status' then ClientCommand::Status
  when 'stop' then ClientCommand::Stop
  else
    raise UnknownClientCommandError, "#{subcommand.inspect} is not a rubocop-daemon command"
  end
end