lib/octopolo/cli.rb in octopolo-1.5.3 vs lib/octopolo/cli.rb in octopolo-1.6.0
- old
+ new
@@ -110,28 +110,25 @@
Dir.chdir(dir) do
yield
end
end
- def self.ask(question, choices, skip_asking = false)
+ def self.ask(question, choices)
return choices.first if choices.size == 1
-
- unless skip_asking
- say question
- choices.each_with_index do |choice, i|
- say "#{i+1}) #{choice}"
- end
+
+ say question
+ choices.each_with_index do |choice, i|
+ say "#{i+1}) #{choice}"
end
selection = nil
while not choices.include?(selection)
selection = prompt
+ break if choices.include?(selection) # passed in the value of the choice
+ selection_index = selection.to_i - 1 # passed in a 1-based index of the choice
+ selection = choices[selection_index] if selection_index >= 0 # gather the value of the choice
break if choices.include?(selection)
- # if entering a 1-based index value
- selection_index = selection.to_i - 1
- selection = choices[selection_index] if selection_index >= 0
- break if choices.include?(selection)
say "Not a valid choice."
end
selection
end
@@ -141,15 +138,15 @@
# question - The question to display to the user in the prompt
#
# Returns a Boolean
def self.ask_boolean(question)
answer = prompt("#{question} (y/n)")
- # basically accept anything that starts with Y as a yes answer
- answer =~ /^y/i
+ # Return true if the answer starts with "Y" or "y"; else return false
+ !!(answer =~ /^y/i)
end
- def self.prompt prompt_text="> "
+ def self.prompt(prompt_text="> ")
highline.ask prompt_text do |conf|
conf.readline = true
end.to_s
end
@@ -161,11 +158,11 @@
#
# # Accept multiple lines of text, with the prompt "QA Plan:"
# plan = CLI.prompt_multiline "QA Plan:"
#
# Returns a String containing the value the user entered
- def self.prompt_multiline prompt_text
+ def self.prompt_multiline(prompt_text)
highline.ask(prompt_text) do |conf|
# accept text until the first blank line (instead of stopping at the
# first newline), to allow multiple lines of input
conf.gather = ""
conf.readline = true
@@ -175,10 +172,10 @@
# Public: Prompt user for input, but do not display what they type
#
# prompt_text - The text to display before the prompt; e.g., "Password: "
#
# Returns a String containing the value the user entered
- def self.prompt_secret prompt_text
+ def self.prompt_secret(prompt_text)
highline.ask(prompt_text) do |conf|
# do not display the text input
conf.echo = false
conf.readline = true
end