Package com.j3d.engine.interact.cmd.base
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
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:
- Defining the command's identity and structure.
- Providing a
run(com.j3d.engine.interact.cmd.Invoker, com.j3d.ui.SafeJLabel, java.lang.String, java.lang.Object[], java.util.ArrayList<com.j3d.engine.interact.cmd.args.TaggedArgValue<?>>)method for subclasses to implement their specific logic. - Supporting a hierarchy of commands through subcommand dispatching.
- A mechanism (
parseUsages()) to automatically generate detailed usage strings based on its arguments, which is crucial for providing dynamic help and command suggestions to the user.
- Author:
- Lehlogonolo Poole
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionA list of all names this command can be called by, including the primary name.A user-friendly description of what the command does.private booleanprivate booleanA flag indicating whether this command accepts a variable number of tagged arguments (e.g., key:value pairs). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds one or more aliases to this command.Returns a stream of all the aliases of the command.Adds one or more arguments to this command's definition.protected voiddispatchToSubcommands(String subcommandName, SafeJLabel logLabel, Object[] args, ArrayList<TaggedArgValue<?>> taggedArgs) Dispatches the command to the appropriate subcommand based on the first argument.booleanParses the usages of the command based on its arguments.voidrun(Invoker invoker, SafeJLabel logLabel, String aliasUsed, Object[] args, ArrayList<TaggedArgValue<?>> taggedArgs) The method to be overridden by subclasses to implement command functionality.boolean
-
Field Details
-
aliases
A list of all names this command can be called by, including the primary name. -
description
A user-friendly description of what the command does. -
args
-
hasNoArgUsage
private boolean hasNoArgUsage -
variadicTaggedArgs
private boolean variadicTaggedArgsA flag indicating whether this command accepts a variable number of tagged arguments (e.g., key:value pairs). -
usages
-
-
Constructor Details
-
Command
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
Adds one or more aliases to this command.- Parameters:
a- A varargs array of alias strings.- Returns:
- This Command instance for method chaining.
-
args
Adds one or more arguments to this command's definition.- Parameters:
a- A varargs array ofArgumentobjects.- Returns:
- This Command instance for method chaining.
-
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 commandlogLabel- 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
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
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
-
usages
-
varTaggedArgs
public boolean varTaggedArgs() -
hasNoArgs
public boolean hasNoArgs()
-