Skip to content

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, reads process.argv, exits process

  • Import: @kjanat/dreamcli

  • Export kind: class

  • Declared in: src/core/cli/index.ts

  • Source link: src/core/cli/index.ts:1031

Signatures ​

ts
class CLIBuilder {}

Members ​

Properties ​

schema ​

Runtime schema descriptor.

ts
schema: CLISchema;

Methods ​

builtins ​

ts
builtins(config: BuiltinsConfig): CLIBuilder;

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?: CompletionRegistrationOptions): 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>, options?: DefaultCommandOptions): CLIBuilder;

description ​

ts
description(text: string): CLIBuilder;

execute ​

ts
execute(argv: readonly string[], options?: CLIExecuteOptions): Promise<RunResult>;

help ​

ts
help(config: HelpConfig): CLIBuilder;
ts
links(links?: { name?: string | URL; version?: string | URL; }): CLIBuilder;

manifest ​

ts
manifest(data: PackageJsonData): CLIBuilder;

plugin ​

ts
plugin(definition: CLIPlugin): CLIBuilder;

run ​

ts
run(options?: CLIRunOptions): Promise<never>;

version ​

ts
version(v: string): CLIBuilder;

_from ​

ts
_from(schema: CLISchema, compiled: CompiledCLI): 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();

See Also ​

Released under the MIT License.