Class HelpCommand

java.lang.Object
com.everdro1d.libs.commands.included.HelpCommand
All Implemented Interfaces:
CommandInterface

public class HelpCommand extends Object implements CommandInterface
A --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 Details

    • HelpCommand

      public HelpCommand()
      Constructs a new HelpCommand instance without a description. This command, when executed, prints all valid CLI arguments and their descriptions. managed by the CommandManager.
      See Also:
    • HelpCommand

      public HelpCommand(String description)
      Constructs a new HelpCommand instance. This command, when executed, prints all valid CLI arguments and their descriptions. managed by the CommandManager.
      Parameters:
      description - description of what the command does
  • Method Details

    • getExpectedArguments

      public int getExpectedArguments()
      Description copied from interface: CommandInterface
      Returns 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:
      getExpectedArguments in interface CommandInterface
      Returns:
      an int representing the number of expected arguments
    • execute

      public void execute(CommandManager commandManager)
      Description copied from interface: CommandInterface
      Executes the command using the provided CommandManager.

      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.

      Specified by:
      execute in interface CommandInterface
      Parameters:
      commandManager - the CommandManager instance managing the command

      Example:

       CommandManager commandManager = new CommandManager();
       commandManager.executeCommand("--help");
       
    • execute

      public void execute(CommandManager commandManager, String[] args)
      Description copied from interface: CommandInterface
      Executes the command using the provided CommandManager 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.

      Specified by:
      execute in interface CommandInterface
      Parameters:
      commandManager - the CommandManager instance managing the command
      args - an array of String arguments passed to the command
    • getDescription

      public String getDescription()
      Description copied from interface: CommandInterface
      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.

      Specified by:
      getDescription in interface CommandInterface
      Returns:
      a String describing the command

      Example:

       HelpCommand helpCommand = new HelpCommand("Displays a list of valid commands");
       System.out.println(helpCommand.getDescription());
       // Output: "Displays a list of valid commands"
       
    • setDescription

      public void setDescription(String description)
      Description copied from interface: CommandInterface
      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.

      Specified by:
      setDescription in interface CommandInterface
      Parameters:
      description - a String describing the command

      Example:

       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: