Class: PreCommit::Cli
- Inherits:
-
Object
- Object
- PreCommit::Cli
- Defined in:
- lib/pre-commit/cli.rb
Instance Method Summary collapse
- #config ⇒ Object
- #execute ⇒ Object
- #execute_disable(*args) ⇒ Object
- #execute_enable(*args) ⇒ Object
- #execute_help(*args) ⇒ Object
- #execute_install(key = nil, *args) ⇒ Object
- #execute_list(*args) ⇒ Object
- #execute_new(*args) ⇒ Object
- #execute_plugins(*args) ⇒ Object
- #execute_run(*args) ⇒ Object
-
#initialize(*args) ⇒ Cli
constructor
A new instance of Cli.
- #list_evaluator ⇒ Object
Constructor Details
#initialize(*args) ⇒ Cli
Returns a new instance of Cli.
13 14 15 |
# File 'lib/pre-commit/cli.rb', line 13 def initialize(*args) @args = args end |
Instance Method Details
#config ⇒ Object
74 75 76 |
# File 'lib/pre-commit/cli.rb', line 74 def config @config ||= PreCommit::Configuration.new(PreCommit.pluginator) end |
#execute ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/pre-commit/cli.rb', line 17 def execute() action_name = @args.shift or 'help' action = :"execute_#{action_name}" if respond_to?(action) then send(action, *@args) else execute_help(action_name, *@args) end end |
#execute_disable(*args) ⇒ Object
68 69 70 71 72 |
# File 'lib/pre-commit/cli.rb', line 68 def execute_disable(*args) config.disable(*args) rescue ArgumentError execute_help('disable', *args) end |
#execute_enable(*args) ⇒ Object
62 63 64 65 66 |
# File 'lib/pre-commit/cli.rb', line 62 def execute_enable(*args) config.enable(*args) rescue ArgumentError execute_help('enable', *args) end |
#execute_help(*args) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/pre-commit/cli.rb', line 26 def execute_help(*args) warn "Unknown parameters: #{args.map(&:inspect) * " "}" unless args.empty? warn "Usage: pre-commit install" warn "Usage: pre-commit list" warn "Usage: pre-commit plugins" warn "Usage: pre-commit new plugin-name 'Author Name' author@email 'description of the plugin'" warn "Usage: pre-commit <enable|disable> <git|yaml> <checks|warnings> check1 [check2...]" args.empty? # return status, it's ok if user requested help end |
#execute_install(key = nil, *args) ⇒ Object
41 42 43 |
# File 'lib/pre-commit/cli.rb', line 41 def execute_install(key = nil, *args) PreCommit::Installer.new(key).install end |
#execute_list(*args) ⇒ Object
45 46 47 48 |
# File 'lib/pre-commit/cli.rb', line 45 def execute_list(*args) puts list_evaluator.list true end |
#execute_new(*args) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/pre-commit/cli.rb', line 55 def execute_new(*args) PreCommit::Template.new(*args).save rescue ArgumentError => e warn e warn "Usage: pre-commit new plugin-name 'Author Name' author@email 'description of the plugin'" end |
#execute_plugins(*args) ⇒ Object
50 51 52 53 |
# File 'lib/pre-commit/cli.rb', line 50 def execute_plugins(*args) puts list_evaluator.plugins true end |
#execute_run(*args) ⇒ Object
36 37 38 39 |
# File 'lib/pre-commit/cli.rb', line 36 def execute_run(*args) require 'pre-commit/runner' PreCommit::Runner.new.run(*args).tap { |ok| puts "No failed checks." if ok } end |
#list_evaluator ⇒ Object
78 79 80 |
# File 'lib/pre-commit/cli.rb', line 78 def list_evaluator @list_evaluator ||= PreCommit::ListEvaluator.new(config) end |