Skip to content

Instantly share code, notes, and snippets.

@topfunky
Created September 11, 2008 18:21
Show Gist options
  • Save topfunky/10282 to your computer and use it in GitHub Desktop.
Save topfunky/10282 to your computer and use it in GitHub Desktop.
#!/bin/env ruby -w
require 'optparse'
require File.dirname(__FILE__) + "/../lib/couchrest"
# Set defaults
options = {
:verbose => false,
:design_name => "_design",
}
opts = OptionParser.new do |opts|
opts.banner = "Usage: #$0 [options] (push|generate) directory database"
opts.on('-v', '--verbose', "Print extra debug info") do
options[:verbose] = true
end
opts.on('-d', '--design-name [name]', "Use an alternate name. Defaults to #{options[:design_name]}") do |design_name|
options[:design_name] = design_name
end
opts.on_tail('-h', '--help', "Display this help and exit") do
puts opts
exit
end
end
opts.parse!(ARGV)
options[:command] = ARGV.shift
options[:directory] = ARGV.shift
options[:database] = ARGV.shift
# There must be a better way to check for extra required args
unless (["push", "generate"].include?(options[:command]) && options[:directory] && options[:database])
puts(opts)
exit
end
# DEBUG
puts options.inspect
# The options hash now contains the resolved defaults
# and the overrides from the command line.
# Call your class and send it the options here
# cr = CouchRest::FileManager.new(options[:database_name])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment