Function: cli()
Run the command.
Call Signature
export async function cli<
A extends Args = Args,
G extends GunshiParams = { args: A; extensions: {} }
>(args: string[], entry:
| (Command<NoInferParams<G>> & { args?: A & UnknownArgKeys<A> })
| CommandRunner<NoInferParams<G>>
| LazyCommand<NoInferParams<G>>, options?: CliOptions<NoInferParams<G>>): Promise<string | undefined>Run the command.
An object written as the entry command is typed by its args, as with define: ctx.values of its run are inferred from them, and a key that an argument does not have is an error.
Type Parameters
| Name | Description |
|---|---|
A extends Args = Args | The type of arguments of the entry command, inferred from its args. |
G extends GunshiParams = { args: A; extensions: {} } | A type extending GunshiParams, which is not inferred: { args: A; extensions: {} }. |
Parameters
| Name | Type | Description |
|---|---|---|
args | string[] | Command line arguments |
entry | (Command<NoInferParams<G>> & { args?: A & UnknownArgKeys<A> }) | CommandRunner<NoInferParams<G>> | LazyCommand<NoInferParams<G>> | A entry command, an inline command runner, or a lazily-loaded command |
options | CliOptions<NoInferParams<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. It is also undefined when the arguments fail validation and the errors are reported to stderr (see CliOptions.renderValidationErrors).
Call Signature
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
| Name | Description |
|---|---|
G extends GunshiParamsConstraint | A type extending GunshiParams to specify the shape of command and cli options. |
Parameters
| Name | Type | Description |
|---|---|---|
args | string[] | Command line arguments |
entry | Command<G> | CommandRunner<G> | LazyCommand<G> | A entry command, an inline command runner, or a lazily-loaded command |
options | CliOptions<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. It is also undefined when the arguments fail validation and the errors are reported to stderr (see CliOptions.renderValidationErrors).
Call Signature
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
| Name | Description |
|---|---|
E extends ExtendContext = ExtendContext | An ExtendContext type to specify the shape of command and cli options. |
G extends GunshiParams = { args: Args; extensions: E } | - |
Parameters
| Name | Type | Description |
|---|---|---|
args | string[] | Command line arguments |
entry | Command<G> | CommandRunner<G> | LazyCommand<G> | A entry command, an inline command runner, or a lazily-loaded command |
options | CliOptions<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. It is also undefined when the arguments fail validation and the errors are reported to stderr (see CliOptions.renderValidationErrors).
Call Signature
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
| Name | Description |
|---|---|
G extends GunshiParams = DefaultGunshiParams | A type extending GunshiParams to specify the shape of command and cli options. |
Parameters
| Name | Type | Description |
|---|---|---|
args | string[] | Command line arguments |
entry | Command<G> | CommandRunner<G> | LazyCommand<G> | A entry command, an inline command runner, or a lazily-loaded command |
options | CliOptions<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. It is also undefined when the arguments fail validation and the errors are reported to stderr (see CliOptions.renderValidationErrors).
Call Signature
export async function cli(args: string[], entry: EntryCommandable, options?: CliOptions): Promise<string | undefined>Run the command.
This overload takes a command of another copy of the types of gunshi, such as a command of @gunshi/definition, whose types the overloads above cannot compare. Its arguments are checked as Args, and its runner returns what a runner returns.
Note: This overload MUST be last in the overload list. TypeScript checks overloads in declaration order and selects the first matching one.
Parameters
| Name | Type | Description |
|---|---|---|
args | string[] | Command line arguments |
entry | EntryCommandable | A command-like object (command, command runner, or lazy command) |
options | CliOptions | 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. It is also undefined when the arguments fail validation and the errors are reported to stderr (see CliOptions.renderValidationErrors).
