Skip to main content

Cli.create()

Creates a new CLI application. Can be used to create a single-command CLI with a root handler, or a router CLI that registers subcommands.

Signature

Parameters

string
required
The name of the CLI application. Used as the primary command name.
create.Options
Configuration options for the CLI. Omit run for a router CLI that only registers subcommands, or include run to create a leaf CLI with a root command handler.

Return Type

Cli<commands, vars, env>
A CLI application instance. Also used as a command group when mounted on a parent CLI.

Examples

Create a simple router CLI

Create a CLI with root command

Create CLI with environment variables

Cli Type

The CLI instance returned by Cli.create(). Also used as a command group when mounted on a parent CLI.

Properties

string
The name of the CLI application.
string | undefined
A short description of the CLI.
z.ZodObject<any> | undefined
The vars schema, if declared. Use typeof cli.vars with middleware<vars, env>() for typed middleware.
z.ZodObject<any> | undefined
The env schema, if declared. Use typeof cli.env with middleware<vars, env>() for typed middleware.

Methods

command()

Registers a root command or mounts a sub-CLI as a command group. Returns the CLI instance for chaining.
Parameters:
string
required
The command name. Used to invoke the command.
CommandDefinition
The command definition. See Commands for details.
Mounting a sub-CLI:
Parameters:
Cli
A sub-CLI instance to mount as a command group. All subcommands will be namespaced under this CLI’s name.
Examples:

serve()

Parses argv, runs the matched command, and writes the output envelope to stdout.
Parameters:
string[]
default:"process.argv.slice(2)"
Command-line arguments to parse. Defaults to process arguments.
serve.Options
Options for serve, primarily used for testing.
Example:

use()

Registers middleware that runs around every command.
Parameters:
MiddlewareHandler
The middleware handler function. See Middleware for details.
Example: