/**
 * Copyright (C) 2010-2013 Alibaba Group Holding Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.alibaba.rocketmq.tools.command.consumer;

import com.alibaba.rocketmq.common.protocol.body.SubscriptionGroupWrapper;
import com.alibaba.rocketmq.common.subscription.SubscriptionGroupConfig;
import com.alibaba.rocketmq.remoting.RPCHook;
import com.alibaba.rocketmq.srvutil.ServerUtil;
import com.alibaba.rocketmq.tools.admin.DefaultMQAdminExt;
import com.alibaba.rocketmq.tools.command.SubCommand;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;

import java.util.Map;


/**
 * List subscription groups of a broker.
 */
public class ListSubGroupSubCommand implements SubCommand {

    @Override
    public String commandName() {
        return "listSubGroup";
    }


    @Override
    public String commandDesc() {
        return "List subscription groups";
    }


    @Override
    public Options buildCommandlineOptions(Options options) {
        Option opt = new Option("b", "brokerAddress", true, "list subscription groups of which broker");
        opt.setRequired(true);
        options.addOption(opt);
        return options;
    }


    @Override
    public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) {
        final DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);

        defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));

        try {

            if (commandLine.hasOption('b')) {
                String addr = commandLine.getOptionValue('b').trim();

                defaultMQAdminExt.start();
                SubscriptionGroupWrapper subscriptionGroupWrapper = defaultMQAdminExt.fetchAllSubscriptionGroups(addr, 3000);
                for (Map.Entry<String, SubscriptionGroupConfig> entry :
                        subscriptionGroupWrapper.getSubscriptionGroupTable().entrySet()) {
                    System.out.println(entry.getValue());
                }
                return;
            } else {
                System.err.println("Fatal error! Required broker address is absent!");
            }
            ServerUtil.printCommandLineHelp("mqadmin " + this.commandName(), options);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            defaultMQAdminExt.shutdown();
        }
    }
}

@@ -2346,208 +2346,852 @@
     
-for (Map.Entry%3CString, SubscriptionGroupConfig%3E entry :%0A                        subscriptionGroupWrapper.getSubscriptionGroupTable().entrySet()) %7B%0A                    System.out.println(entry.getValue
+String format = %22%25-16s  %25-6s  %25-6s  %25-6s %25-6s%22;%0A                System.out.printf(format, %22Consumer Group%22, %22Consume Enabled%22, %22Broadcast%22, %22Consume From Min%22, %22Which Broker When Consume Slow%22);%0A                for (Map.Entry%3CString, SubscriptionGroupConfig%3E entry :%0A                        subscriptionGroupWrapper.getSubscriptionGroupTable().entrySet()) %7B%0A                    SubscriptionGroupConfig subscriptionGroupConfig = entry.getValue();%0A                    System.out.printf(format, subscriptionGroupConfig.getGroupName(),%0A                            subscriptionGroupConfig.isConsumeEnable(),%0A                            subscriptionGroupConfig.isConsumeBroadcastEnable(),%0A                            subscriptionGroupConfig.isConsumeFromMinEnable(),%0A                            subscriptionGroupConfig.getWhichBrokerWhenConsumeSlowly
 ());

Format output