mirror of
https://github.com/donl/homebrew-cask-versions.git
synced 2026-07-17 14:26:45 -06:00
- add `run!` method which raises if command does not succeed - use `run!` when the command we are running must succeed for things to move forward. this should help produce clearer error messages in failure scenarios. - move caveats earlier in the install process so reports can be made about potential failures - remove the destination tree on cask install failure, so the cask will not be considered installed
52 lines
1.2 KiB
Ruby
52 lines
1.2 KiB
Ruby
class Cask::SystemCommand
|
|
def self.run(command, options={})
|
|
command = _process_options(command, options)
|
|
output = ''
|
|
IO.popen(command, 'r+') do |pipe|
|
|
if options[:input]
|
|
options[:input].each { |line| pipe.puts line }
|
|
end
|
|
pipe.close_write
|
|
while line = pipe.gets
|
|
output << line
|
|
ohai line.chomp if options[:print]
|
|
end
|
|
end
|
|
_assert_success($?, command, output) if options[:must_succeed]
|
|
if options[:plist]
|
|
Plist::parse_xml(output)
|
|
else
|
|
output
|
|
end
|
|
end
|
|
|
|
def self.run!(command, options)
|
|
run(command, options.merge(:must_succeed => true))
|
|
end
|
|
|
|
def self._process_options(command, options)
|
|
if options[:sudo]
|
|
command = "sudo -E #{_quote(command)}"
|
|
end
|
|
if options[:args]
|
|
command = "#{command} #{options[:args].map { |arg| _quote(arg) }.join(' ')}"
|
|
end
|
|
case options[:stderr]
|
|
when :silence then
|
|
command = "#{command} 2>/dev/null"
|
|
when :merge, nil then
|
|
command = "#{command} 2>&1"
|
|
end
|
|
command
|
|
end
|
|
|
|
def self._assert_success(status, command, output)
|
|
unless status.success?
|
|
raise CaskCommandFailedError.new(command, output)
|
|
end
|
|
end
|
|
|
|
def self._quote(string)
|
|
%Q('#{string}')
|
|
end
|
|
end
|