#!/usr/bin/env ruby require 'optparse' %w(generate push).each do |file| require File.dirname(__FILE__) + "/../lib/couchrest/commands/#{file}" end # Set defaults options = { :loud => true, } opts = OptionParser.new do |opts| opts.banner = "Usage: #$0 [options] (push|generate) directory database" opts.on('-q', '--quiet', "Omit extra debug info") do options[:loud] = false end opts.on_tail('-h', '--help [push|generate]', "Display detailed help and exit") do |help_command| puts opts case help_command when "push" puts CouchRest::Commands::Push.help when "generate" puts CouchRest::Commands::Generate.help end exit end end opts.parse!(ARGV) options[:command] = ARGV.shift options[:directory] = ARGV.shift options[:trailing_args] = ARGV # There must be a better way to check for extra required args unless (["push", "generate"].include?(options[:command]) && options[:directory] && options[:trailing_args]) puts(opts) exit end case options[:command] when "push" CouchRest::Commands::Push.run(options) when "generate" CouchRest::Commands::Generate.run(options) end