Merge pull request #5591 from paperlesspost/extract_shell_cmd

Move shell_cmd to a method in SSH::Communicator
This commit is contained in:
Seth Vargo 2015-05-31 20:57:46 -07:00
commit 2daa9ed175
1 changed files with 16 additions and 9 deletions

View File

@ -434,6 +434,21 @@ module VagrantPlugins
return yield connection if block_given?
end
# The shell wrapper command used in shell_execute defined by
# the sudo and shell options.
def shell_cmd(opts)
sudo = opts[:sudo]
shell = opts[:shell]
# Determine the shell to execute. Prefer the explicitly passed in shell
# over the default configured shell. If we are using `sudo` then we
# need to wrap the shell in a `sudo` call.
cmd = @machine.config.ssh.shell
cmd = shell if shell
cmd = "sudo -E -H #{cmd}" if sudo
cmd
end
# Executes the command on an SSH connection within a login shell.
def shell_execute(connection, command, **opts)
opts = {
@ -442,18 +457,10 @@ module VagrantPlugins
}.merge(opts)
sudo = opts[:sudo]
shell = opts[:shell]
@logger.info("Execute: #{command} (sudo=#{sudo.inspect})")
exit_status = nil
# Determine the shell to execute. Prefer the explicitly passed in shell
# over the default configured shell. If we are using `sudo` then we
# need to wrap the shell in a `sudo` call.
shell_cmd = @machine.config.ssh.shell
shell_cmd = shell if shell
shell_cmd = "sudo -E -H #{shell_cmd}" if sudo
# These variables are used to scrub PTY output if we're in a PTY
pty = false
pty_stdout = ""
@ -472,7 +479,7 @@ module VagrantPlugins
end
end
ch.exec(shell_cmd) do |ch2, _|
ch.exec(shell_cmd(opts)) do |ch2, _|
# Setup the channel callbacks so we can get data and exit status
ch2.on_data do |ch3, data|
# Filter out the clear screen command