Show nice error if vagrant destroy can't confirm [GH-779]

This commit is contained in:
Mitchell Hashimoto 2012-03-07 22:35:40 -08:00
parent 95b3e9f82f
commit 3046845215
4 changed files with 20 additions and 2 deletions

View File

@ -2,6 +2,8 @@
- Add missing `rubygems` require in `environment.rb` to avoid
possible load errors. [GH-781]
- `vagrant destroy` shows a nice error when called without a
TTY (and hence can't confirm). [GH-779]
## 1.0.0 (March 6, 2012)

View File

@ -30,8 +30,15 @@ module Vagrant
if options[:force]
do_destroy = true
else
choice = @env.ui.ask(I18n.t("vagrant.commands.destroy.confirmation",
:name => vm.name))
choice = nil
begin
choice = @env.ui.ask(I18n.t("vagrant.commands.destroy.confirmation",
:name => vm.name))
rescue Errors::UIExpectsTTY
# We raise a more specific error but one which basically
# means the same thing.
raise Errors::DestroyRequiresForce
end
do_destroy = choice.upcase == "Y"
end

View File

@ -148,6 +148,11 @@ module Vagrant
error_key(:deprecation)
end
class DestroyRequiresForce < VagrantError
status_code(74)
error_key(:destroy_requires_force)
end
class DotfileIsDirectory < VagrantError
status_code(46)
error_key(:dotfile_is_directory)

View File

@ -36,6 +36,10 @@ en:
%{message}
Note that this error message will not appear in the next version of Vagrant.
destroy_requires_force: |-
Destroy doesn't have a TTY to ask for confirmation. Please pass the
`--force` flag to force a destroy, otherwise attach a TTY so that
the destroy can be confirmed.
dotfile_is_directory: |-
The local file Vagrant uses to store data ".vagrant" already exists
and is a directory! If you are in your home directory, then please run