module Terraformer class UserInputError < RuntimeError end class UserInputMaxAttemptsError < RuntimeError end class UserInput MAX_ATTEMPTS = 10 class << self def get_input(message, success, failure) Thor::Shell::Basic.new.ask("#{message} [#{success}/#{failure}]") end def ask(message, success, failure) (0..MAX_ATTEMPTS).each do |i| response = get_input(message, success, failure).chomp if response.downcase == success.downcase || response == "" return true elsif response.downcase == failure.downcase puts "Exiting" raise UserInputError end end raise UserInputMaxAttemptsError, "Reached max number of attempts." end end end end