From 7da9ad0fa6d2264e601690b2d90ee3e85d5e1fed Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 15 Apr 2014 21:29:12 -0700 Subject: [PATCH] commands/destroy: change exit codes [GH-811] --- CHANGELOG.md | 2 ++ plugins/commands/destroy/command.rb | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6713b07b..48d7aa068 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ FEATURES: IMPROVEMENTS: + - commands/destroy: Exit codes changes. 0 means everything succeeded. + 1 means everything was declined. 2 means some were declined. [GH-811] - commands/ssh-config: Works without a target in multi-machine envs [GH-2844] - guests/freebsd: Support for virtio interfaces. [GH-3082] - guests/openbsd: Support for virtio interfaces. [GH-3082] diff --git a/plugins/commands/destroy/command.rb b/plugins/commands/destroy/command.rb index c141598b4..b8a7cdd5c 100644 --- a/plugins/commands/destroy/command.rb +++ b/plugins/commands/destroy/command.rb @@ -25,17 +25,25 @@ module VagrantPlugins return if !argv @logger.debug("'Destroy' each target VM...") - declined = false + declined = 0 + total = 0 with_target_vms(argv, :reverse => true) do |vm| action_env = vm.action( :destroy, :force_confirm_destroy => options[:force]) - declined = true if action_env.has_key?(:force_confirm_destroy_result) && + total += 1 + declined += 1 if action_env.has_key?(:force_confirm_destroy_result) && action_env[:force_confirm_destroy_result] == false end - # Success if no confirms were declined - declined ? 1 : 0 + # Nothing was declined + return 0 if declined == 0 + + # Everything was declined + return 1 if declined == total + + # Some was declined + return 2 end end end