lib/pre-commit/checks/shell.rb in pre-commit-0.19.0 vs lib/pre-commit/checks/shell.rb in pre-commit-0.20.0
- old
+ new
@@ -1,16 +1,29 @@
require 'pre-commit/checks/plugin'
-require 'open3'
+require 'shellwords'
module PreCommit
module Checks
class Shell < Plugin
private
- def execute(command)
- _, stdout, stderr, process = Open3.popen3(command)
- stdout.read + stderr.read unless process.value.success?
+ def execute(*args)
+ options = args.last.is_a?(::Hash) ? args.pop : {}
+ args = build_command(*args)
+ execute_raw(args, options)
+ end
+
+ def build_command(*args)
+ args.flatten.map do |arg|
+ arg = arg.shellescape if arg != '|' && arg != '&&' && arg != '||'
+ arg
+ end.join(" ")
+ end
+
+ def execute_raw(command, options = {})
+ result = `#{command} 2>&1`
+ $?.success? == (options.fetch(:success_status, true)) ? nil : result
end
end
end
end