Class SimpleCommandManager
java.lang.Object
com.pnfsoftware.jeb.util.interpreter.SimpleCommandManager
- All Implemented Interfaces:
ICommandManager,ICommandNode
A basic command manager that may be extended.
-
Field Summary
Fields inherited from interface com.pnfsoftware.jeb.util.interpreter.ICommandNode
QUOTES_AS_NORMAL_CHAR -
Constructor Summary
ConstructorsConstructorDescriptionCreate a root command manager.SimpleCommandManager(ICommandManager parent, String name) Create a command manager. -
Method Summary
Modifier and TypeMethodDescriptionaddChild(ICommandNode node) Add a child command node.Parse and execute a command line.execute(List<InputToken> tokens) Execute the command.Get child command nodes.getHelp()Retrieve a short help that describes the commandgetName()Retrieve the name of the command (used to invoke the command)intGet parser and execution options for this node.Retrieve the parent, that is, this node's manager.parseTokenString(String line) Parse a command line into input tokens.protected ExecutionResultOverride to do command post-execution check.protected ExecutionResultpreCheck()Override to do command pre-execution check.
-
Constructor Details
-
SimpleCommandManager
public SimpleCommandManager()Create a root command manager. -
SimpleCommandManager
Create a command manager.- Parameters:
parent- parent command manager, or null for the root managername- manager name; must be empty for a root manager
-
-
Method Details
-
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
-
getName
Description copied from interface:ICommandNodeRetrieve the name of the command (used to invoke the command)- Specified by:
getNamein interfaceICommandNode- Returns:
- the command name
-
addChild
Description copied from interface:ICommandManagerAdd a child command node.- Specified by:
addChildin interfaceICommandManager- Parameters:
node- child node to add- Returns:
- the added node
-
getChildren
Description copied from interface:ICommandNodeGet child command nodes.- Specified by:
getChildrenin interfaceICommandNode- Returns:
- child nodes, or an empty list for leaf nodes
-
getHelp
Description copied from interface:ICommandNodeRetrieve a short help that describes the command- Specified by:
getHelpin interfaceICommandNode- Returns:
- short help text
-
execute
Parse and execute a command line.- Parameters:
line- command line- Returns:
- the execution result, or null if no command matched
-
execute
Description copied from interface:ICommandNodeExecute the command.- Specified by:
executein interfaceICommandNode- Parameters:
tokens- command arguments- Returns:
- the execution result, or null if no command was executed
-
preCheck
Override to do command pre-execution check. The default implementation does nothing.- Returns:
- an error to prevent the command from executing; null or a success to proceed with command execution
-
postCheck
Override to do command post-execution check. Only executed if command execution succeeded. The default implementation does nothing.- Returns:
- an error to prevent the command from executing; null or a success to proceed
-
parseTokenString
Parse a command line into input tokens.- Parameters:
line- command line- Returns:
- parsed input tokens
- Throws:
ParseException- if the command line contains invalid quoting or escaping
-
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
-