class Object
Public Instance Methods
ask_confirm(question)
click to toggle source
# File lib/snapback.rb, line 116 def ask_confirm question while true print "#{question} [Y/N]: " confirmed = $stdin.gets.chomp.upcase if confirmed.eql? 'Y' then return true elsif confirmed.eql? 'N' then return false else puts "Please enter either Y or N." end end end
ask_int(question, max)
click to toggle source
Ask
# File lib/snapback.rb, line 83 def ask_int question, max number = nil while true print "#{question}: " number = $stdin.gets.chomp if !Integer(number) then puts "The value you entered is not a number." puts "" next end number = number.to_i if number < 1 || number > max then puts "Please enter a number between 1 and #{max}." puts "" next end break end number end
ask_string(question)
click to toggle source
# File lib/snapback.rb, line 111 def ask_string question print "#{question}: " $stdin.gets.chomp end
return_failed()
click to toggle source
# File lib/snapback.rb, line 76 def return_failed return nil if Snapback.quiet? puts "[#{"FAILED".colorize(:red)}]" end
return_no()
click to toggle source
# File lib/snapback.rb, line 71 def return_no return nil if Snapback.quiet? puts "[#{" NO ".colorize(:red)}]" end
return_ok()
click to toggle source
Output status
# File lib/snapback.rb, line 66 def return_ok return nil if Snapback.quiet? puts "[#{" OK ".colorize(:green)}]" end
run_command(description, command = "", &block)
click to toggle source
# File lib/snapback.rb, line 29 def run_command description, command = "", &block if Snapback.verbose? print "#{description}".to_s.ljust(72) STDOUT.flush end begin if block_given? then result = block.call if result then return_ok else return_no end else err = "" status = Open4::popen4(command) do |pid, stdin, stdout, stderr| err = stderr.read end if status != 0 then raise err end return_ok end rescue Exception => e return_failed raise $! # rethrow end return result end