Sha256: 8e9bcb18f7d829a7f04f629d10450a6f451eede86cf2f54429ba29c2dbeffabb

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

require 'fileutils'

module RuboCop
  module Codetakt
    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 'rubocop-codetakt commands:'
        puts '  init - Setup .rubocop.yml'
      end

      CONFIG_FILE_NAME = '.rubocop.yml'.freeze
      def init(args)
        raise 'usage: rubocop-codetakt 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
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-codetakt-0.84.0.0 lib/rubocop/codetakt/cli.rb
rubocop-codetakt-0.83.0.1 lib/rubocop/codetakt/cli.rb
rubocop-codetakt-0.82.0.1 lib/rubocop/codetakt/cli.rb
rubocop-codetakt-0.83.0.0 lib/rubocop/codetakt/cli.rb