Class CommandContext

java.lang.Object
org.strassburger.tui4j.command.CommandContext

public class CommandContext extends Object
Represents the context of a command execution, including its name, arguments, and options.
  • Constructor Details

    • CommandContext

      public CommandContext(String commandName, Map<Argument<?>,Object> arguments, Map<Option<?>,Object> options)
      Constructs a CommandContext with the given options map.
      Parameters:
      commandName - The name of the command
      options - A map of Option instances to their corresponding values
  • Method Details

    • getCommandName

      public String getCommandName()
      Retrieves the name of the command associated with this context.
      Returns:
      The command name
    • getOptionValue

      public <T> T getOptionValue(Option<T> option)
      Retrieves the value of the specified option. If the option is not present in the context, returns its default value.
      Type Parameters:
      T - The type of the option's value
      Parameters:
      option - The option whose value is to be retrieved
      Returns:
      The value of the option, or its default value if not set
    • getOptionValue

      public <T> T getOptionValue(String optionName, Class<T> type)
      Retrieves the value of the specified option by its name.
      Type Parameters:
      T - The type of the option's value
      Parameters:
      optionName - The name of the option (long or short)
      type - The class type of the option's value
      Returns:
      The value of the option, or null if not found
    • getArgumentValue

      public <T> T getArgumentValue(Argument<T> argument)
      Retrieves the value of the specified argument.
      Type Parameters:
      T - The type of the argument's value
      Parameters:
      argument - The argument whose value is to be retrieved
      Returns:
      The value of the argument
    • getArgumentValue

      public <T> T getArgumentValue(String argumentName, Class<T> type)
      Retrieves the value of the specified argument by its name.
      Type Parameters:
      T - The type of the argument's value
      Parameters:
      argumentName - The name of the argument
      type - The class type of the argument's value
      Returns:
      The value of the argument, or null if not found
    • getOptions

      public Map<Option<?>,Object> getOptions()
      Retrieves the map of options and their corresponding values.
      Returns:
      A map of Option instances to their values
    • getArguments

      public Map<Argument<?>,Object> getArguments()
      Retrieves the map of arguments and their corresponding values.
      Returns:
      A map of Argument instances to their values