#!/usr/bin/env ruby

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

class QueueStatCommand < AmqpUtils::Command
  def prepare_options(options)
    options.banner %Q{
    |Gets statistics on the queues specified.
    |
    |  #{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

    @queues.each do |queue|
      mq.queue(queue, :passive => true).status do |size, consumers|
        puts "Queue <#{queue}>: #{size} message(s), #{consumers} consumer(s)"

        @queues.delete(queue)
        AMQP.stop { EM.stop } if @queues.empty?
      end
    end
  end
end

QueueStatCommand.run
