Easy operations `run` and `sudo` now echo stdout/stderr
This commit is contained in:
parent
f133f39bcc
commit
ca6d49bc94
|
@ -1,6 +1,8 @@
|
|||
require "delegate"
|
||||
require "optparse"
|
||||
|
||||
require "log4r"
|
||||
|
||||
require "vagrant/easy/operations"
|
||||
|
||||
module Vagrant
|
||||
|
@ -13,8 +15,9 @@ module Vagrant
|
|||
def initialize(vm, argv)
|
||||
super(Operations.new(vm))
|
||||
|
||||
@argv = argv
|
||||
@vm = vm
|
||||
@logger = Log4r::Logger.new("vagrant::easy::command_api")
|
||||
@argv = argv
|
||||
@vm = vm
|
||||
end
|
||||
|
||||
# Gets the value of an argument from the command line. Many arguments
|
||||
|
@ -22,6 +25,8 @@ module Vagrant
|
|||
#
|
||||
# @return [String]
|
||||
def arg(*names)
|
||||
@logger.info("reading args: #{names.inspect}")
|
||||
|
||||
# Mangle the names a bit to add "=VALUE" to every flag.
|
||||
names = names.map do |name|
|
||||
"#{name}=VALUE"
|
||||
|
|
|
@ -58,18 +58,22 @@ module Vagrant
|
|||
# puts "Output was #{output.stdout}"
|
||||
#
|
||||
# @param [String] command Command to run
|
||||
def run(command)
|
||||
# @param [Hash] options Additional options
|
||||
def run(command, options=nil)
|
||||
@logger.info("run: #{command}")
|
||||
remote_command(:execute, command)
|
||||
options = { :echo => true }.merge(options || {})
|
||||
remote_command(:execute, command, options)
|
||||
end
|
||||
|
||||
# Same as {run} except runs the command with superuser privileges
|
||||
# via `sudo`.
|
||||
#
|
||||
# @param [String] command Command
|
||||
def sudo(command)
|
||||
# @param [Hash] options Additional options
|
||||
def sudo(command, options=nil)
|
||||
@logger.info("sudo: #{command}")
|
||||
remote_command(:sudo, command)
|
||||
options = { :echo => true }.merge(options || {})
|
||||
remote_command(:sudo, command, options)
|
||||
end
|
||||
|
||||
# Uploads a file to the virtual machine.
|
||||
|
@ -105,7 +109,7 @@ module Vagrant
|
|||
protected
|
||||
|
||||
# Runs a command on the remote host.
|
||||
def remote_command(type, command)
|
||||
def remote_command(type, command, options)
|
||||
# If the VM is not running, then we can't run SSH commands...
|
||||
raise Errors::VMNotRunningError if @vm.state != :running
|
||||
|
||||
|
@ -120,6 +124,13 @@ module Vagrant
|
|||
elsif type == :stderr
|
||||
result.stderr += data
|
||||
end
|
||||
|
||||
# If we're echoing data, then echo it!
|
||||
if options[:echo]
|
||||
@vm.ui.info(data.to_s,
|
||||
:prefix => false,
|
||||
:new_line => false)
|
||||
end
|
||||
end
|
||||
|
||||
# Return the result
|
||||
|
|
Loading…
Reference in New Issue