1 16 package org.jmanage.cmdui.commands; 17 18 import org.jmanage.cmdui.*; 19 import org.jmanage.cmdui.util.Out; 20 import org.jmanage.cmdui.util.Table; 21 22 import java.util.Collection ; 23 import java.util.Iterator ; 24 25 30 public class HelpHandler implements CommandHandler { 31 32 37 public boolean execute(HandlerContext context) { 38 39 try { 40 return execute0(context); 41 } catch (InvalidCommandException e) { 42 43 throw new RuntimeException (e); 44 } 45 } 46 47 private boolean execute0(HandlerContext context) 48 throws InvalidCommandException { 49 50 String [] args = context.getCommand().getArgs(); 51 if(args.length == 1){ 52 53 CommandHandler handler = null; 54 try { 55 handler = CommandHandlerFactory.getHandler(args[0]); 56 handler.help(); 57 return true; 58 } catch (InvalidCommandException e) { 59 Out.println(e.getMessage()); 60 Out.println(); 61 } 62 } 63 64 65 Out.println("jmanage [-username <username>] [-password <password>] " + 66 "[-verbose[=<level>]] [command] [command args]"); 67 68 Out.println(); 69 Out.println("Commands:"); 70 Table table = new Table(2); 71 Collection commandNames = CommandHandlerFactory.getCommandNames(); 72 for(Iterator it=commandNames.iterator(); it.hasNext();){ 73 String commandName = (String )it.next(); 74 CommandHandler handler = 75 CommandHandlerFactory.getHandler(commandName); 76 table.add(commandName, handler.getShortHelp()); 77 } 78 table.print(); 79 Out.println(); 80 Out.println("Type \"help <command>\" for detailed command help."); 81 return true; 82 } 83 84 public String getShortHelp(){ 85 return "Prints jManage command line help"; 86 } 87 88 public void help() { 89 Out.println(getShortHelp()); 90 } 91 } 92 | Popular Tags |