couchrest_model/bin/couchview

54 lines
1.3 KiB
Ruby
Executable file

#!/usr/bin/env ruby
require 'optparse'
require File.dirname(__FILE__) + "/../lib/couch_rest/commands"
# 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
# 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])
case options[:command]
when "push"
CouchRest::Commands::Push.run(options)
when "generate"
CouchRest::Commands::Generate.run(options)
end