Interface CommandInterface
- All Known Implementing Classes:
HelpCommand
CommandManager
.
Commonly used for handling CLI arguments in applications.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoid
execute
(CommandManager commandManager) Executes the command using the providedCommandManager
.void
execute
(CommandManager commandManager, String[] args) Executes the command using the providedCommandManager
and arguments.Returns the description of the command.int
Returns the number of arguments expected by the command.void
setDescription
(String description) Sets the description of the command.
-
Method Details
-
getExpectedArguments
int getExpectedArguments()Returns the number of arguments expected by the command.This method is used to validate the number of arguments provided when executing the command.
- Returns:
- an
int
representing the number of expected arguments
-
execute
Executes the command using the providedCommandManager
.This method contains the logic for what the command should do when triggered. It is invoked by the
CommandManager
when the associated command key is executed.- Parameters:
commandManager
- theCommandManager
instance managing the commandExample:
CommandManager commandManager = new CommandManager(); commandManager.executeCommand("--help");
-
execute
Executes the command using the providedCommandManager
and arguments.This method contains the logic for what the command should do when triggered, including handling any additional arguments passed to it. It is invoked by the
CommandManager
when the associated command key is executed.- Parameters:
commandManager
- theCommandManager
instance managing the commandargs
- an array ofString
arguments passed to the command
-
getDescription
String getDescription()Returns the description of the command.This description provides a brief explanation of the command's purpose and is typically used in help menus or documentation.
- Returns:
- a
String
describing the commandExample:
HelpCommand helpCommand = new HelpCommand("Displays a list of valid commands"); System.out.println(helpCommand.getDescription()); // Output: "Displays a list of valid commands"
-
setDescription
Sets the description of the command.This description provides a brief explanation of the command's purpose and is typically used in help menus or documentation.
- Parameters:
description
- aString
describing the commandExample:
HelpCommand helpCommand = new HelpCommand("--change-me"); System.out.println(helpCommand.getDescription()); // Output: "--change-me" helpCommand.setDescription("Displays a list of valid commands"); System.out.println(helpCommand.getDescription()); // Output: "Displays a list of valid commands"
- See Also:
-