UI errors if a TTY is required and not given

This commit is contained in:
Mitchell Hashimoto 2012-03-07 22:32:44 -08:00
parent 700938b668
commit 95b3e9f82f
3 changed files with 14 additions and 1 deletions

View File

@ -323,6 +323,11 @@ module Vagrant
error_key(:ssh_unavailable_windows)
end
class UIExpectsTTY < VagrantError
status_code(73)
error_key(:ui_expects_tty)
end
class VagrantInterrupt < VagrantError
status_code(40)
error_key(:interrupted)

View File

@ -51,6 +51,9 @@ module Vagrant
def ask(message, opts=nil)
super(message)
# We can't ask questions when the output isn't a TTY.
raise Errors::UIExpectsTTY if !$stdin.tty?
# Setup the options so that the new line is suppressed
opts ||= {}
opts[:new_line] = false if !opts.has_key?(:new_line)
@ -60,7 +63,7 @@ module Vagrant
say(:info, message, opts)
# Get the results and chomp off the newline
STDIN.gets.chomp
$stdin.gets.chomp
end
# This is used to output progress reports to the UI.

View File

@ -141,6 +141,11 @@ en:
Port: %{port}
Username: %{username}
Private key: %{key_path}
ui_expects_tty: |-
Vagrant is attempting to interface with the UI in a way that requires
a TTY. Most actions in Vagrant that require a TTY have configuration
switches to disable this requirement. Please do that or run Vagrant
with TTY.
vagrantfile_exists: |-
`Vagrantfile` already exists in this directory. Remove it before
running `vagrant init`.