Added UI#ask methods (yes?, no?, etc.)

This commit is contained in:
Mitchell Hashimoto 2010-09-07 00:45:21 -07:00
parent 88fedb419e
commit b7d0790a6b
1 changed files with 14 additions and 7 deletions

View File

@ -11,7 +11,7 @@ module Vagrant
@env = env @env = env
end end
[:warn, :error, :info, :confirm, :say_with_vm, :report_progress].each do |method| [:warn, :error, :info, :confirm, :say_with_vm, :report_progress, :ask, :no?, :yes?].each do |method|
# By default these methods don't do anything. A silent UI. # By default these methods don't do anything. A silent UI.
define_method(method) { |*args| } define_method(method) { |*args| }
end end
@ -27,10 +27,14 @@ module Vagrant
[[:warn, :yellow], [:error, :red], [:info, nil], [:confirm, :green]].each do |method, color| [[:warn, :yellow], [:error, :red], [:info, nil], [:confirm, :green]].each do |method, color|
define_method(method) do |message, opts=nil| define_method(method) do |message, opts=nil|
opts = { :_prefix => true, :_translate => true }.merge(opts || {}) @shell.say("#{line_reset}#{format_message(message, opts)}", color)
message = I18n.t(message, opts) if opts[:_translate] end
message = format_message(message) if opts[:_prefix] end
@shell.say("#{line_reset}#{message}", color)
[:ask, :no?, :yes?].each do |method|
define_method(method) do |message, opts=nil|
opts ||= {}
@shell.send(method, format_message(message, opts), opts[:_color])
end end
end end
@ -45,8 +49,11 @@ module Vagrant
protected protected
def format_message(message) def format_message(message, opts=nil)
"[#{env.resource}] #{message}" opts = { :_prefix => true, :_translate => true }.merge(opts || {})
message = I18n.t(message, opts) if opts[:_translate]
message = "[#{env.resource}] #{message}" if opts[:_prefix]
message
end end
def line_reset def line_reset