2016-09-16 10:32:53 +08:00
|
|
|
require 'open3'
|
|
|
|
|
2016-07-22 10:45:39 +08:00
|
|
|
module BackupRestore
|
|
|
|
module Utils
|
2016-09-16 10:32:53 +08:00
|
|
|
def execute_command(*command, failure_message: "")
|
|
|
|
stdout, stderr, status = Open3.capture3(*command)
|
2016-07-22 10:45:39 +08:00
|
|
|
|
2016-09-16 10:32:53 +08:00
|
|
|
if !status.success?
|
2016-07-22 10:45:39 +08:00
|
|
|
failure_message = "#{failure_message}\n" if !failure_message.blank?
|
2016-09-16 10:32:53 +08:00
|
|
|
raise "#{failure_message}#{stderr}"
|
2016-07-22 10:45:39 +08:00
|
|
|
end
|
|
|
|
|
2016-09-16 10:32:53 +08:00
|
|
|
stdout
|
2016-07-22 10:45:39 +08:00
|
|
|
end
|
2016-08-03 16:18:35 +08:00
|
|
|
|
|
|
|
def pretty_logs(logs)
|
|
|
|
logs.join("\n")
|
|
|
|
end
|
2016-07-22 10:45:39 +08:00
|
|
|
end
|
|
|
|
end
|