(#9137) Exit 0 if vagrant destroy finds no running vms

This commit reverts the behavior of `vagrant destroy` to exit 0 if no
running vms were found when the destroy command is run.
This commit is contained in:
Brian Cain 2017-12-07 11:02:43 -08:00
parent f03f8baa8d
commit d4d4ed6473
2 changed files with 12 additions and 0 deletions

View File

@ -60,6 +60,10 @@ module VagrantPlugins
# Nothing was declined # Nothing was declined
return 0 if declined == 0 return 0 if declined == 0
# Everything was declined, and all states are `not_created`
return 0 if declined == machines.length &&
declined == init_states.values.count(:not_created)
# Everything was declined, state was not changed # Everything was declined, state was not changed
return 1 if declined == machines.length return 1 if declined == machines.length

View File

@ -51,6 +51,14 @@ describe VagrantPlugins::CommandDestroy::Command do
expect(subject.execute).to eq(0) expect(subject.execute).to eq(0)
end end
it "exits 0 if vms are not created" do
allow_any_instance_of(Vagrant::BatchAction).to receive(:action) .with(machine, :destroy, anything)
allow(machine.state).to receive(:id).and_return(:not_created)
expect(machine.state).to receive(:id).and_return(:not_created)
expect(subject.execute).to eq(0)
end
it "exits 1 if a vms destroy was declined" do it "exits 1 if a vms destroy was declined" do
allow_any_instance_of(Vagrant::BatchAction).to receive(:action) .with(machine, :destroy, anything) allow_any_instance_of(Vagrant::BatchAction).to receive(:action) .with(machine, :destroy, anything)