provisioners/shell: handle comm output in a uniform way

This commit is contained in:
Mitchell Hashimoto 2014-04-11 21:40:05 -07:00
parent cde5d0bafb
commit 89671974cf
1 changed files with 18 additions and 20 deletions

View File

@ -24,6 +24,22 @@ module VagrantPlugins
protected protected
# This handles outputting the communication data back to the UI
def handle_comm(type, data)
if [:stderr, :stdout].include?(type)
# Output the data with the proper color based on the stream.
color = type == :stdout ? :green : :red
options = {
new_line: false,
prefix: false,
}
options[:color] = color if !config.keep_color
@machine.env.ui.info(data, options)
end
end
# This is the provision method called if SSH is what is running # This is the provision method called if SSH is what is running
# on the remote end, which assumes a POSIX-style host. # on the remote end, which assumes a POSIX-style host.
def provision_ssh(args) def provision_ssh(args)
@ -49,18 +65,7 @@ module VagrantPlugins
# Execute it with sudo # Execute it with sudo
comm.execute(command, sudo: config.privileged) do |type, data| comm.execute(command, sudo: config.privileged) do |type, data|
if [:stderr, :stdout].include?(type) handle_comm(type, data)
# Output the data with the proper color based on the stream.
color = type == :stdout ? :green : :red
options = {
new_line: false,
prefix: false,
}
options[:color] = color if !config.keep_color
@machine.env.ui.info(data, options)
end
end end
end end
end end
@ -97,14 +102,7 @@ module VagrantPlugins
# Execute it with sudo # Execute it with sudo
comm.sudo(command) do |type, data| comm.sudo(command) do |type, data|
if [:stderr, :stdout].include?(type) handle_comm(type, data)
# Output the data with the proper color based on the stream.
color = type == :stdout ? :green : :red
@machine.ui.info(
data,
:color => color, :new_line => false, :prefix => false)
end
end end
end end
end end