com.notuvy.cmd
Class CommandSet

java.lang.Object
  extended by com.notuvy.cmd.CommandAction
      extended by com.notuvy.cmd.CommandSet
Direct Known Subclasses:
CommandSubSet

public class CommandSet
extends CommandAction

A command line argument interpreter. User: murali Date: Jan 2, 2008 Time: 2:04:45 PM


Field Summary
static String CMD_HELP
           
static String CMD_VERSION
           
 
Fields inherited from class com.notuvy.cmd.CommandAction
LOG
 
Constructor Summary
  CommandSet()
           
protected CommandSet(String pKey)
           
 
Method Summary
 CommandSet define(CommandAction pAction)
          Add the given command to this set.
 CommandSet defineSynonym(String pSynonym, String pKey)
          Define a command as a synonym for an existing command.
 void defineVersionFrom(Class pReferenceClass)
           
 void defineVersionFrom(Class pReferenceClass, String pAdditional)
           
static void execute(Commandable pCommandable, String[] pArgs)
          The top-level entry point to application execution.
static void execute(DefaultedCommandable pCommandable, String[] pArgs)
           
static void execute(SimpleExecutable pExecutable, String[] pArgs)
           
 List<String> getHandled()
          Give the list of all commands that were handled.
protected  Map<String,CommandAction> getMap()
           
protected  boolean handle(CommandArgs pArgs)
           
 boolean isAllowEmpty()
          Whether it is acceptable for the command set to be executed with no arguments.
 List<String> listCommands()
           
protected  List<String> preliminaryCommands()
           
 void processAndExecute(String[] pArgs, Runnable pRunnable)
          The primary action is defined externally by the given Runnable, so process all the given arguments, then execute the runnable (assuming no errors during processing).
protected  boolean processNext(CommandArgs pArgs)
           
 void setAllowEmpty(boolean pAllowEmpty)
          Define whether it is acceptable for the command set to be executed with no arguments.
 String toString()
           
 String toUsageString()
           
 
Methods inherited from class com.notuvy.cmd.CommandAction
constructParentCommands, getKey, getParent, isTerminated, process, process, setParent, setTerminated
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CMD_HELP

public static final String CMD_HELP
See Also:
Constant Field Values

CMD_VERSION

public static final String CMD_VERSION
See Also:
Constant Field Values
Constructor Detail

CommandSet

public CommandSet()

CommandSet

protected CommandSet(String pKey)
Method Detail

execute

public static void execute(Commandable pCommandable,
                           String[] pArgs)
The top-level entry point to application execution. Create a new CommandSet, have the application configure it, process the arguments, then run the application.

Parameters:
pCommandable - The initialized application instance.
pArgs - The raw command line args.

execute

public static void execute(DefaultedCommandable pCommandable,
                           String[] pArgs)

execute

public static void execute(SimpleExecutable pExecutable,
                           String[] pArgs)

getMap

protected Map<String,CommandAction> getMap()

getHandled

public List<String> getHandled()
Give the list of all commands that were handled.

Returns:
The list of String names of executed commands.

isAllowEmpty

public boolean isAllowEmpty()
Whether it is acceptable for the command set to be executed with no arguments.

Returns:
boolean flag.

setAllowEmpty

public void setAllowEmpty(boolean pAllowEmpty)
Define whether it is acceptable for the command set to be executed with no arguments. Some usages will require that an action must be specified. Others use the command interpretor just to define settings (and none may be specified) and the actual action may be triggered externally.

Parameters:
pAllowEmpty - boolean flag.

processNext

protected boolean processNext(CommandArgs pArgs)

defineVersionFrom

public void defineVersionFrom(Class pReferenceClass)

defineVersionFrom

public void defineVersionFrom(Class pReferenceClass,
                              String pAdditional)

define

public CommandSet define(CommandAction pAction)
Add the given command to this set.

Parameters:
pAction - action object
Returns:
this, for cascading.

defineSynonym

public CommandSet defineSynonym(String pSynonym,
                                String pKey)
Define a command as a synonym for an existing command. (Duplication without redefinition.)

Parameters:
pSynonym - The new command to define.
pKey - The name of the existing command to duplicate.
Returns:
this, for cascading.

processAndExecute

public void processAndExecute(String[] pArgs,
                              Runnable pRunnable)
The primary action is defined externally by the given Runnable, so process all the given arguments, then execute the runnable (assuming no errors during processing).

Parameters:
pArgs - The list of arguments (from the main method).
pRunnable - The externally define principle action.

toString

public String toString()
Overrides:
toString in class Object

handle

protected boolean handle(CommandArgs pArgs)
Specified by:
handle in class CommandAction

listCommands

public List<String> listCommands()
Specified by:
listCommands in class CommandAction

preliminaryCommands

protected List<String> preliminaryCommands()

toUsageString

public String toUsageString()
Specified by:
toUsageString in class CommandAction


Copyright © 2013. All Rights Reserved.