Interface: CommandEnvironment<G>
Command environment.
Signature
ts
export interface CommandEnvironment<G extends GunshiParamsConstraint = DefaultGunshiParams>Type Parameters
| Name | Description |
|---|---|
G extends GunshiParamsConstraint = DefaultGunshiParams | A type extending GunshiParams to specify the shape of command environments. |
Properties
| Name | Type | Description |
|---|---|---|
cwd | string | undefined | Current working directory. |
description | string | undefined | Command description. |
entryCommand (optional) | Command<any> | LazyCommand<any> | The entry command of the CLI, marked with entry: true. It is available whether or not the CLI has sub-commands, while CommandEnvironment.subCommands includes the entry command only when the sub-commands are given with CliOptions.subCommands. It is not frozen, like the commands in CommandEnvironment.subCommands. |
globalOptions (optional) | ReadonlyMap<string, ArgSchema> | The global options that are in effect for the command being executed. A plugin registers a global option with addGlobalOption, and gunshi merges it into the arguments of the command that runs. An argument that the command declares under the same name replaces it, and the option is then not in effect: the value under that name is the command's, and the plugin that registered it must not read it as its own. The schema is the one in effect, which may have given up its short name to an argument of the command that claims the same letter. |
leftMargin | number | Left margin of the command output. Default: 2 |
middleMargin | number | Middle margin of the command output. Default: 10 |
name | string | undefined | Command name. |
onAfterCommand | ((ctx: Readonly<CommandContext<G>>, result: string | undefined) => Awaitable<void>) | undefined | Hook that runs after successful command execution Since v0.27.0 |
onBeforeCommand | ((ctx: Readonly<CommandContext<G>>) => Awaitable<void>) | undefined | Hook that runs before any command execution Since v0.27.0 |
onErrorCommand | ((ctx: Readonly<CommandContext<G>>, error: Error) => Awaitable<void>) | undefined | Hook that runs when a command throws an error Since v0.27.0 |
renderHeader | ((ctx: Readonly<CommandContext<G>>) => Promise<string>) | null | undefined | Render function the header section in the command usage. |
renderUsage | ((ctx: Readonly<CommandContext<G>>) => Promise<string>) | null | undefined | Render function the command usage. |
renderValidationErrors | ((ctx: Readonly<CommandContext<G>>, error: AggregateError) => Promise<string>) | null | undefined | Render function the validation errors. |
strict | boolean | Whether to treat undefined options as argument validation errors. Default: false |
subCommands | Map<string, Command<any> | LazyCommand<any>> | undefined | Sub commands. |
usageOptionType | boolean | Whether to display the usage option type. Default: false |
usageOptionValue | boolean | Whether to display the option value. Default: true |
usageSilent | boolean | Whether to keep usage, header, version, and validation-error text off the terminal (they are still returned as strings) and to silence CommandContext.log. Output that must still appear — machine-readable results for an agent, warnings for the CLI author — should use console.log / console.warn, not ctx.log. Default: false |
version | string | undefined | Command version. |
