lib/cliprompt.rb in cliprompt-0.0.2 vs lib/cliprompt.rb in cliprompt-0.0.3

- old
+ new

@@ -6,11 +6,11 @@ module Cliprompt module_function MSG_MANDATORY_TEXT = "Sorry you need to fill that information." - MSG_YES_OR_NO = "You need to answer by yes, no, y or n." + MSG_YES_OR_NO = "You need to answer by yes, no, y, n, 1 or 0." MSG_CHOSE_IN_LIST = "You need to chose between the available options." def ask(question, *options) if options[0].class == Optionset opts = options[0] @@ -19,9 +19,18 @@ end output.print "#{question} #{opts.display} " answer = input.gets.chomp output.flush opts.validate(question, answer) + end + + def guess(env, question, *options) + opts = Optionset.new *options + if ENV[env] + opts.validate(question, ENV[env]) + else + ask question, opts + end end def say(message) output.puts message end