Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

modify maybe() method to accept a default and

continue if not overridden within 10s timeout.
  • Loading branch information...
commit 8b4af051833addd84f4282bcedbdffa814d8e033 1 parent 090702f
@fairchild fairchild authored
Showing with 12 additions and 5 deletions.
  1. +11 −4 lib/cloud_providers/cloud_provider.rb
  2. +1 −1  lib/poolparty.rb
View
15 lib/cloud_providers/cloud_provider.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
2  lib/poolparty.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.