Skip to content

Interface: CliOptions<G> ​

CLI options of cli function.

Signature ​

ts
export interface CliOptions<G extends GunshiParamsConstraint = DefaultGunshiParams>

Type Parameters ​

NameDescription
G extends GunshiParamsConstraint = DefaultGunshiParamsA type extending GunshiParams to specify the shape of cli options.

Properties ​

NameTypeDescription
cwd (optional)stringCurrent working directory.
description (optional)stringCommand program description.
fallbackToEntry (optional)booleanWhether to fallback to entry command when the sub-command is not found. Default: false Since v0.27.0
leftMargin (optional)numberLeft margin of the command output.
middleMargin (optional)numberMiddle margin of the command output.
name (optional)stringCommand program name.
onAfterCommand (optional)(ctx: Readonly<CommandContext<G>>, result: string | undefined) => Awaitable<void>Hook that runs after successful command execution Since v0.27.0
onBeforeCommand (optional)(ctx: Readonly<CommandContext<G>>) => Awaitable<void>Hook that runs before any command execution Since v0.27.0
onErrorCommand (optional)(ctx: Readonly<CommandContext<G>>, error: Error) => Awaitable<void>Hook that runs when a command throws an error Since v0.27.0
plugins (optional)Plugin[]User plugins. Since v0.27.0
renderHeader (optional)((ctx: Readonly<CommandContext<G>>) => Promise<string>) | nullRender function the header section in the command usage.
renderUsage (optional)((ctx: Readonly<CommandContext<G>>) => Promise<string>) | nullRender function the command usage.
renderValidationErrors (optional)((ctx: Readonly<CommandContext<G>>, error: AggregateError) => Promise<string>) | nullRender function the validation errors.
strict (optional)booleanWhether to treat undefined options as argument validation errors. When enabled, option tokens that are not declared by the resolved command arguments or installed global options are reported as validation errors before the command runner is executed. Default: false
subCommands (optional)Record<string, SubCommandable> | Map<string, SubCommandable>Sub commands.
usageOptionType (optional)booleanWhether to display the usage optional argument type.
usageOptionValue (optional)booleanWhether to display the optional argument value.
usageSilent (optional)booleanWhether 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 (optional)stringCommand program version.

onAfterCommand Parameters ​

NameTypeDescription
ctxReadonly<CommandContext<G>>The command context
resultstring | undefinedThe command execution result

onAfterCommand Returns ​

Awaitable<void>

onBeforeCommand Parameters ​

NameTypeDescription
ctxReadonly<CommandContext<G>>The command context

onBeforeCommand Returns ​

Awaitable<void>

onErrorCommand Parameters ​

NameTypeDescription
ctxReadonly<CommandContext<G>>The command context
errorErrorThe error thrown during execution

onErrorCommand Returns ​

Awaitable<void>

Released under the MIT License.