#!/usr/bin/env ruby require 'fileutils' require 'rubygems' gem 'RequirePaths'; require 'require_paths' require_paths '.','../../..','/Users/gary/repos/Buzzware/projects_2009/yore/lib' gem 'cmdparse'; require 'cmdparse' require 'ihl_ruby/misc_utils' require 'ihl_ruby/xml_utils' require 'ihl_ruby/extend_base_classes' require 'yore/yore_core' CMD_OPTIONS = {} # options given on command line # this contains a block that actually creates the controller, yore def command(aParser,aController,aAction,aShortDescription=nil,aOptionParser=nil,aOther={}) c = CmdParse::Command.new( aAction.to_s, false ) c.short_desc = aShortDescription c.description = aOther[:description] if aOther[:description] c.options = aOptionParser if aOptionParser c.set_execution_block do |args| job = args.first aController.logger.info "Job file: #{File.expand_path(job)}" xmlRoot = XmlUtils.get_file_root(job) aController.configure(xmlRoot,CMD_OPTIONS,{:basepath => File.dirname(File.expand_path(job))}) aController.do_action(aAction,args) end aParser.add_command(c) end cmd = CmdParse::CommandParser.new( true ) cmd.program_name = "yore" cmd.program_version = [0, 0, 1] # Options are given after a command and before arguments on the command line # so global options are given first, before the first command # ie ruby yore.rb --global_option command --command_option argument1 argument2 argumentn cmd.options = CmdParse::OptionParserWrapper.new do |opt| opt.separator "Global options:" opt.on("--verbose", "Be verbose when outputting info") do |t| CMD_OPTIONS[:verbose] = t end end cmd.add_command( CmdParse::HelpCommand.new ) cmd.add_command( CmdParse::VersionCommand.new ) yore = YoreCore::Yore.new # main program object # these options must be given after backup and before arguments option_parser = CmdParse::OptionParserWrapper.new do |opt| opt.on( '--all', 'Delete all IP addresses' ) do CMD_OPTIONS[:deleteAll] = true end end command(cmd,yore,:backup,"Backup filelist to S3",option_parser) command(cmd,yore,:test_email,"Test email sending\n") command(cmd,yore,:db_dump,"Dump database by name in job\n") cmd.parse yore.logger.info "\nComplete.\n" yore.report