UNPKG

@backtrace/javascript-cli

Version:
30 lines (29 loc) 1.34 kB
import { Result } from '@backtrace/sourcemap-tools'; import { Section } from 'command-line-usage'; import { CliLogger } from '../logger'; import { CommandError } from '../models/CommandError'; import { ExtendedOptionDefinition } from '../models/OptionDefinition'; export type CommandFunction<T> = (context: CommandContext<T>) => Result<number | unknown, string> | Promise<Result<number | unknown, string>>; export interface CommandOptions { readonly _unknown?: string[]; } export interface CommandContext<T> { readonly opts: Partial<T> & CommandOptions; readonly logger: CliLogger; getHelpMessage(): string; } export declare class Command<T extends object = object> { readonly definition: ExtendedOptionDefinition; readonly subcommands: Command[]; readonly options: ExtendedOptionDefinition[]; readonly helpSections: Section[]; private _execute?; constructor(definition: ExtendedOptionDefinition); subcommand(command: Command): this; option<N extends keyof T & string>(option: ExtendedOptionDefinition<N>): this; help(...sections: Section[]): this; execute(fn: Command<T>['_execute']): this; run(argv: string[], stack?: Command[]): Promise<Result<number, CommandError>>; static getHelpMessage(command: Command, stack?: Command[]): string; private safeCommandLineArgs; }