Skip to content

Function: cli() ​

Run the command.

Call Signature ​

ts
export async function cli<G extends GunshiParamsConstraint>(args: string[], entry: Command<G> | CommandRunner<G> | LazyCommand<G>, options?: CliOptions<G>): Promise<string | undefined>

Run the command.

Type Parameters ​

NameDescription
G extends GunshiParamsConstraintA type extending GunshiParams to specify the shape of command and cli options.

Parameters ​

NameTypeDescription
argsstring[]Command line arguments
entryCommand<G> | CommandRunner<G> | LazyCommand<G>A entry command, an inline command runner, or a lazily-loaded command
optionsCliOptions<G>A CLI options (optional)

Returns ​

Promise<string | undefined> — A rendered usage or undefined. if you will use CliOptions.usageSilent option, it will return rendered usage string.

Call Signature ​

ts
export async function cli<
  A extends Args = Args,
  G extends GunshiParams = { args: A; extensions: {} }
>(args: string[], entry: Command<G> | CommandRunner<G> | LazyCommand<G>, options?: CliOptions<G>): Promise<string | undefined>

Run the command.

Type Parameters ​

NameDescription
A extends Args = ArgsThe type of arguments defined in the command and cli options.
G extends GunshiParams = { args: A; extensions:-

Parameters ​

NameTypeDescription
argsstring[]Command line arguments
entryCommand<G> | CommandRunner<G> | LazyCommand<G>A entry command, an inline command runner, or a lazily-loaded command
optionsCliOptions<G>A CLI options (optional)

Returns ​

Promise<string | undefined> — A rendered usage or undefined. if you will use CliOptions.usageSilent option, it will return rendered usage string.

Call Signature ​

ts
export async function cli<
  E extends ExtendContext = ExtendContext,
  G extends GunshiParams = { args: Args; extensions: E }
>(args: string[], entry: Command<G> | CommandRunner<G> | LazyCommand<G>, options?: CliOptions<G>): Promise<string | undefined>

Run the command.

Type Parameters ​

NameDescription
E extends ExtendContext = ExtendContextAn ExtendContext type to specify the shape of command and cli options.
G extends GunshiParams = { args: Args; extensions: E }-

Parameters ​

NameTypeDescription
argsstring[]Command line arguments
entryCommand<G> | CommandRunner<G> | LazyCommand<G>A entry command, an inline command runner, or a lazily-loaded command
optionsCliOptions<G>A CLI options (optional)

Returns ​

Promise<string | undefined> — A rendered usage or undefined. if you will use CliOptions.usageSilent option, it will return rendered usage string.

Call Signature ​

ts
export async function cli<G extends GunshiParams = DefaultGunshiParams>(args: string[], entry: Command<G> | CommandRunner<G> | LazyCommand<G>, options?: CliOptions<G>): Promise<string | undefined>

Run the command.

Type Parameters ​

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

Parameters ​

NameTypeDescription
argsstring[]Command line arguments
entryCommand<G> | CommandRunner<G> | LazyCommand<G>A entry command, an inline command runner, or a lazily-loaded command
optionsCliOptions<G>A CLI options (optional)

Returns ​

Promise<string | undefined> — A rendered usage or undefined. if you will use CliOptions.usageSilent option, it will return rendered usage string.

Call Signature ​

ts
export async function cli(args: string[], entry: SubCommandable, options?: CliOptions): Promise<string | undefined>

Run the command.

This overload accepts any command-like object using a loose structural type. It bypasses TypeScript contravariance issues with callback properties.

Note: This overload MUST be last in the overload list. TypeScript checks overloads in declaration order and selects the first matching one. The SubCommandable type is intentionally loose and would match any command, so placing it first would prevent proper type inference for more specific command types.

Parameters ​

NameTypeDescription
argsstring[]Command line arguments
entrySubCommandableA command-like object (command, command runner, or lazy command)
optionsCliOptionsA CLI options (optional)

Returns ​

Promise<string | undefined> — A rendered usage or undefined. if you will use CliOptions.usageSilent option, it will return rendered usage string.

Released under the MIT License.