lib/kapost/bootstrapper.rb in kapost-bootstrapper-0.5.0 vs lib/kapost/bootstrapper.rb in kapost-bootstrapper-0.5.1
- old
+ new
@@ -51,11 +51,15 @@
instance_eval(&block) if block_given?
end
def default_check(command, version)
- installed?(command) and (!version or right_version?(command, version))
+ installed?(command) or raise CommandNotFoundError, command
+ if version
+ actual_version = right_version?(command, version) or raise CommandVersionMismatchError, command, version, actual_version
+ end
+ true
end
def check(command, help = nil, version: nil)
say(label(command, version)) do
begin
@@ -80,20 +84,16 @@
end
end
def installed?(command)
_, status = cli.capture2e "bash -c 'type #{command}'"
- raise CommandNotFoundError, command unless status.success?
- true
+ status.success?
end
def right_version?(command, expected_version)
version, status = cli.capture2e "#{command} --version"
- unless status.success? && version.include?(expected_version)
- raise CommandVersionMismatchError, command, expected_version, version
- end
- true
+ status.success? && version.include?(expected_version) && version
end
def say(message)
if block_given?
# If we're given a block print a label with a success indicator
@@ -108,10 +108,10 @@
end
def sh(*cmd)
options = (Hash === cmd.last) ? cmd.pop : {}
say(cmd.join(" ")) if options[:verbose]
- result = cli.system(*cmd)
+ result = shell.system(*cmd)
status = $?
raise CommandFailedError.new(cmd.join(" "), status.exitstatus) unless result
result
end