Interface CommandInterface
- All Known Implementing Classes:
HelpCommand
CommandManager.
Commonly used for handling CLI arguments in applications.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidexecute(CommandManager commandManager) Executes the command using the providedCommandManager.voidexecute(CommandManager commandManager, String[] args) Executes the command using the providedCommandManagerand arguments.Returns the description of the command.intReturns the number of arguments expected by the command.voidsetDescription(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
intrepresenting 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
CommandManagerwhen the associated command key is executed.- Parameters:
commandManager- theCommandManagerinstance managing the commandExample:
CommandManager commandManager = new CommandManager(); commandManager.executeCommand("--help");
-
execute
Executes the command using the providedCommandManagerand 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
CommandManagerwhen the associated command key is executed.- Parameters:
commandManager- theCommandManagerinstance managing the commandargs- an array ofStringarguments 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
Stringdescribing 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- aStringdescribing 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:
-