CLIBuilder
Immutable CLI program builder.
Registers commands, handles root-level --help/--version, and dispatches to the matched command based on argv.
Two execution paths:
.execute(argv, options?)— testable, returns RunResult.run(options?)— production entry, readsprocess.argv, exits processImport:
@kjanat/dreamcliExport kind: class
Declared in:
src/core/cli/index.tsSource link:
packages/dreamcli/src/core/cli/index.ts:315
Signatures
ts
class CLIBuilder {}Members
Constructors
constructor
ts
constructor();Properties
schema
Runtime schema descriptor.
ts
schema: CLISchema;Methods
command
ts
command<F extends Record<string, FlagBuilder<FlagConfig>>, A extends Record<string, ArgBuilder<ArgConfig>>, C extends Record<string, unknown>>(cmd: CommandBuilder<F, A, C>): CLIBuilder;completions
ts
completions(options?: CompletionOptions): CLIBuilder;config
ts
config(appName: string, loaders?: readonly FormatLoader[]): CLIBuilder;configLoader
ts
configLoader(loader: FormatLoader): CLIBuilder;default
ts
default<F extends Record<string, FlagBuilder<FlagConfig>>, A extends Record<string, ArgBuilder<ArgConfig>>, C extends Record<string, unknown>>(cmd: CommandBuilder<F, A, C>): CLIBuilder;description
ts
description(text: string): CLIBuilder;execute
ts
execute(argv: readonly string[], options?: CLIRunOptions): Promise<RunResult>;packageJson
ts
packageJson(settings?: { inferName?: boolean; }): CLIBuilder;plugin
ts
plugin(definition: CLIPlugin): CLIBuilder;run
ts
run(options?: CLIRunOptions): Promise<never>;version
ts
version(v: string): CLIBuilder;Examples
ts
import { cli, command, flag, arg } from '@kjanat/dreamcli';
const deploy = command('deploy')
.arg('target', arg.string())
.flag('force', flag.boolean().alias('f'))
.action(({ args, flags, out }) => {
out.log(`Deploying ${args.target}...`);
});
cli('mycli')
.version('1.0.0')
.command(deploy)
.run();