Sha256: 838d53fed09cc65f25e70705ef30c1ed7a640c8279e52a1a52d88a230037db2c
Contents?: true
Size: 791 Bytes
Versions: 2
Compression:
Stored size: 791 Bytes
Contents
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
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
terraform-exporter-0.0.4 | lib/terraformer/user_input.rb |
terraform-exporter-0.0.3 | lib/terraformer/user_input.rb |