Sha256: fe1f99f3e5323a3238137a7340b18e9c660ae7f7af7d56308b07c937e9011ff6

Contents?: true

Size: 1.54 KB

Versions: 4

Compression:

Stored size: 1.54 KB

Contents

require 'fileutils'
require 'pre-commit/configuration'
require 'pre-commit/installer'
require 'pre-commit/list_evaluator'

module PreCommit

  TemplateNotFound = Class.new(StandardError)

  class Cli

    def initialize(*args)
      @args = args
    end

    def execute()
      action_name = @args.shift or 'help'
      action = "execute_#{action_name}".to_sym
      if respond_to?(action)
      then send(action, *@args)
      else execute_help(action_name, *@args)
      end
    end

    def execute_help(*args)
      warn "Unknown parameters: #{args * " "}" unless args.empty?
      warn "Usage: pre-commit install"
      warn "Usage: pre-commit list"
      warn "Usage: pre-commit plugins"
      warn "Usage: pre-commit <enable|disable> <git|yaml> <checks|warnings> check1 [check2...]"
      args.empty? # return status, it's ok if user requested help
    end

    def execute_install(key = nil, *args)
      PreCommit::Installer.new(key).install
    end

    def execute_list(*args)
      puts list_evaluator.list
      true
    end

    def execute_plugins(*args)
      puts list_evaluator.plugins
      true
    end

    def execute_enable(*args)
      config.enable(*args)
    rescue ArgumentError
      execute_help('enable', *args)
    end

    def execute_disable(*args)
      config.disable(*args)
    rescue ArgumentError
      execute_help('disable', *args)
    end

    def config
      @config ||= PreCommit::Configuration.new(PreCommit.pluginator)
    end

    def list_evaluator
      @list_evaluator ||= PreCommit::ListEvaluator.new(config)
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pre-commit-0.16.3 lib/pre-commit/cli.rb
pre-commit-0.16.2 lib/pre-commit/cli.rb
pre-commit-0.16.1 lib/pre-commit/cli.rb
pre-commit-0.16.0 lib/pre-commit/cli.rb