Package org.xjge.core

Class TerminalCommand

java.lang.Object
org.xjge.core.TerminalCommand

public abstract class TerminalCommand
extends java.lang.Object
Abstract class used to define additional commands for the Terminal.
Since:
2.0.0
  • Field Summary

    Fields
    Modifier and Type Field Description
    protected java.util.Map<java.lang.String,​TerminalCommand> commands  
  • Constructor Summary

    Constructors
    Constructor Description
    TerminalCommand​(java.lang.String description, java.lang.String usage, java.lang.String syntax)
    Creates a new terminal command with metadata that the help command will display.
  • Method Summary

    Modifier and Type Method Description
    protected java.lang.String errorInvalidArg​(java.lang.String found, java.lang.String required)
    Provides a generic response for when users supply an argument to a command which cannot be processed either due to differing data types or a syntax error.
    protected java.lang.String errorNotEnoughArgs​(int required)
    Provides a generic response for when users supply an insufficient amount of arguments to a command.
    protected java.lang.String errorTooManyArgs​(int numPassed, int maxArgs)
    Provides a generic response for when users supply more arguments than allowed by a command.
    abstract void execute​(java.util.List<java.lang.String> args)
    Executes the command and creates an output string indicating its success or failure.
    protected void setOutput​(java.lang.String text, Color color)
    Provides a response to the user upon executing a command.
    protected static java.lang.String useGenericSetter​(java.lang.String diff)
    Provides a generic response for "setter" style commands with a similar signature.
    protected static java.lang.String useGenericShowing​(java.lang.String diff)
    Provides a generic response for "showing" style commands with a similar signature.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • commands

      protected java.util.Map<java.lang.String,​TerminalCommand> commands
  • Constructor Details

    • TerminalCommand

      public TerminalCommand​(java.lang.String description, java.lang.String usage, java.lang.String syntax)
      Creates a new terminal command with metadata that the help command will display.
      On Syntax Structure:
      SyntaxMeaning
      plain textEnter this literally, exactly as shown.
      <type>An argument that should be replaced with an appropriate value of the specified data type.
      [entry]This entry is optional.
      (entry|entry)(Required) Pick one of the entries that are shown.
      [entry|entry](Optional) Pick one of the entries that are shown.
      Parameters:
      description - a description of what the command does
      usage - a description of how to use the command from the terminal
      syntax - the syntax structure of the command
  • Method Details

    • execute

      public abstract void execute​(java.util.List<java.lang.String> args)
      Executes the command and creates an output string indicating its success or failure. Values parsed from the arguments passed by the command terminal must be validated individually by subclasses that contain this method.
      Parameters:
      args - any arguments required by the command
    • setOutput

      protected void setOutput​(java.lang.String text, Color color)
      Provides a response to the user upon executing a command.
      Parameters:
      text - the text to show the user
      color - the color the text will be rendered in
    • useGenericSetter

      protected static java.lang.String useGenericSetter​(java.lang.String diff)
      Provides a generic response for "setter" style commands with a similar signature. Commands are considered "setter" style if they can be used to iterate and apply changes through some collection.
      Parameters:
      diff - the small difference used to better contextualize the response
      Returns:
      the generated message as a string
    • useGenericShowing

      protected static java.lang.String useGenericShowing​(java.lang.String diff)
      Provides a generic response for "showing" style commands with a similar signature. Commands are considered "showing" style if they control some boolean value.
      Parameters:
      diff - the small difference used to better contextualize the response
      Returns:
      the generated message as a string
    • errorNotEnoughArgs

      protected java.lang.String errorNotEnoughArgs​(int required)
      Provides a generic response for when users supply an insufficient amount of arguments to a command.
      Parameters:
      required - the minimum number of arguments required by this command
      Returns:
      an error message as a string that can be passed to setOutput()
    • errorTooManyArgs

      protected java.lang.String errorTooManyArgs​(int numPassed, int maxArgs)
      Provides a generic response for when users supply more arguments than allowed by a command.
      Parameters:
      numPassed - the number of arguments provided by the user
      maxArgs - the maximum number of arguments allowed by the command
      Returns:
      an error message as a string that can be passed to setOutput()
    • errorInvalidArg

      protected java.lang.String errorInvalidArg​(java.lang.String found, java.lang.String required)
      Provides a generic response for when users supply an argument to a command which cannot be processed either due to differing data types or a syntax error.
      Parameters:
      found - the argument provided by the user
      required - the argument(s) or data types as accepted by the command
      Returns:
      an error message as a string that can be passed to setOutput()