Readonly
enqueueAppend to the list of resolved commands to be executed.
Readonly
executeExecute the context's command string.
This function will override the context's result with the result of the final command in the chain each time it is called.
Optional
initialData: anyOptional data to be passed to the first command in the chain.
Readonly
exitExit the CLI with an optional exit code and message.
The exit code. Defaults to 0.
Optional
message: anyThe message to be displayed before exiting.
Readonly
parseParse a command string into a structured object using the configured
parseFn
and the context's options config.
This function has no side effects and is simply a wrapper around the
configured parseFn
and options config.
The command string to be parsed. Defaults to the context's command string.
Additional options config to be merged with the context's options config.
A ParsedCommand
object containing the parsed command tokens and
option values.
Readonly
resolveResolve the first command module from a command string using the configured
resolveFn
and parseFn
.
This function has no side effects and is simply a wrapper around the
configured resolveFn
and parseFn
.
The command string to be resolved. Defaults to the context's command string.
The path to the directory containing command modules. Defaults to the context's commands directory.
A ResolvedCommand
object.
Readonly
setSet the options config for the context, merging it with the existing options config. Typically, this is done by plugins during initialization.
The options config to be merged with the context's options config.
Readonly
setReadonly
throwThrow an error, allowing hooks to modify the error or ignore it.
The error to be thrown.
Static
prepareCreate a new Context
instance and automatically prep it for execution.
Readonly
clientThe client instance used for logging and user interaction.
Readonly
commandsReadonly
commandReadonly
hooksThe hooks emitter.
Readonly
pluginsMetadata about the plugins that will be used during preparation and execution.
The context for a command execution.
The
Context
serves as the orchestrator for the entire command lifecycle. It is responsible for initializing the CLI environment, resolving commands, parsing options, and managing execution flow. It ensures that all aspects of the CLI are prepared and ready before any action is taken, establishing a predictable and stable execution environment.Philosophy:
Context
offers explicit control over the command execution process, allowing for extensibility and customization without sacrificing predictability.Context
focuses on the setup and execution environment, whileState
manages the actual progression and state changes during command execution. This separation ensures that each module only handles its designated responsibilities, making the system easier to maintain and extend.Scope: