Class AbstractCommandHandler

java.lang.Object
com.pnfsoftware.jeb.util.interpreter.AbstractCommandHandler
All Implemented Interfaces:
ICommandHandler, ICommandNode

public abstract class AbstractCommandHandler extends Object implements ICommandHandler
Skeleton for a command handler.
  • Field Details

    • parent

      protected ICommandManager parent
      Parent command manager.
    • name

      protected String name
      Command name.
    • params

      protected List<CommandParameter> params
      Command parameter descriptors.
    • help

      protected String help
      Short help text.
    • helpDetails

      protected String helpDetails
      Extended help text.
  • Constructor Details

    • AbstractCommandHandler

      public AbstractCommandHandler(ICommandManager parent, String name)
      Create a command handler with no help text.
      Parameters:
      parent - parent command manager
      name - command name
    • AbstractCommandHandler

      public AbstractCommandHandler(ICommandManager parent, String name, String help)
      Create a command handler.
      Parameters:
      parent - parent command manager
      name - command name
      help - 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 manager
      name - command name
      paramNames - parameter names
      help - short help text
      helpDetails - 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 manager
      name - command name
      params - command parameter descriptors
      help - short help text
      helpDetails - extended help text
  • Method Details

    • parseInputToken

      public InputToken[] parseInputToken(List<InputToken> tokens)
      Parse input tokens and validate mandatory parameters.
      Parameters:
      tokens - input tokens to parse
      Returns:
      tokens mapped to this handler's parameter list
    • parseInputToken

      public InputToken[] parseInputToken(List<InputToken> tokens, boolean failOnErrors)
      Assign input token values at the same indexes as the internal CommandParameter list. The result array can be larger than the parameter list if the last parameter allows multiple tokens.
      Parameters:
      tokens - input tokens to parse
      failOnErrors - 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

      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
    • 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
    • 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
    • setName

      protected void setName(String name)
      Set the command name.
      Parameters:
      name - command name
    • 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
    • setHelp

      protected void setHelp(String help)
      Set the short help text.
      Parameters:
      help - short help text
    • getHelpDetails

      public String getHelpDetails()
      Description copied from interface: ICommandHandler
      Give additional details used when help <command> is called, such as usage notes or return format details.
      Specified by:
      getHelpDetails in interface ICommandHandler
      Returns:
      extended help text, or an empty string if none is available
    • getParameters

      public List<CommandParameter> getParameters()
      Description copied from interface: ICommandHandler
      Retrieve the list of parameters available for this command
      Specified by:
      getParameters in interface ICommandHandler
      Returns:
      the command parameters, in parsing order
    • getParameterIndex

      public int getParameterIndex(String paramName, String prefix)
      Get the index of a command parameter.
      Parameters:
      paramName - parameter name
      prefix - parameter prefix
      Returns:
      the parameter index, or -1 if none matches
    • addParameter

      public AbstractCommandHandler addParameter(String paramName)
      Add a mandatory parameter by name.
      Parameters:
      paramName - parameter name
      Returns:
      this handler
    • addParameter

      public AbstractCommandHandler addParameter(CommandParameter parameter)
      Add a parameter descriptor.
      Parameters:
      parameter - parameter descriptor
      Returns:
      this handler
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getToken

      public static InputToken getToken(List<InputToken> tokens, int i)
      Get an input token by index.
      Parameters:
      tokens - input tokens
      i - token index
      Returns:
      the token, or null if the index is invalid
    • getParameter

      public static String getParameter(List<InputToken> tokens, int i)
      Get a parameter.
      Parameters:
      tokens - input tokens
      i - token index
      Returns:
      the parameter, null on error
    • getParameterSafe

      public static String getParameterSafe(List<InputToken> tokens, int i)
      Get a parameter, never return null.
      Parameters:
      tokens - input tokens
      i - token index
      Returns:
      the parameter, or the empty string on error
    • 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
    • setOptions

      public AbstractCommandHandler setOptions(int options)
      Set parser and execution options for this handler.
      Parameters:
      options - option bit flags
      Returns:
      this handler