lib/backup/cli.rb in backup-3.0.13 vs lib/backup/cli.rb in backup-3.0.14
- old
+ new
@@ -4,13 +4,25 @@
module CLI
##
# Wrapper method for %x[] to run CL commands
# through a ruby method. This helps with test coverage and
- # improves readability
+ # improves readability.
+ #
+ # Every time the Backup::CLI#run method is invoked, it'll invoke
+ # the Backup::CLI#raise_if_command_not_found method after running the
+ # requested command on the OS.
+ #
+ # Backup::CLI#raise_if_command_not_found takes a single argument, the utility name.
+ # the command.slice(0, command.index(/\s/)).split('/')[-1] line will extract only the utility
+ # name (e.g. mongodump, pgdump, etc) from a command like "/usr/local/bin/mongodump <options>"
+ # and pass that in to the Backup::CLI#raise_if_command_not_found
def run(command)
%x[#{command}]
+ raise_if_command_not_found!(
+ command.slice(0, command.index(/\s/)).split('/')[-1]
+ )
end
##
# Wrapper method for FileUtils.mkdir_p to create directories
# through a ruby method. This helps with test coverage and
@@ -42,9 +54,22 @@
if path = %x[which #{name}].chomp and not path.empty?
return path
end
name
+ end
+
+ ##
+ # If the command that was previously run via this Ruby process returned
+ # error code "32512", the invoked utility (e.g. mysqldump, pgdump, etc) could not be found.
+ # If this is the case then this method will throw an exception, informing the user of this problem.
+ #
+ # Since this raises an exception, it'll stop the entire backup process, clean up the temp files
+ # and notify the user via the built-in notifiers if these are set.
+ def raise_if_command_not_found!(utility)
+ if $?.to_i.eql?(32512)
+ raise Exception::CommandNotFound , "Could not find the utility \"#{utility}\" on \"#{RUBY_PLATFORM}\"."
+ end
end
end
end