Record Class CommandContext

java.lang.Object
java.lang.Record
org.springframework.shell.core.command.CommandContext

public record CommandContext(ParsedInput parsedInput, CommandRegistry commandRegistry, PrintWriter outputWriter, InputReader inputReader) extends Record
Interface containing runtime information about the current command invocation.
Since:
4.0.0
Author:
Mahmoud Ben Hassine
  • Constructor Details

    • CommandContext

      public CommandContext(ParsedInput parsedInput, CommandRegistry commandRegistry, PrintWriter outputWriter, InputReader inputReader)
      Creates an instance of a CommandContext record class.
      Parameters:
      parsedInput - the value for the parsedInput record component
      commandRegistry - the value for the commandRegistry record component
      outputWriter - the value for the outputWriter record component
      inputReader - the value for the inputReader record component
  • Method Details

    • getOptionByName

      public @Nullable CommandOption getOptionByName(String optionName)
      Retrieve a command option by its name (long or short).
      Parameters:
      optionName - the name of the option to retrieve
      Returns:
      the matching CommandOption or null if not found
    • getArgumentByIndex

      public @Nullable CommandArgument getArgumentByIndex(int index)
      Retrieve a command argument by its index.
      Parameters:
      index - the index of the argument to retrieve
      Returns:
      the matching CommandArgument
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • parsedInput

      public ParsedInput parsedInput()
      Returns the value of the parsedInput record component.
      Returns:
      the value of the parsedInput record component
    • commandRegistry

      public CommandRegistry commandRegistry()
      Returns the value of the commandRegistry record component.
      Returns:
      the value of the commandRegistry record component
    • outputWriter

      public PrintWriter outputWriter()
      Returns the value of the outputWriter record component.
      Returns:
      the value of the outputWriter record component
    • inputReader

      public InputReader inputReader()
      Returns the value of the inputReader record component.
      Returns:
      the value of the inputReader record component