From 95b3e9f82f210d80cf73c8583b4686a25f64a804 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 7 Mar 2012 22:32:44 -0800 Subject: [PATCH] UI errors if a TTY is required and not given --- lib/vagrant/errors.rb | 5 +++++ lib/vagrant/ui.rb | 5 ++++- templates/locales/en.yml | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 1f4a8d8af..7bf99d63e 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -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) diff --git a/lib/vagrant/ui.rb b/lib/vagrant/ui.rb index d026b8725..a9c9a67e9 100644 --- a/lib/vagrant/ui.rb +++ b/lib/vagrant/ui.rb @@ -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. diff --git a/templates/locales/en.yml b/templates/locales/en.yml index ba26c633e..acdfd676f 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -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`.