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 Summary
ConstructorsConstructorDescriptionCommandContext(ParsedInput parsedInput, CommandRegistry commandRegistry, PrintWriter outputWriter, InputReader inputReader) Creates an instance of aCommandContextrecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of thecommandRegistryrecord component.final booleanIndicates whether some other object is "equal to" this one.@Nullable CommandArgumentgetArgumentByIndex(int index) Retrieve a command argument by its index.@Nullable CommandOptiongetOptionByName(String optionName) Retrieve a command option by its name (long or short).final inthashCode()Returns a hash code value for this object.Returns the value of theinputReaderrecord component.Returns the value of theoutputWriterrecord component.Returns the value of theparsedInputrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
CommandContext
public CommandContext(ParsedInput parsedInput, CommandRegistry commandRegistry, PrintWriter outputWriter, InputReader inputReader) Creates an instance of aCommandContextrecord class.- Parameters:
parsedInput- the value for theparsedInputrecord componentcommandRegistry- the value for thecommandRegistryrecord componentoutputWriter- the value for theoutputWriterrecord componentinputReader- the value for theinputReaderrecord component
-
-
Method Details
-
getOptionByName
Retrieve a command option by its name (long or short).- Parameters:
optionName- the name of the option to retrieve- Returns:
- the matching
CommandOptionor null if not found
-
getArgumentByIndex
Retrieve a command argument by its index.- Parameters:
index- the index of the argument to retrieve- Returns:
- the matching
CommandArgument
-
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
parsedInput
Returns the value of theparsedInputrecord component.- Returns:
- the value of the
parsedInputrecord component
-
commandRegistry
Returns the value of thecommandRegistryrecord component.- Returns:
- the value of the
commandRegistryrecord component
-
outputWriter
Returns the value of theoutputWriterrecord component.- Returns:
- the value of the
outputWriterrecord component
-
inputReader
Returns the value of theinputReaderrecord component.- Returns:
- the value of the
inputReaderrecord component
-