class MeowCop::CLI

Constants

CONFIG_FILE_NAME
EXIT_FAILURE
EXIT_SUCCESS
Options

Public Class Methods

start(args) click to toggle source
# File lib/meowcop/cli.rb, line 35
def self.start(args)
  action_name = args.shift || 'help'

  instance = self.new

  unless instance.public_methods(false).include?(action_name.to_sym)
    puts "Could not find command '#{action_name}'."
    instance.help(args)
    return EXIT_FAILURE
  end

  instance.public_send(action_name, args)
end

Public Instance Methods

help(_args) click to toggle source
# File lib/meowcop/cli.rb, line 63
    def help(_args)
      puts <<-END
Usage: meowcop <command>

Commands:
    init           Setup .rubocop.yml
    run            Run RuboCop with MeowCop
    version        Show version
    help           Show help
END

      EXIT_SUCCESS
    end
init(_args) click to toggle source
# File lib/meowcop/cli.rb, line 49
def init(_args)
  action = File.exist?(CONFIG_FILE_NAME) ? "overwritten" : "created"
  FileUtils.copy_file(config_file_path, CONFIG_FILE_NAME)
  puts "Meow! #{CONFIG_FILE_NAME} has been #{action} successfully."

  EXIT_SUCCESS
end
run(args) click to toggle source
# File lib/meowcop/cli.rb, line 57
def run(args)
  require 'rubocop'

  RuboCop::CLI.new.run(['--config', config_file_path, *args])
end
version(_args) click to toggle source
# File lib/meowcop/cli.rb, line 77
def version(_args)
  puts VERSION

  EXIT_SUCCESS
end

Private Instance Methods

config_file_path() click to toggle source
# File lib/meowcop/cli.rb, line 85
def config_file_path
  template_path = File.expand_path("../../examples", __dir__)
  File.join(template_path, CONFIG_FILE_NAME)
end