| Method from org.jboss.console.twiddle.Twiddle Detail: |
public void addCommandPrototype(Command proto) {
String name = proto.getName();
log.debug("Adding command '" + name + "'; proto: " + proto);
commandProtoList.add(proto);
commandProtoMap.put(name, proto);
}
|
public Command createCommand(String name) throws Exception, NoSuchCommandException {
//
// jason: need to change this to accept unique substrings on command names
//
Command proto = (Command) commandProtoMap.get(name);
if (proto == null)
{
throw new NoSuchCommandException(name);
}
Command command = (Command) proto.clone();
command.setCommandContext(createCommandContext());
return command;
}
|
public void displayCommandList() {
if( commandProtoList.size() == 0 )
{
try
{
loadCommands();
}
catch(Exception e)
{
System.err.println("Failed to load commnads from: "+cmdProps);
e.printStackTrace();
}
}
Iterator iter = commandProtoList.iterator();
out.println(PROGRAM_NAME + " commands: ");
int maxNameLength = getMaxCommandNameLength();
log.debug("max command name length: " + maxNameLength);
while (iter.hasNext())
{
Command proto = (Command) iter.next();
String name = proto.getName();
String desc = proto.getDescription();
out.print(" ");
out.print(name);
// an even pad, so things line up correctly
out.print(Strings.pad(" ", maxNameLength - name.length()));
out.print(" ");
out.println(desc);
}
out.flush();
}
|
public static void main(String[] args) {
Command command = null;
try
{
// initialize java.protocol.handler.pkgs
initProtocolHandlers();
// Prosess global options
processArguments(args);
loadCommands();
// Now execute the command
if (commandName == null)
{
// Display program help
displayHelp();
}
else
{
command = twiddle.createCommand(commandName);
if (commandHelp)
{
System.out.println("Help for command: '" + command.getName() + "'");
System.out.println();
command.displayHelp();
}
else
{
// Execute the command
command.execute(commandArgs);
}
}
System.exit(0);
}
catch (CommandException e)
{
log.error("Command failure", e);
System.err.println();
if (e instanceof NoSuchCommandException)
{
twiddle.displayCommandList();
}
else
{
if (command != null)
{
System.err.println("Help for command: '" + command.getName() + "'");
System.err.println();
command.displayHelp();
}
}
System.exit(1);
}
catch (Exception e)
{
log.error("Exec failed", e);
System.exit(1);
}
}
|
public void setAdapterName(String name) {
this.adapterName = name;
}
|
public void setQuiet(boolean flag) {
this.quiet = flag;
}
|
public void setServerURL(String url) {
this.serverURL = url;
}
|