Class HelpCommand
- All Implemented Interfaces:
CommandInterface
--help command that prints all valid CLI argument commands when executed.
This command is designed to provide users with a list of all available commands
managed by the CommandManager. It is particularly useful for providing
guidance to users of a CLI application.
Usage
To use this command, include --help as an argument when running the application.
The command will output a list of valid commands to the console.
Example:
CommandManager commandManager = new CommandManager();
commandManager.executeCommand("--help");
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newHelpCommandinstance without a description.HelpCommand(String description) Constructs a newHelpCommandinstance. -
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.
-
Constructor Details
-
HelpCommand
public HelpCommand()Constructs a newHelpCommandinstance without a description. This command, when executed, prints all valid CLI arguments and their descriptions. managed by theCommandManager.- See Also:
-
HelpCommand
Constructs a newHelpCommandinstance. This command, when executed, prints all valid CLI arguments and their descriptions. managed by theCommandManager.- Parameters:
description- description of what the command does
-
-
Method Details
-
getExpectedArguments
public int getExpectedArguments()Description copied from interface:CommandInterfaceReturns the number of arguments expected by the command.This method is used to validate the number of arguments provided when executing the command.
- Specified by:
getExpectedArgumentsin interfaceCommandInterface- Returns:
- an
intrepresenting the number of expected arguments
-
execute
Description copied from interface:CommandInterfaceExecutes 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.- Specified by:
executein interfaceCommandInterface- Parameters:
commandManager- theCommandManagerinstance managing the commandExample:
CommandManager commandManager = new CommandManager(); commandManager.executeCommand("--help");
-
execute
Description copied from interface:CommandInterfaceExecutes 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.- Specified by:
executein interfaceCommandInterface- Parameters:
commandManager- theCommandManagerinstance managing the commandargs- an array ofStringarguments passed to the command
-
getDescription
Description copied from interface:CommandInterfaceReturns 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.
- Specified by:
getDescriptionin interfaceCommandInterface- 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
Description copied from interface:CommandInterfaceSets 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.
- Specified by:
setDescriptionin interfaceCommandInterface- 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:
-