Permalink
Browse files

retry global option

  • Loading branch information...
1 parent c3cdbbd commit 11eb77b3483917b68244929886e786ee1e6f6e4e Kyle Maxwell committed Aug 25, 2010
Showing with 18 additions and 2 deletions.
  1. +18 −2 lib/gizzmo.rb
View
@@ -83,7 +83,7 @@ def separators(opts, string)
'rebalance' => OptionParser.new do |opts|
opts.banner = "Usage: #{zero} rebalance"
separators(opts, DOC_STRINGS["rebalance"])
-
+
opts.on("-h", "--hosts=list") do |h|
subcommand_options.hosts = h
end
@@ -230,6 +230,10 @@ def separators(opts, string)
global_options.port = port
end
+ opts.on("-r", "--retry=TIMES", "TIMES to retry the command") do |r|
+ global_options.retry = r
+ end
+
opts.on("--subtree", "Render in subtree mode") do
global_options.render << "subtree"
end
@@ -303,8 +307,20 @@ def process_nested_parsers(global, subcommands)
argv << line.strip
end
+tries_left = global_options.retry.to_i + 1
begin
- Gizzard::Command.run(subcommand_name, global_options, argv, subcommand_options, log)
+ while (tries_left -= 1) >= 0
+ begin
+ Gizzard::Command.run(subcommand_name, global_options, argv, subcommand_options, log)
+ break
+ rescue
+ if tries_left > 0
+ STDERR.puts "Retrying..."
+ else
+ raise
+ end
+ end
+ end
rescue HelpNeededError => e
if e.class.name != e.message
STDERR.puts("=" * 80)

0 comments on commit 11eb77b

Please sign in to comment.