module Onering module CLI class Automation < Plugin def self.configure(global={}) @requests = Onering::CLI.connect(global).automation_requests @jobs = Onering::CLI.connect(global).automation_jobs @tasks = Onering::CLI.connect(global).automation_tasks end def self.run(args) sc = args.shift # subcommand ssc = args.shift # sub-subcommand case (sc.downcase.to_sym rescue nil) # ----------------------------------------------------------------------------- when :requests @opts = ::Trollop::options do banner <<-EOS Options: EOS stop_on %w{show status requeue flush purge} end case (ssc.downcase.to_sym rescue nil) when :show return @requests.show(args[0]) when :requeue return @requests.requeue_all_failed() if args[0].nil? return @requests.requeue(args[0]) when :status fields = (args.empty? ? ["status"] : args) rv = {} out = @requests.summary(fields) _rejigger_hash = Proc.new do |h| [*h].collect{|i| [i['id'], (i['children'].nil? ? i['count'] : Hash[_rejigger_hash.call(i['children'])])] } end return Hash[_rejigger_hash.call(out)] when :flush return @requests.flush_queue() when :purge return @requests.purge() end # ----------------------------------------------------------------------------- when :jobs # ----------------------------------------------------------------------------- when :tasks end end end end end