Skip to content

Interface: CommandContext<G> ​

Command context.

Command context is the context of the command execution.

Signature ​

ts
export interface CommandContext<G extends GunshiParamsConstraint = DefaultGunshiParams>

Type Parameters ​

NameDescription
G extends GunshiParamsConstraint = DefaultGunshiParamsA type extending GunshiParams to specify the shape of command context.

Properties ​

NameTypeDescription
_string[]Original command line arguments. This argument is passed from cli function.
argsExtractArgs<G>Command arguments, that is the arguments of the command that is executed. The command arguments is same Command.args.
callModeCommandCallModeCommand call mode. The command call mode is entry when the command is executed as an entry command, and subCommand when the command is executed as a sub-command.
commandPathstring[]The path of nested sub-commands that were resolved to reach the current command. For example, if the user runs git remote add, commandPath would be ['remote', 'add']. For the entry command, this is an empty array. Since v0.28.0
descriptionstring | undefinedCommand description, that is the description of the command that is executed. The command description is same CommandEnvironment.description.
envReadonly<CommandEnvironment<G>>Command environment, that is the environment of the command that is executed. The command environment is same CommandEnvironment.
explicitExtractArgExplicitlyProvided<G>Whether arguments were explicitly provided by the user. - true: The argument was explicitly provided via command line - false: The argument was not explicitly provided. This means either: - The value comes from a default value defined in the argument schema - The value is undefined (no explicit input and no default value)
extensionskeyof ExtractExtensions<G> extends never ? any : ExtractExtensions<G>Command context extensions. Since v0.27.0
log(message?: any, ...optionalParams: any[]) => voidOutput a message for people. If CommandEnvironment.usageSilent is true, the message is not output. Nor is it when a command that spreads jsonArgs is asked for JSON with --json, so that stdout has the JSON only: the hooks and the plugins get the same function.
namestring | undefinedCommand name, that is the command that is executed. The command name is same CommandEnvironment.name.
omittedbooleanWhether the currently executing command has been executed with the sub-command name omitted. A command that has sub-commands and no run prints its usage then, with the global options plugin, as --help does.
passthroughstring[]The arguments that the command does not take, as they are given and in order, for a command with passthrough to pass on to another program: the options that it does not declare, with the arguments that they take as their values, the positional arguments that it does not take, and the arguments after --, at the end and without -- itself. app exec run.js --watch src -- --env x, for exec with the positional argument script, gives ['--watch', 'src', '--env', 'x']. The arguments after -- are in rest too: pass this on in place of rest, not with it. It is an empty array for a command without passthrough.
positionalsstring[]The positional arguments of the command line, the names of the command path first: app deploy web gives ['deploy', 'web']. The positional arguments of the command itself are positionals.slice(commandPath.length), and the ones that it declares are in values too.
reststring[]Command rest arguments, that is the remaining argument not resolved by the optional command option delimiter --.
toKebab (optional)booleanWhether to convert the camel-case style argument name to kebab-case. This context value is set from Command.toKebab option.
tokensArgToken[]Argument tokens, that is parsed by parseArgs function.
validationError (optional)AggregateErrorValidation error from argument parsing. This will be set if argument validation fails during CLI execution.
valuesArgValues<ExtractArgs<G>>Command values, that is the values of the command that is executed. Resolve values with resolveArgs from command arguments and Command.args.

log Parameters ​

NameTypeDescription
messageanyan output message, see console.log (optional)
optionalParamsany[]an optional parameters, see console.log

log Returns ​

void

Released under the MIT License.