#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../lib/amqp_utils/command'

class QueueDeleteCommand < AmqpUtils::Command
  def prepare_options(options)
    options.banner %Q{
    |Deletes the supplied queues.
    |
    |  #{command_name} <queue> [<another queue> ...]
    }.margin
  end

  def validate
    raise "need at least one queue name" unless args[0] && !args[0].empty?
  end

  def execute
    @queues = args
    def @queues.delete_or_stop
      queue = pop
      if queue
        puts "Deleteing #{queue}..."
        MQ.new.queue(queue).delete
        EM.next_tick { delete_or_stop }
      else
        AMQP.stop { EM.stop }
      end
    end

    EM.next_tick { @queues.delete_or_stop }
  end
end

QueueDeleteCommand.run
