Class Command

java.lang.Object
com.j3d.engine.interact.cmd.base.Command
Direct Known Subclasses:
CameraCmd, ClipboardCmd, CreateCmd, DebugCmd, EngineCmd, ExplodeCmd, ExtrudeCmd, HelpCmd, JaivaExecCmd, JoinCmd, MacroCmd, MeasureCmd, PrismCmd, SelectCmd, Subcommand, ThingCmd, TransformCmd, UICmd

public class Command extends Object
A Command encapsulates all the information needed to define and execute a user-callable action. This includes its name, aliases, description, and a structured list of accepted Arguments.

Key responsibilities of this class include:

Author:
Lehlogonolo Poole
See Also:
  • Field Details

    • aliases

      public ArrayList<String> aliases
      A list of all names this command can be called by, including the primary name.
    • description

      public String description
      A user-friendly description of what the command does.
    • args

      public ArrayList<Argument> args
    • hasNoArgUsage

      private boolean hasNoArgUsage
    • variadicTaggedArgs

      private boolean variadicTaggedArgs
      A flag indicating whether this command accepts a variable number of tagged arguments (e.g., key:value pairs).
    • usages

      protected ArrayList<String> usages
  • Constructor Details

    • Command

      public Command(String name, String d)
      Constructs a new Command.
      Parameters:
      name - The primary name of the command. This will also be its first alias.
      d - A user-friendly description of the command.
  • Method Details

    • aliases

      public Command aliases(String... a)
      Adds one or more aliases to this command.
      Parameters:
      a - A varargs array of alias strings.
      Returns:
      This Command instance for method chaining.
    • args

      public Command args(Argument... a)
      Adds one or more arguments to this command's definition.
      Parameters:
      a - A varargs array of Argument objects.
      Returns:
      This Command instance for method chaining.
    • addNoArgUsage

      public Command addNoArgUsage()
    • run

      public void run(Invoker invoker, SafeJLabel logLabel, String aliasUsed, Object[] args, ArrayList<TaggedArgValue<?>> taggedArgs)
      The method to be overridden by subclasses to implement command functionality.
      Parameters:
      invoker - The invoker of this command
      logLabel - The JLabel to display log messages.
      aliasUsed - The alias of the command that was used to invoke it.
      args - The arguments passed to the command.
      taggedArgs - Tagged arguments passed to the command.
    • dispatchToSubcommands

      protected void dispatchToSubcommands(String subcommandName, SafeJLabel logLabel, Object[] args, ArrayList<TaggedArgValue<?>> taggedArgs)
      Dispatches the command to the appropriate subcommand based on the first argument.
      Parameters:
      subcommandName - The name of the subcommand to dispatch to.
      args - The raw arguments passed to the main command, including the subcommand name as the first argument.
      taggedArgs -
    • aliasStream

      public Stream<String> aliasStream()
      Returns a stream of all the aliases of the command. (Including it's own name)
      Returns:
      A stream of all the aliases of the command.
    • parseUsages

      public Command parseUsages()
      Parses the usages of the command based on its arguments. This method populates the usages list with all possible usages of the command, taking into account subcommands and typed arguments.
      Returns:
      The Command instance with populated usages.
    • getUsages

      public ArrayList<String> getUsages()
    • usages

      public ArrayList<String> usages(String alias)
    • varTaggedArgs

      public boolean varTaggedArgs()
    • hasNoArgs

      public boolean hasNoArgs()