lib/overcommit/cli.rb in overcommit-jeygeethanmedia-0.53.1.2 vs lib/overcommit/cli.rb in overcommit-jeygeethanmedia-0.58.0
- old
+ new
@@ -4,11 +4,11 @@
require 'optparse'
module Overcommit
# Responsible for parsing command-line options and executing appropriate
# application logic based on those options.
- class CLI # rubocop:disable ClassLength
+ class CLI # rubocop:disable Metrics/ClassLength
def initialize(arguments, input, logger)
@arguments = arguments
@input = input
@log = logger
@options = {}
@@ -27,15 +27,15 @@
when :sign
sign
when :run_all
run_all
end
- rescue Overcommit::Exceptions::ConfigurationSignatureChanged => ex
- puts ex
+ rescue Overcommit::Exceptions::ConfigurationSignatureChanged => e
+ puts e
exit 78 # EX_CONFIG
- rescue Overcommit::Exceptions::HookContextLoadError => ex
- puts ex
+ rescue Overcommit::Exceptions::HookContextLoadError => e
+ puts e
exit 64 # EX_USAGE
end
private
@@ -50,12 +50,12 @@
# Default action is to install
@options[:action] ||= :install
# Unconsumed arguments are our targets
@options[:targets] = @arguments
- rescue OptionParser::InvalidOption => ex
- print_help @parser.help, ex
+ rescue OptionParser::InvalidOption => e
+ print_help @parser.help, e
end
end
def create_option_parser
OptionParser.new do |opts|
@@ -92,12 +92,13 @@
opts.on('-f', '--force', 'Overwrite any previously installed hooks') do
@options[:force] = true
end
- opts.on('-r', '--run', 'Run pre-commit hook against all git tracked files') do
+ opts.on('-r [hook]', '--run [hook]', 'Run specified hook against all git tracked files. Defaults to `pre_commit`.') do |arg| # rubocop:disable Layout/LineLength
@options[:action] = :run_all
+ @options[:hook_to_run] = arg ? arg.to_s : 'run-all'
end
end
def add_other_options(opts)
opts.on('-s', '--sign [hook]', 'Update hook signatures', String) do |hook_to_sign|
@@ -123,15 +124,15 @@
end
@options[:targets].each do |target|
begin
Installer.new(log).run(target, @options)
- rescue Overcommit::Exceptions::InvalidGitRepo => error
- log.warning "Invalid repo #{target}: #{error}"
+ rescue Overcommit::Exceptions::InvalidGitRepo => e
+ log.warning "Invalid repo #{target}: #{e}"
halt 69 # EX_UNAVAILABLE
- rescue Overcommit::Exceptions::PreExistingHooks => error
- log.warning "Unable to install into #{target}: #{error}"
+ rescue Overcommit::Exceptions::PreExistingHooks => e
+ log.warning "Unable to install into #{target}: #{e}"
halt 73 # EX_CANTCREAT
end
end
end
@@ -197,10 +198,10 @@
halt
end
def run_all
empty_stdin = File.open(File::NULL) # pre-commit hooks don't take input
- context = Overcommit::HookContext.create('run-all', config, @arguments, empty_stdin)
+ context = Overcommit::HookContext.create(@options[:hook_to_run], config, @arguments, empty_stdin) # rubocop:disable Layout/LineLength
config.apply_environment!(context, ENV)
printer = Overcommit::Printer.new(config, log, context)
runner = Overcommit::HookRunner.new(config, log, context, printer)