Permalink
Browse files

modify maybe() method to accept a default and

continue if not overridden within 10s timeout.
  • Loading branch information...
1 parent 090702f commit 8b4af051833addd84f4282bcedbdffa814d8e033 @fairchild fairchild committed Sep 5, 2011
Showing with 12 additions and 5 deletions.
  1. +11 −4 lib/cloud_providers/cloud_provider.rb
  2. +1 −1 lib/poolparty.rb
@@ -61,10 +61,17 @@ def cloud
init_opts.has_key?(:cloud) ? init_opts[:cloud] : nil
end
- def maybe action_description, &block
- puts "About to #{action_description}. Type 'Y' to do this, 'N' to skip"
- line = $stdin.readline
- if line =~ /^Y/
+ def maybe(action_description, default='Y', &block)
+ puts "About to #{action_description}. Type 'Y' to do this, 'N' to skip. #{default} will be chosen within 10 seconds."
+ begin
+ Timeout::timeout(10) do
+ line = $stdin.readline
+ end
+ rescue Timeout::Error => e
+ line = default
+ puts "Timeout: #{default} default will be used."
+ end
+ if line =~ /^Y/i
block.call
else
puts "Skipping."
View
@@ -5,7 +5,7 @@
require 'yaml'
# Load system gems
-%w(rubygems logger erb open-uri fileutils).each do |lib|
+%w(rubygems logger erb open-uri fileutils timeout).each do |lib|
require lib
end

0 comments on commit 8b4af05

Please sign in to comment.