2014-04-11 01:26:19 +00:00
|
|
|
require "vagrant/util/busy"
|
|
|
|
require "vagrant/util/subprocess"
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module DockerProvider
|
|
|
|
module Executor
|
|
|
|
# The Local executor executes a Docker client that is running
|
|
|
|
# locally.
|
|
|
|
class Local
|
2014-04-29 23:27:22 +00:00
|
|
|
def execute(*cmd, **opts, &block)
|
2014-04-11 01:26:19 +00:00
|
|
|
# Append in the options for subprocess
|
|
|
|
cmd << { :notify => [:stdout, :stderr] }
|
|
|
|
|
|
|
|
interrupted = false
|
|
|
|
int_callback = ->{ interrupted = true }
|
2014-04-30 16:21:42 +00:00
|
|
|
result = ::Vagrant::Util::Busy.busy(int_callback) do
|
|
|
|
::Vagrant::Util::Subprocess.execute(*cmd, &block)
|
2014-04-11 01:26:19 +00:00
|
|
|
end
|
|
|
|
|
2014-04-29 21:16:24 +00:00
|
|
|
result.stderr.gsub!("\r\n", "\n")
|
|
|
|
result.stdout.gsub!("\r\n", "\n")
|
|
|
|
|
2014-04-11 01:26:19 +00:00
|
|
|
if result.exit_code != 0 && !interrupted
|
2014-04-29 21:16:24 +00:00
|
|
|
raise Errors::ExecuteError,
|
|
|
|
command: command.inspect,
|
|
|
|
stderr: result.stderr,
|
|
|
|
stdout: result.stdout
|
2014-04-11 01:26:19 +00:00
|
|
|
end
|
|
|
|
|
2014-04-29 21:16:24 +00:00
|
|
|
result.stdout
|
2014-04-11 01:26:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|