Class AbstractCommandHandler
java.lang.Object
com.pnfsoftware.jeb.util.interpreter.AbstractCommandHandler
- All Implemented Interfaces:
ICommandHandler,ICommandNode
Skeleton for a command handler.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringShort help text.protected StringExtended help text.protected StringCommand name.protected List<CommandParameter> Command parameter descriptors.protected ICommandManagerParent command manager.Fields inherited from interface com.pnfsoftware.jeb.util.interpreter.ICommandNode
QUOTES_AS_NORMAL_CHAR -
Constructor Summary
ConstructorsConstructorDescriptionAbstractCommandHandler(ICommandManager parent, String name) Create a command handler with no help text.AbstractCommandHandler(ICommandManager parent, String name, CommandParameter[] params, String help, String helpDetails) Create a command handler with explicit parameter descriptors.AbstractCommandHandler(ICommandManager parent, String name, String help) Create a command handler.AbstractCommandHandler(ICommandManager parent, String name, String[] paramNames, String help, String helpDetails) Create a command handler with named mandatory parameters. -
Method Summary
Modifier and TypeMethodDescriptionaddParameter(CommandParameter parameter) Add a parameter descriptor.addParameter(String paramName) Add a mandatory parameter by name.Get child command nodes.getHelp()Retrieve a short help that describes the commandGive additional details used whenhelp <command>is called, such as usage notes or return format details.getName()Retrieve the name of the command (used to invoke the command)intGet parser and execution options for this node.static StringgetParameter(List<InputToken> tokens, int i) Get a parameter.intgetParameterIndex(String paramName, String prefix) Get the index of a command parameter.Retrieve the list of parameters available for this commandstatic StringgetParameterSafe(List<InputToken> tokens, int i) Get a parameter, never return null.Retrieve the parent, that is, this node's manager.static InputTokengetToken(List<InputToken> tokens, int i) Get an input token by index.parseInputToken(List<InputToken> tokens) Parse input tokens and validate mandatory parameters.parseInputToken(List<InputToken> tokens, boolean failOnErrors) Assign input token values at the same indexes as the internalCommandParameterlist.protected voidSet the short help text.protected voidSet the command name.setOptions(int options) Set parser and execution options for this handler.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.pnfsoftware.jeb.util.interpreter.ICommandNode
execute
-
Field Details
-
parent
Parent command manager. -
name
Command name. -
params
Command parameter descriptors. -
help
Short help text. -
helpDetails
Extended help text.
-
-
Constructor Details
-
AbstractCommandHandler
Create a command handler with no help text.- Parameters:
parent- parent command managername- command name
-
AbstractCommandHandler
Create a command handler.- Parameters:
parent- parent command managername- command namehelp- short help text
-
AbstractCommandHandler
public AbstractCommandHandler(ICommandManager parent, String name, String[] paramNames, String help, String helpDetails) Create a command handler with named mandatory parameters.- Parameters:
parent- parent command managername- command nameparamNames- parameter nameshelp- short help texthelpDetails- extended help text
-
AbstractCommandHandler
public AbstractCommandHandler(ICommandManager parent, String name, CommandParameter[] params, String help, String helpDetails) Create a command handler with explicit parameter descriptors.- Parameters:
parent- parent command managername- command nameparams- command parameter descriptorshelp- short help texthelpDetails- extended help text
-
-
Method Details
-
parseInputToken
Parse input tokens and validate mandatory parameters.- Parameters:
tokens- input tokens to parse- Returns:
- tokens mapped to this handler's parameter list
-
parseInputToken
Assign input token values at the same indexes as the internalCommandParameterlist. The result array can be larger than the parameter list if the last parameter allows multiple tokens.- Parameters:
tokens- input tokens to parsefailOnErrors- set to false if you allow missing parameter after a prefixed parameter (used for autocompletion) or missing mandatory parameters- Returns:
- tokens mapped to this handler's parameter list
-
getParent
Description copied from interface:ICommandNodeRetrieve the parent, that is, this node's manager.- Specified by:
getParentin interfaceICommandNode- Returns:
- the parent manager, or null for a root node
-
getChildren
Description copied from interface:ICommandNodeGet child command nodes.- Specified by:
getChildrenin interfaceICommandNode- Returns:
- child nodes, or an empty list for leaf nodes
-
getName
Description copied from interface:ICommandNodeRetrieve the name of the command (used to invoke the command)- Specified by:
getNamein interfaceICommandNode- Returns:
- the command name
-
setName
Set the command name.- Parameters:
name- command name
-
getHelp
Description copied from interface:ICommandNodeRetrieve a short help that describes the command- Specified by:
getHelpin interfaceICommandNode- Returns:
- short help text
-
setHelp
Set the short help text.- Parameters:
help- short help text
-
getHelpDetails
Description copied from interface:ICommandHandlerGive additional details used whenhelp <command>is called, such as usage notes or return format details.- Specified by:
getHelpDetailsin interfaceICommandHandler- Returns:
- extended help text, or an empty string if none is available
-
getParameters
Description copied from interface:ICommandHandlerRetrieve the list of parameters available for this command- Specified by:
getParametersin interfaceICommandHandler- Returns:
- the command parameters, in parsing order
-
getParameterIndex
Get the index of a command parameter.- Parameters:
paramName- parameter nameprefix- parameter prefix- Returns:
- the parameter index, or -1 if none matches
-
addParameter
Add a mandatory parameter by name.- Parameters:
paramName- parameter name- Returns:
- this handler
-
addParameter
Add a parameter descriptor.- Parameters:
parameter- parameter descriptor- Returns:
- this handler
-
toString
-
getToken
Get an input token by index.- Parameters:
tokens- input tokensi- token index- Returns:
- the token, or null if the index is invalid
-
getParameter
Get a parameter.- Parameters:
tokens- input tokensi- token index- Returns:
- the parameter, null on error
-
getParameterSafe
Get a parameter, never return null.- Parameters:
tokens- input tokensi- token index- Returns:
- the parameter, or the empty string on error
-
getOptions
public int getOptions()Description copied from interface:ICommandNodeGet parser and execution options for this node.- Specified by:
getOptionsin interfaceICommandNode- Returns:
- bit flags such as
ICommandNode.QUOTES_AS_NORMAL_CHAR
-
setOptions
Set parser and execution options for this handler.- Parameters:
options- option bit flags- Returns:
- this handler
-