Module
Command line framework for deno 🦕 Including Commandline-Interfaces, Prompts, CLI-Table, Arguments Parser and more...
Extremely Popular
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538// deno-lint-ignore-file no-explicit-any
import type { ArgumentOptions, ArgumentValue, DefaultValue, FlagOptions, TypeHandler, ValueHandler,} from "../flags/types.ts";import { MapTypes } from "./_argument_types.ts";import type { ValidationError } from "./_errors.ts";import type { Command } from "./command.ts";import type { HelpOptions } from "./help/_help_generator.ts";import type { Type } from "./type.ts";import type { Merge } from "./_type_utils.ts";
export type { ArgumentValue, DefaultValue, TypeHandler };
export type TypeOrTypeHandler<TValue> = Type<TValue> | TypeHandler<TValue>;
export type Id<TValue> = TValue extends Record<string, unknown> ? TValue extends infer U ? { [K in keyof U]: Id<U[K]> } : never : TValue;
/* COMMAND TYPES */
/** Description handler. */export type Description< TOptions extends Record<string, any> | void = any, TArguments extends Array<unknown> = TOptions extends number ? any : [], TGlobals extends Record<string, any> | void = TOptions extends number ? any : void, TParentGlobals extends Record<string, any> | void = TOptions extends number ? any : void, TTypes extends Record<string, any> | void = TOptions extends number ? any : void, TGlobalTypes extends Record<string, any> | void = TOptions extends number ? any : void, TParentTypes extends Record<string, any> | void = TOptions extends number ? any : void, TParentCommand extends Command<any> | undefined = TOptions extends number ? any : undefined,> = | string | DescriptionHandler< TOptions, TArguments, TGlobals, TParentGlobals, TTypes, TGlobalTypes, TParentTypes, TParentCommand >;
/** Description handler. */export type DescriptionHandler< TOptions extends Record<string, any> | void = any, TArguments extends Array<unknown> = TOptions extends number ? any : [], TGlobals extends Record<string, any> | void = TOptions extends number ? any : void, TParentGlobals extends Record<string, any> | void = TOptions extends number ? any : void, TTypes extends Record<string, any> | void = TOptions extends number ? any : void, TGlobalTypes extends Record<string, any> | void = TOptions extends number ? any : void, TParentTypes extends Record<string, any> | void = TOptions extends number ? any : void, TParentCommand extends Command<any> | undefined = TOptions extends number ? any : undefined,> = ( this: Command< TParentGlobals, TParentTypes, TOptions, TArguments, TGlobals, TTypes, TGlobalTypes, TParentCommand >,) => string;
/** Action handler for commands and options. */export type ActionHandler< TOptions extends Record<string, any> | void = any, TArguments extends Array<unknown> = TOptions extends number ? any : [], TGlobals extends Record<string, any> | void = TOptions extends number ? any : void, TParentGlobals extends Record<string, any> | void = TOptions extends number ? any : void, TTypes extends Record<string, any> | void = TOptions extends number ? any : void, TGlobalTypes extends Record<string, any> | void = TOptions extends number ? any : void, TParentTypes extends Record<string, any> | void = TOptions extends number ? any : void, TParentCommand extends Command<any> | undefined = TOptions extends number ? any : undefined,> = ( this: Command< TParentGlobals, TParentTypes, TOptions, TArguments, TGlobals, TTypes, TGlobalTypes, TParentCommand >, options: CommandOptions<TOptions, TGlobals, TParentGlobals>, ...args: MapTypes<TArguments>) => unknown;
export type CommandOptions< TOptions extends Record<string, any> | void = any, TGlobals extends Record<string, any> | void = TOptions extends number ? any : void, TParentGlobals extends Record<string, any> | void = TOptions extends number ? any : void,> = MapTypes<Merge<TParentGlobals, Merge<TGlobals, TOptions>>>;
/** Argument details. */export interface Argument extends ArgumentOptions { /** Argument name. */ name: string; /** Shell completion action. */ action: string; /** Arguments type. */ type: string;}
/** Result of `cmd.parse()` method. */export interface CommandResult< TOptions extends Record<string, any> | void = any, TArguments extends Array<unknown> = TOptions extends number ? any : [], TGlobals extends Record<string, any> | void = TOptions extends number ? any : void, TParentGlobals extends Record<string, any> | void = TOptions extends number ? any : void, TTypes extends Record<string, any> | void = TOptions extends number ? any : void, TGlobalTypes extends Record<string, any> | void = TOptions extends number ? any : void, TParentTypes extends Record<string, any> | void = TOptions extends number ? any : void, TParentCommand extends Command<any> | undefined = TOptions extends number ? any : undefined,> { options: Id<Merge<Merge<TParentGlobals, TGlobals>, TOptions>>; args: TArguments; literal: string[]; cmd: Command< TParentGlobals, TParentTypes, TOptions, TArguments, TGlobals, TTypes, TGlobalTypes, TParentCommand >;}
/* OPTION TYPES */
export type OptionValueHandler<TValue = any, TReturn = TValue> = ValueHandler< TValue, TReturn>;
type ExcludedCommandOptions = | "name" | "args" | "type" | "optionalValue" | "requiredValue" | "aliases" | "variadic" | "list" | "value" | "default";
/** Command option options. */export interface GlobalOptionOptions< TOptions extends Record<string, any> | void = any, TArguments extends Array<unknown> = TOptions extends number ? any : [], TGlobals extends Record<string, any> | void = TOptions extends number ? any : void, TParentGlobals extends Record<string, any> | void = TOptions extends number ? any : void, TTypes extends Record<string, any> | void = TOptions extends number ? any : void, TGlobalTypes extends Record<string, any> | void = TOptions extends number ? any : void, TParentTypes extends Record<string, any> | void = TOptions extends number ? any : void, TParentCommand extends Command<any> | undefined = TOptions extends number ? any : undefined,> extends Omit<FlagOptions, ExcludedCommandOptions> { override?: boolean; hidden?: boolean; action?: ActionHandler< TOptions, TArguments, TGlobals, TParentGlobals, TTypes, TGlobalTypes, TParentTypes, TParentCommand >; prepend?: boolean; value?: OptionValueHandler; default?: DefaultValue;}
export interface OptionOptions< TOptions extends Record<string, any> | void = any, TArguments extends Array<unknown> = TOptions extends number ? any : [], TGlobals extends Record<string, any> | void = TOptions extends number ? any : void, TParentGlobals extends Record<string, any> | void = TOptions extends number ? any : void, TTypes extends Record<string, any> | void = TOptions extends number ? any : void, TGlobalTypes extends Record<string, any> | void = TOptions extends number ? any : void, TParentTypes extends Record<string, any> | void = TOptions extends number ? any : void, TParentCommand extends Command<any> | undefined = TOptions extends number ? any : undefined,> extends GlobalOptionOptions< TOptions, TArguments, TGlobals, TParentGlobals, TTypes, TGlobalTypes, TParentTypes, TParentCommand > { global?: boolean;}
/** Command option settings. */export interface Option< TOptions extends Record<string, any> | void = any, TArguments extends Array<unknown> = TOptions extends number ? any : [], TGlobals extends Record<string, any> | void = TOptions extends number ? any : void, TParentGlobals extends Record<string, any> | void = TOptions extends number ? any : void, TTypes extends Record<string, any> | void = TOptions extends number ? any : void, TGlobalTypes extends Record<string, any> | void = TOptions extends number ? any : void, TParentTypes extends Record<string, any> | void = TOptions extends number ? any : void, TParentCommand extends Command<any> | undefined = TOptions extends number ? any : undefined,> extends OptionOptions< TOptions, TArguments, TGlobals, TParentGlobals, TTypes, TGlobalTypes, TParentTypes, TParentCommand >, Omit<FlagOptions, "value"> { description: string; flags: Array<string>; typeDefinition?: string; args: Argument[]; groupName?: string;}
/* ENV VARS TYPES */
export type EnvVarValueHandler<TValue = any, TReturn = TValue> = ( val: TValue,) => TReturn;
/** Environment variable options */export interface GlobalEnvVarOptions { hidden?: boolean; required?: boolean; prefix?: string | undefined; value?: EnvVarValueHandler; exitCode?: number;}
/** Environment variable options */export interface EnvVarOptions extends GlobalEnvVarOptions { global?: boolean;}
/** Environment variable settings. */export interface EnvVar extends EnvVarOptions { name: string; names: string[]; description: string; type: string; details: Argument;}
/* TYPE TYPES */
/** Type options. */export interface TypeOptions { override?: boolean; global?: boolean;}
/** Type settings. */export interface TypeDef extends TypeOptions { name: string; handler: Type<unknown> | TypeHandler<unknown>;}
/* EXAMPLE TYPES */
/** Example settings. */export interface Example { name: string; description: string;}
/* COMPLETION TYPES */
/** Completion options. */export interface CompleteOptions { override?: boolean; global?: boolean;}
/** Completion settings. */export interface Completion< TOptions extends Record<string, any> | void = any, TArguments extends Array<unknown> = TOptions extends number ? any : [], TGlobals extends Record<string, any> | void = TOptions extends number ? any : void, TParentGlobals extends Record<string, any> | void = TOptions extends number ? any : void, TTypes extends Record<string, any> | void = TOptions extends number ? any : void, TGlobalTypes extends Record<string, any> | void = TOptions extends number ? any : void, TParentTypes extends Record<string, any> | void = TOptions extends number ? any : void, TParentCommand extends Command<any> | undefined = TOptions extends number ? any : undefined,> extends CompleteOptions { name: string; complete: CompleteHandler< TOptions, TArguments, TGlobals, TParentGlobals, TTypes, TGlobalTypes, TParentTypes, TParentCommand >;}
export type CompleteHandlerResult = | Array<string | number | boolean> | Promise<Array<string | number | boolean>>;
export type ValuesHandlerResult = Array<string | number | boolean>;
/** Type parser method. */export type CompleteHandler< TOptions extends Record<string, any> | void = any, TArguments extends Array<unknown> = TOptions extends number ? any : [], TGlobals extends Record<string, any> | void = TOptions extends number ? any : void, TParentGlobals extends Record<string, any> | void = TOptions extends number ? any : void, TTypes extends Record<string, any> | void = TOptions extends number ? any : void, TGlobalTypes extends Record<string, any> | void = TOptions extends number ? any : void, TParentTypes extends Record<string, any> | void = TOptions extends number ? any : void, TParentCommand extends Command<any> | undefined = TOptions extends number ? any : undefined,> = ( cmd: Command< TParentGlobals, TParentTypes, TOptions, TArguments, TGlobals, TTypes, TGlobalTypes, TParentCommand >, parent?: Command<any>,) => CompleteHandlerResult;
/** * Help callback method to print the help. * Invoked by the `--help` option and `help` command and the `.getHelp()` and `.showHelp()` methods. */export type HelpHandler< TOptions extends Record<string, any> | void = any, TArguments extends Array<unknown> = TOptions extends number ? any : [], TGlobals extends Record<string, any> | void = TOptions extends number ? any : void, TParentGlobals extends Record<string, any> | void = TOptions extends number ? any : void, TTypes extends Record<string, any> | void = TOptions extends number ? any : void, TGlobalTypes extends Record<string, any> | void = TOptions extends number ? any : void, TParentTypes extends Record<string, any> | void = TOptions extends number ? any : void, TParentCommand extends Command<any> | undefined = TOptions extends number ? any : undefined, TCommand extends Command< TParentGlobals, TParentTypes, TOptions, TArguments, TGlobals, TTypes, TGlobalTypes, TParentCommand > = Command< TParentGlobals, TParentTypes, TOptions, TArguments, TGlobals, TTypes, TGlobalTypes, TParentCommand >,> = (this: TCommand, cmd: TCommand, options: HelpOptions) => string;
/** * Version callback method to print the version. * Invoked by the `--help` option command and the `.getVersion()` and `.showHelp()` methods. */export type VersionHandler< TOptions extends Record<string, any> | void = any, TArguments extends Array<unknown> = TOptions extends number ? any : [], TGlobals extends Record<string, any> | void = TOptions extends number ? any : void, TParentGlobals extends Record<string, any> | void = TOptions extends number ? any : void, TTypes extends Record<string, any> | void = TOptions extends number ? any : void, TGlobalTypes extends Record<string, any> | void = TOptions extends number ? any : void, TParentTypes extends Record<string, any> | void = TOptions extends number ? any : void, TParentCommand extends Command<any> | undefined = TOptions extends number ? any : undefined, TCommand extends Command< TParentGlobals, TParentTypes, TOptions, TArguments, TGlobals, TTypes, TGlobalTypes, TParentCommand > = Command< TParentGlobals, TParentTypes, TOptions, TArguments, TGlobals, TTypes, TGlobalTypes, TParentCommand >,> = (this: TCommand, cmd: TCommand) => string;
export type ErrorHandler = ( error: Error | ValidationError, cmd: Command,) => unknown;