import { CommandContext, ProvidersFromChain } from "./context.mjs"; import { CompletionCallback, OptionCompletionCallback } from "./completion-types.mjs"; import { PromptOptionConfig, PromptProvider } from "./prompt-types.mjs"; import { CLI, CLICommandOptions, Command, CommandToChildEntry, ErrorHandler, SDKCommand } from "./public-api.mjs"; import * as _$_cli_forge_parser0 from "@cli-forge/parser"; import { ArgvParser, ConfigurationFiles, EnvOptionConfig, LocalizationDictionary, LocalizationFunction, OptionConfig, ParsedArgs } from "@cli-forge/parser"; //#region src/lib/internal-cli.d.ts /** Type alias for an InternalCLI instance with any type parameters. */ type AnyInternalCLI = InternalCLI; type ProviderRegistration = { type: 'eager'; value: unknown; } | { type: 'factory'; factory: Function; lifetime: 'global' | 'executionScope'; }; /** * The base class for a CLI application. This class is used to define the structure of the CLI. * * {@link cli} is provided as a small helper function to create a new CLI instance. * * @example * ```ts * import { cli } from 'cli-forge'; * * cli('basic-cli').command('hello', { * builder: (args) => * args.option('name', { * type: 'string', * }), * handler: (args) => { * console.log(`Hello, ${args.name}!`); * }).forge(); * ``` */ /** * Cross-realm brand symbol used to identify InternalCLI instances across * different copies of the cli-forge package (e.g. when pnpm resolves * multiple copies due to differing peer dependencies). `Symbol.for()` * returns the same symbol globally, so the brand check works even when * `instanceof` would fail. */ declare const CLI_FORGE_BRAND: unique symbol; declare class InternalCLI implements CLI { name: string; /** * Cross-realm brand for identifying InternalCLI instances across * different package copies. See {@link CLI_FORGE_BRAND}. */ readonly [CLI_FORGE_BRAND] = true; /** * Check whether `obj` is an InternalCLI instance, even when it was * created by a different copy of the cli-forge package. */ static isInternalCLI(obj: unknown): obj is AnyInternalCLI; /** * For internal use only. Stick to properties available on {@link CLI}. */ registeredCommands: Record; /** * Process-unique identifier stamped at construction time. Used to * validate at runtime that a CLI instance passed to `getCommandContext` * actually belongs to the active command chain. Never mutated once set — * builders, handlers, and middleware see the same value for the lifetime * of the instance, even across clones. * * For internal use only. */ readonly commandId: string; /** * Registered DI providers keyed by name. * For internal use only. */ registeredProviders: Map; /** * For internal use only. Stick to properties available on {@link CLI}. */ commandChain: string[]; /** * Reference to the parent CLI instance, if this command was registered as a subcommand. * For internal use only. Use `getParent()` instead. */ private _parent?; private requiresCommand; private _configuration?; private _versionOverride?; private registeredErrorHandlers; private registeredMiddleware; private registeredInitHooks; registeredPromptProviders: PromptProvider[]; /** * Stores prompt config for each option, keyed by option name. * Set when .option() is called with a `prompt` property. */ promptConfigs: Map>; /** * Custom completion callback for this command level. * Set when .completion() is called with a callback argument. */ completionCallback?: CompletionCallback; /** * Per-option completion callbacks, keyed by option name. * Set when .option() is called with a `completion` property. */ completionConfigs: Map>; /** * Whether .completion() has been called on this CLI instance. */ private _completionEnabled; /** * Set when a `$0` alias replaces the root builder via `.command()`. * The $0 builder should only run if no explicit subcommand is given, * so `forge()` defers it until the discovery loop confirms no match. */ private builderIsFrom$0Alias; /** * A list of option groups that have been registered with the CLI. Grouped Options are displayed together in the help text. * * For internal use only. Stick to properties available on {@link CLI}. */ registeredOptionGroups: Array<{ label: string; sortOrder: number; keys: Array; }>; getGroupedOptions(): { label: string; sortOrder: number; keys: Array<_$_cli_forge_parser0.InternalOptionConfig>; }[]; get configuration(): CLICommandOptions | undefined; private set configuration(value); /** * The parser used to parse the arguments for the current command. * * Meant for internal use only. Stick to properties available on {@link CLI}. * * If you need this kind of info, please open an issue on the GitHub repo with * your use case. */ parser: ArgvParser; /** * @param name What should the name of the cli command be? * @param configuration Configuration for the current CLI command. */ constructor(name: string, rootCommandConfiguration?: CLICommandOptions); withRootCommandConfiguration(configuration: CLICommandOptions): InternalCLI; command>(cmd: TCommand): CLI>, TParent, TProviders>; command(key: TCommandName, options: CLICommandOptions, TChildChildren, TChildProviders>): CLI, TChildProviders> }, TParent, TProviders>; commands(...a0: Command[] | Command[][]): any; option>(name: TOption, config: TOptionConfig & { prompt?: PromptOptionConfig; completion?: OptionCompletionCallback; }): any; positional>(name: TOption, config: TOptionConfig & { prompt?: PromptOptionConfig; completion?: OptionCompletionCallback; }): any; conflicts(...args: [string, string, ...string[]]): CLI; implies(option: string, ...impliedOptions: string[]): CLI; env(a0?: string | EnvOptionConfig | undefined): CLI; localize(dictionaryOrFn: LocalizationDictionary | LocalizationFunction, locale?: string): CLI; /** * Gets the localized display name for a command key. * @param key The command key * @returns The localized command name, or the original key if not localized */ getLocalizedCommandName(key: string): string; demandCommand(): CLI; strict(enable?: boolean): CLI; usage(usageText: string): CLI; hidden(hidden?: boolean): CLI; examples(...examples: string[]): CLI; version(version?: string): CLI; /** * Gets help text for the current command as a string. * @returns Help text for the current command. */ formatHelp(): string; /** * Prints help text for the current command to the console. */ printHelp(): void; middleware(callback: (args: TArgs) => TArgs2 | Promise | void | Promise): CLI; handler(fn: (args: TArgs, context: any) => R): CLI; provide(key: string, valueOrConfig: unknown): any; init(callback: (cli: CLI, args: TArgs) => Promise | void): CLI; completion(callback?: CompletionCallback): CLI; /** * Runs the current command. * @param cmd The command to run. * @param args The arguments to pass to the command. */ runCommand(args: T, originalArgV: string[], executedMiddleware?: Set<(args: any) => void>): Promise; getChildren(): TChildren; getParent(): TParent; getContext(): CommandContext, TChildren>; getBuilder(): ((parser: CLI) => CLI) | undefined; getHandler(): ((args: Omit) => THandlerReturn) | undefined; sdk(): SDKCommand; private buildSDKProxy; private collectMiddlewareChain; enableInteractiveShell(): CLI; private versionHandler; private withErrorHandlers; errorHandler(handler: ErrorHandler): CLI; withPromptProvider(provider: PromptProvider): CLI; group(labelOrConfigObject: string | { label: string; keys: (keyof TArgs)[]; sortOrder?: number; }, keys?: (keyof TArgs)[]): CLI; config(provider: ConfigurationFiles.AnyConfigProvider): CLI; updateConfig(values: Partial): Promise; updateConfig(updater: ConfigurationFiles.ConfigUpdater): Promise; /** * Parses argv and executes the CLI. * * Execution proceeds in two phases: * * **Discovery loop** (per command level): builder → parse (non-strict, * no validation) → merge → middleware → init hooks → find next * subcommand in unmatched tokens → repeat. * * **Final parse + execution**: parse (with validation, seeded with * accumulated args) → help/version check → handler. Middleware that * already ran during discovery is skipped. * * @param args argv. Defaults to process.argv.slice(2) * @returns Promise that resolves when the handler completes. */ forge: (args?: string[]) => Promise>; getParser(): _$_cli_forge_parser0.ReadonlyArgvParser; getSubcommands(): Readonly>; private collectProviders; /** * Walks the command chain from root (this) down to the running command * and collects each instance's `commandId`. Populates * `ForgeContextData.commandIdChain` so `getCommandContext(cli)` can * validate at runtime that the CLI passed as a type witness is any * command on the active chain. */ private collectCommandIdChain; clone(): InternalCLI; } //#endregion export { AnyInternalCLI, InternalCLI }; //# sourceMappingURL=internal-cli.d.mts.map