Sha256: d3b5187d63bc10377bcdc544b3c97e70e49bfb3c06af191fd384204f844c18f1

Contents?: true

Size: 1.09 KB

Versions: 16

Compression:

Stored size: 1.09 KB

Contents

require "fileutils"
module Fablicop
  class CLI
    def self.start(args)
      action_name = retrieve_command_name(args)
      unless action_name
        print_help
        exit
      end

      instance = self.new
      if instance.public_methods(false).include?(action_name.to_sym)
        instance.__send__(action_name, args)
        exit
      end

      puts "Could not find command #{action_name}."
      print_help
      exit(1)
    rescue => e
      puts e.message
      exit(1)
    end

    def self.retrieve_command_name(args)
      meth = args.first.to_s unless args.empty?
      args.shift if meth && (meth !~ /^\-/)
    end

    def self.print_help
      puts "fablicop commands:"
      puts "  init - Setup .rubocop.yml"
    end

    CONFIG_FILE_NAME = ".rubocop.yml"
    def init(args)
      raise "usage: fablicop init" unless args.empty?
      template_path = File.expand_path("../../templates", __dir__)
      puts "#{File.exist?(CONFIG_FILE_NAME) ? "overwrite" : "create"} #{CONFIG_FILE_NAME}"
      FileUtils.copy_file(File.join(template_path, CONFIG_FILE_NAME), CONFIG_FILE_NAME)
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
fablicop-1.1.0 lib/fablicop/cli.rb
fablicop-1.0.9 lib/fablicop/cli.rb
fablicop-1.0.8 lib/fablicop/cli.rb
fablicop-1.0.7 lib/fablicop/cli.rb
fablicop-1.0.6 lib/fablicop/cli.rb
fablicop-1.0.5 lib/fablicop/cli.rb
fablicop-1.0.4 lib/fablicop/cli.rb
fablicop-1.0.3 lib/fablicop/cli.rb
fablicop-1.0.2 lib/fablicop/cli.rb
fablicop-1.0.1 lib/fablicop/cli.rb
fablicop-0.3.4 lib/fablicop/cli.rb
fablicop-0.3.3 lib/fablicop/cli.rb
fablicop-0.3.2 lib/fablicop/cli.rb
fablicop-0.3.1 lib/fablicop/cli.rb
fablicop-0.3.0 lib/fablicop/cli.rb
fablicop-0.2.0 lib/fablicop/cli.rb