Interface CommandInterface

All Known Implementing Classes:
HelpCommand

public interface CommandInterface
Interface for defining commands that can be executed by the CommandManager.

Commonly used for handling CLI arguments in applications.

See Also:
  • 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

      void execute(CommandManager commandManager)
      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.

      Parameters:
      commandManager - the CommandManager instance managing the command

      Example:

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

      void execute(CommandManager commandManager, String[] args)
      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.

      Parameters:
      commandManager - the CommandManager instance managing the command
      args - an array of String 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 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

      void setDescription(String description)
      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 - 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: