Class SimpleCommandManager

java.lang.Object
com.pnfsoftware.jeb.util.interpreter.SimpleCommandManager
All Implemented Interfaces:
ICommandManager, ICommandNode

public class SimpleCommandManager extends Object implements ICommandManager
A basic command manager that may be extended.
  • Constructor Details

    • SimpleCommandManager

      public SimpleCommandManager()
      Create a root command manager.
    • SimpleCommandManager

      public SimpleCommandManager(ICommandManager parent, String name)
      Create a command manager.
      Parameters:
      parent - parent command manager, or null for the root manager
      name - manager name; must be empty for a root manager
  • Method Details

    • getParent

      public ICommandManager getParent()
      Description copied from interface: ICommandNode
      Retrieve the parent, that is, this node's manager.
      Specified by:
      getParent in interface ICommandNode
      Returns:
      the parent manager, or null for a root node
    • getName

      public String getName()
      Description copied from interface: ICommandNode
      Retrieve the name of the command (used to invoke the command)
      Specified by:
      getName in interface ICommandNode
      Returns:
      the command name
    • addChild

      public ICommandNode addChild(ICommandNode node)
      Description copied from interface: ICommandManager
      Add a child command node.
      Specified by:
      addChild in interface ICommandManager
      Parameters:
      node - child node to add
      Returns:
      the added node
    • getChildren

      public List<ICommandNode> getChildren()
      Description copied from interface: ICommandNode
      Get child command nodes.
      Specified by:
      getChildren in interface ICommandNode
      Returns:
      child nodes, or an empty list for leaf nodes
    • getHelp

      public String getHelp()
      Description copied from interface: ICommandNode
      Retrieve a short help that describes the command
      Specified by:
      getHelp in interface ICommandNode
      Returns:
      short help text
    • execute

      public ExecutionResult execute(String line)
      Parse and execute a command line.
      Parameters:
      line - command line
      Returns:
      the execution result, or null if no command matched
    • execute

      public ExecutionResult execute(List<InputToken> tokens)
      Description copied from interface: ICommandNode
      Execute the command.
      Specified by:
      execute in interface ICommandNode
      Parameters:
      tokens - command arguments
      Returns:
      the execution result, or null if no command was executed
    • preCheck

      protected ExecutionResult 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

      protected ExecutionResult 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

      public List<InputToken> parseTokenString(String line) throws ParseException
      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: ICommandNode
      Get parser and execution options for this node.
      Specified by:
      getOptions in interface ICommandNode
      Returns:
      bit flags such as ICommandNode.QUOTES_AS_NORMAL_CHAR