core: interrupt in Cli exits with 1

This commit is contained in:
Mitchell Hashimoto 2014-01-13 21:42:40 -08:00
parent 54bb182525
commit 9cf0387e00
4 changed files with 19 additions and 2 deletions

View File

@ -37,7 +37,14 @@ module Vagrant
@logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}") @logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
# Initialize and execute the command class, returning the exit status. # Initialize and execute the command class, returning the exit status.
result = 0
begin
result = command_class.new(@sub_args, @env).execute result = command_class.new(@sub_args, @env).execute
rescue Interrupt
@env.ui.info(I18n.t("vagrant.cli_interrupt"))
result = 1
end
result = 0 if !result.is_a?(Fixnum) result = 0 if !result.is_a?(Fixnum)
return result return result
end end

View File

@ -37,6 +37,8 @@ en:
to automatically delete Chef nodes and clients. to automatically delete Chef nodes and clients.
chef_run_list_empty: |- chef_run_list_empty: |-
Warning: Chef run list is empty. This may not be what you want. Warning: Chef run list is empty. This may not be what you want.
cli_interrupt: |-
Exiting due to interrupt.
docker_auto_start_not_available: |- docker_auto_start_not_available: |-
Unable to configure automatic restart of Docker containers on Unable to configure automatic restart of Docker containers on
the guest machine the guest machine

View File

@ -1,8 +1,9 @@
shared_context "command plugin helpers" do shared_context "command plugin helpers" do
def command_lambda(name, result) def command_lambda(name, result, **opts)
lambda do lambda do
Class.new(Vagrant.plugin("2", "command")) do Class.new(Vagrant.plugin("2", "command")) do
define_method(:execute) do define_method(:execute) do
raise opts[:exception] if opts[:exception]
result result
end end
end end

View File

@ -28,6 +28,13 @@ describe Vagrant::CLI do
subject.should_not_receive(:help) subject.should_not_receive(:help)
expect(subject.execute).to eql(42) expect(subject.execute).to eql(42)
end end
it "returns exit code 1 if interrupted" do
commands[:destroy] = [command_lambda("destroy", 42, exception: Interrupt), {}]
subject = described_class.new(["destroy"], env)
expect(subject.execute).to eql(1)
end
end end
describe "#help" do describe "#help" do