01 /*
02 * Licensed to the Apache Software Foundation (ASF) under one
03 * or more contributor license agreements. See the NOTICE file
04 * distributed with this work for additional information
05 * regarding copyright ownership. The ASF licenses this file
06 * to you under the Apache License, Version 2.0 (the
07 * "License"); you may not use this file except in compliance
08 * with the License. You may obtain a copy of the License at
09 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 *
19 *
20 */
21 package org.apache.qpid.tools.messagestore.commands;
22
23 import org.apache.qpid.tools.messagestore.MessageStoreTool;
24 import org.apache.qpid.tools.utils.Console;
25
26 import java.util.LinkedList;
27 import java.util.Map;
28
29 public class Help extends AbstractCommand
30 {
31 public Help(MessageStoreTool tool)
32 {
33 super(tool);
34 }
35
36 public String help()
37 {
38 return "Provides detailed help on commands.";
39 }
40
41 public String getCommand()
42 {
43 return "help";
44 }
45
46 public String usage()
47 {
48 return "help [<command>]";
49 }
50
51 public void execute(String... args)
52 {
53 assert args.length > 0;
54 assert args[0].equals(getCommand());
55
56 if (args.length > 1)
57 {
58 Command command = _tool.getCommands().get(args[1]);
59 if (command != null)
60 {
61 _console.println(command.help());
62 _console.println("Usage:" + command.usage());
63 }
64 else
65 {
66 commandError("Command not found: ", args);
67 }
68 }
69 else
70 {
71 java.util.List<java.util.List> data = new LinkedList<java.util.List>();
72
73 java.util.List<String> commandName = new LinkedList<String>();
74 java.util.List<String> commandDescription = new LinkedList<String>();
75
76 data.add(commandName);
77 data.add(commandDescription);
78
79 //Set up Headers
80 commandName.add("Command");
81 commandDescription.add("Description");
82
83 commandName.add(Console.ROW_DIVIDER);
84 commandDescription.add(Console.ROW_DIVIDER);
85
86 //Add current Commands with descriptions
87 Map<String, Command> commands = _tool.getCommands();
88
89 for (Command command : commands.values())
90 {
91 commandName.add(command.getCommand());
92 commandDescription.add(command.help());
93 }
94
95 _console.printMap("Available Commands", data);
96 }
97 }
98 }
|