`vagrant ssh -c` will now exit with the same exit status of the command [GH-598]

This commit is contained in:
Mitchell Hashimoto 2011-12-26 09:58:10 -08:00
parent 72b249fd19
commit e07280593d
3 changed files with 16 additions and 2 deletions

View File

@ -24,6 +24,8 @@
- "--no-provision" once again works for certain commands. [GH-591] - "--no-provision" once again works for certain commands. [GH-591]
- Resuming a VM from a saved state will show an error message if there - Resuming a VM from a saved state will show an error message if there
would be port collisions. [GH-602] would be port collisions. [GH-602]
- `vagrant ssh -c` will now exit with the same exit code as the command
run. [GH-598]
## 0.8.10 (December 10, 2011) ## 0.8.10 (December 10, 2011)

View File

@ -40,16 +40,23 @@ module Vagrant
protected protected
def ssh_execute(vm, command=nil) def ssh_execute(vm, command=nil)
exit_status = 0
@logger.debug("Executing command: #{command}") @logger.debug("Executing command: #{command}")
vm.ssh.execute do |ssh| vm.ssh.execute do |ssh|
ssh.exec!(command) do |channel, type, data| ssh.exec!(command) do |channel, type, data|
if type != :exit_status if type == :exit_status
exit_status = data.to_i
else
# Print the SSH output as it comes in, but don't prefix it and don't # Print the SSH output as it comes in, but don't prefix it and don't
# force a new line so that the output is properly preserved # force a new line so that the output is properly preserved
vm.ui.info(data.to_s, :prefix => false, :new_line => false) vm.ui.info(data.to_s, :prefix => false, :new_line => false)
end end
end end
end end
# Exit with the exit status we got from executing the command
exit exit_status
end end
def ssh_connect(vm) def ssh_connect(vm)

View File

@ -32,8 +32,13 @@ describe "vagrant ssh" do
assert_execute("vagrant", "init") assert_execute("vagrant", "init")
assert_execute("vagrant", "up") assert_execute("vagrant", "up")
result = assert_execute("vagrant", "ssh", "-c", "echo foo") result = execute("vagrant", "ssh", "-c", "echo foo")
result.exit_code.should == 0
result.stdout.should == "foo\n" result.stdout.should == "foo\n"
result = execute("vagrant", "ssh", "-c", "foooooooooo")
result.exit_code.should == 127
#result.stderr.should =~ /foooooooooo: command not found/
end end
# TODO: # TODO: