///
///
declare module "error/base" {
/**
* @packageDocumentation
* @internal
*/
import { ErrorMetadata } from "types";
export class BaseError extends Error {
meta: ErrorMetadata;
constructor(message: string, meta?: ErrorMetadata);
}
}
declare module "error/action" {
/**
* @packageDocumentation
* @internal
*/
import { BaseError } from "error/base";
export class ActionError extends BaseError {
constructor(error: string | Error);
}
}
declare module "logger/index" {
import type { Logger } from "types";
export let logger: Logger;
export function setLogger(loggerObj: Logger): void;
export function getLogger(): Logger;
export function createDefaultLogger(): Logger;
}
declare module "error/fatal" {
import type { BaseError } from "error/base";
/**
* @param err - Error object
*/
export function fatalError(error: BaseError): void;
}
declare module "error/invalid-validator" {
/**
* @packageDocumentation
* @internal
*/
import { BaseError } from "error/base";
import { Validator } from "types";
export class InvalidValidatorError extends BaseError {
constructor(validator: Validator);
}
}
declare module "error/missing-argument" {
/**
* @packageDocumentation
* @internal
*/
import { BaseError } from "error/base";
import { Command } from "command/index";
import { Argument } from "types";
export class MissingArgumentError extends BaseError {
constructor(argument: Argument, command: Command);
}
}
declare module "error/missing-flag" {
/**
* @packageDocumentation
* @internal
*/
import { BaseError } from "error/base";
import { Command } from "command/index";
import { Option } from "types";
export class MissingFlagError extends BaseError {
constructor(flag: Option, command: Command);
}
}
declare module "utils/colorize" {
export function colorize(text: string): string;
}
declare module "error/multi-validation" {
/**
* @packageDocumentation
* @internal
*/
import { BaseError } from "error/base";
import type { Command } from "command/index";
export class ValidationSummaryError extends BaseError {
constructor(cmd: Command, errors: BaseError[]);
}
}
declare module "error/no-action" {
/**
* @packageDocumentation
* @internal
*/
import { BaseError } from "error/base";
import { Command } from "command/index";
export class NoActionError extends BaseError {
constructor(cmd?: Command);
}
}
declare module "error/option-synopsis-syntax" {
/**
* @packageDocumentation
* @internal
*/
import { BaseError } from "error/base";
export class OptionSynopsisSyntaxError extends BaseError {
constructor(synopsis: string);
}
}
declare module "option/utils" {
import type { OptionSynopsis, ParserTypes } from "types";
export function getCleanNameFromNotation(str: string, camelCased?: boolean): string;
export function getDashedOpt(name: string): string;
export function isNumeric(n: string): boolean;
export function isOptionStr(str?: string): str is string;
export function isConcatenatedOpt(str: string): string[] | false;
export function isNegativeOpt(opt: string): boolean;
export function isOptArray(flag: ParserTypes | ParserTypes[]): flag is ParserTypes[];
export function formatOptName(name: string): string;
/**
* Parse a option synopsis
*
* @example
* parseSynopsis("-f, --file ")
* // Returns...
* {
* longName: 'file',
* longNotation: '--file',
* shortNotation: '-f',
* shortName: 'f'
* valueType: 0, // 0 = optional, 1 = required, 2 = no value
* variadic: false
* name: 'file'
* notation: '--file' // either the long or short notation
* }
*
* @param synopsis
* @ignore
*/
export function parseOptionSynopsis(synopsis: string): OptionSynopsis;
}
declare module "validator/utils" {
/**
* @packageDocumentation
* @internal
*/
import type { Validator } from "types";
import { Argument, Option } from "types";
export function isCaporalValidator(validator: Validator | undefined): validator is number;
export function isNumericValidator(validator: Validator | undefined): boolean;
export function isStringValidator(validator: Validator | undefined): boolean;
export function isBoolValidator(validator: Validator | undefined): boolean;
export function isArrayValidator(validator: Validator | undefined): boolean;
export function checkValidator(validator: Validator | undefined): void;
export function getTypeHint(obj: Argument | Option): string | undefined;
}
declare module "help/types" {
/**
* @packageDocumentation
* @module caporal/types
*/
import { Command } from "command/index";
import { Program } from "program/index";
import chalk from "chalk";
import { colorize } from "utils/colorize";
import { buildTable } from "help/utils";
import type { GlobalOptions } from "types";
export interface CustomizedHelpOpts {
/**
* Name of the section to be added in help.
*/
sectionName: string;
/**
* Enable or disable the automatic coloration of text.
*/
colorize: boolean;
}
export interface CustomizedHelp {
/**
* Various display options.
*/
options: CustomizedHelpOpts;
/**
* Help text. Padding of the text is automatically handled for you.
*/
text: string;
}
export type CustomizedHelpMap = Map;
export interface Template {
(ctx: TemplateContext): Promise | string;
}
export interface TemplateFunction {
(name: string, ctx: TemplateContext): Promise | string;
}
export interface TemplateContext {
prog: Program;
cmd?: Command;
customHelp: CustomizedHelpMap;
globalOptions: GlobalOptions;
chalk: typeof chalk;
colorize: typeof colorize;
tpl: TemplateFunction;
table: typeof buildTable;
indent: (str: string) => string;
eol: string;
eol2: string;
eol3: string;
spaces: string;
}
}
declare module "help/utils" {
import type { TemplateContext } from "help/types";
import type { Option, Argument } from "types";
import type { Command } from "command/index";
export function buildTable(data: string[][], options?: {}): string;
export function getDefaultValueHint(obj: Argument | Option): string | undefined;
export function getOptionsTable(options: Option[], ctx: TemplateContext, title?: string): string;
export function getArgumentsTable(args: Argument[], ctx: TemplateContext, title?: string): string;
export function getCommandsTable(commands: Command[], ctx: TemplateContext, title?: string): string;
}
declare module "help/templates/command" {
/**
* @packageDocumentation
* @internal
*/
import type { Template } from "help/types";
export const command: Template;
}
declare module "help/templates/header" {
/**
* @packageDocumentation
* @internal
*/
import type { Template } from "help/types";
export const header: Template;
}
declare module "help/templates/program" {
/**
* @packageDocumentation
* @internal
*/
import type { Template } from "help/types";
export const program: Template;
}
declare module "help/templates/usage" {
/**
* @packageDocumentation
* @internal
*/
import type { Template } from "help/types";
export const usage: Template;
}
declare module "help/templates/custom" {
/**
* @packageDocumentation
* @internal
*/
import type { Template } from "help/types";
export const custom: Template;
}
declare module "help/templates/index" {
/**
* @packageDocumentation
* @internal
*/
export * from "help/templates/command";
export * from "help/templates/header";
export * from "help/templates/program";
export * from "help/templates/usage";
export * from "help/templates/custom";
}
declare module "help/index" {
/**
* @packageDocumentation
* @module caporal/help
*/
import { Command } from "command/index";
import { Program } from "program/index";
import { CustomizedHelpOpts, TemplateContext, Template } from "help/types";
/**
* Customize the help
*
* @param obj
* @param text
* @param options
* @internal
*/
export function customizeHelp(obj: Command | Program, text: string, options: Partial): void;
/**
* Register a new help template
*
* @param name Template name
* @param template Template function
*
*/
export function registerTemplate(name: string, template: Template): Map;
/**
* Helper to be used to call templates from within templates
*
* @param name Template name
* @param ctx Execution context
* @internal
*/
export function tpl(name: string, ctx: TemplateContext): Promise;
/**
* @internal
* @param program
* @param command
*/
export function getContext(program: Program, command?: Command): TemplateContext;
/**
* Return the help text
*
* @param program Program instance
* @param command Command instance, if any
* @internal
*/
export function getHelp(program: Program, command?: Command): Promise;
}
declare module "parser/index" {
import type { ParserOptions, ParserResult } from "types";
/**
* Parse a line
*
* @param line Line to be parsed
* @param options Parser options
* @internal
*/
export function parseLine(line: string, options?: Partial): ParserResult;
/**
* Parse command line arguments
*
* @param options Parser options
* @param argv command line arguments array (a.k.a. "argv")
*/
export function parseArgv(options?: Partial, argv?: string[]): ParserResult;
}
declare module "validator/regexp" {
/**
* @packageDocumentation
* @internal
*/
import type { ParserTypes, Argument, Option } from "types";
/**
* Validate using a RegExp
*
* @param validator
* @param value
* @ignore
*/
export function validateWithRegExp(validator: RegExp, value: ParserTypes | ParserTypes[], context: Argument | Option): ParserTypes | ParserTypes[];
}
declare module "validator/array" {
/**
* @packageDocumentation
* @internal
*/
import type { ParserTypes, Argument, Option } from "types";
/**
* Validate using an array of valid values.
*
* @param validator
* @param value
* @ignore
*/
export function validateWithArray(validator: ParserTypes[], value: ParserTypes | ParserTypes[], context: Argument | Option): ParserTypes | ParserTypes[];
}
declare module "validator/function" {
/**
* @packageDocumentation
* @internal
*/
import type { ParserTypes, FunctionValidator, Argument, Option } from "types";
export function validateWithFunction(validator: FunctionValidator, value: ParserTypes | ParserTypes[], context: Argument | Option): Promise;
}
declare module "validator/caporal" {
/**
* @packageDocumentation
* @internal
*/
import type { ParserTypes, Argument, Option } from "types";
import { CaporalValidator } from "types";
export { CaporalValidator };
export function validateWithCaporal(validator: CaporalValidator, value: ParserTypes | ParserTypes[], context: Argument | Option, skipArrayValidation?: boolean): ParserTypes | ParserTypes[];
/**
* The string validator actually just cast the value to string
*
* @param value
* @ignore
*/
export function validateBoolFlag(value: ParserTypes, context: Argument | Option): boolean;
export function validateNumericFlag(validator: number, value: ParserTypes, context: Argument | Option): number;
export function validateArrayFlag(validator: number, value: ParserTypes | ParserTypes[], context: Argument | Option): ParserTypes | ParserTypes[];
/**
* The string validator actually just cast the value to string
*
* @param value
* @ignore
*/
export function validateStringFlag(value: ParserTypes | ParserTypes[]): string;
}
declare module "validator/validate" {
/**
* @packageDocumentation
* @internal
*/
import type { Validator, Promisable, ParsedOption, ParsedArgument, Argument, Option } from "types";
export function validate(value: ParsedOption | ParsedArgument, validator: Validator, context: Argument | Option): Promisable;
}
declare module "argument/find" {
/**
* @packageDocumentation
* @internal
*/
import type { Argument } from "types";
import type { Command } from "command/index";
export function findArgument(cmd: Command, name: string): Argument | undefined;
}
declare module "argument/validate" {
import { BaseError } from "error/index";
import type { ArgumentsRange, ParsedArguments, ParsedArgumentsObject } from "types";
import type { Command } from "command/index";
/**
* Get the number of required argument for a given command
*
* @param cmd
*/
export function getRequiredArgsCount(cmd: Command): number;
export function getArgsObjectFromArray(cmd: Command, args: ParsedArguments): ParsedArgumentsObject;
/**
* Check if the given command has at leat one variadic argument
*
* @param cmd
*/
export function hasVariadicArgument(cmd: Command): boolean;
export function getArgsRange(cmd: Command): ArgumentsRange;
export function checkRequiredArgs(cmd: Command, args: ParsedArgumentsObject, parsedArgv: ParsedArguments): BaseError[];
export function removeCommandFromArgs(cmd: Command, args: ParsedArguments): ParsedArguments;
interface ArgsValidationResult {
args: ParsedArgumentsObject;
errors: BaseError[];
}
/**
*
* @param cmd
* @param parsedArgv
*
* @todo Bugs:
*
*
* ts-node examples/pizza/pizza.ts cancel my-order jhazd hazd
*
* -> result ok, should be too many arguments
*
*/
export function validateArgs(cmd: Command, parsedArgv: ParsedArguments): Promise;
}
declare module "command/import" {
/**
* @packageDocumentation
* @internal
*/
import { CommandCreator } from "types";
export function importCommand(file: string): Promise;
}
declare module "command/find" {
/**
* @packageDocumentation
* @internal
*/
import type { Program } from "program/index";
import type { Command } from "command/index";
export function findCommand(program: Program, argv: string[]): Promise;
}
declare module "autocomplete/types" {
/**
* @packageDocumentation
* @module caporal/types
*/
import type { Argument, Option, Promisable, ParserResult } from "types";
import type tabtab from "tabtab";
import type { Command } from "command/index";
import type { Program } from "program/index";
export interface CompletionItem {
name: string;
description: string;
}
export interface Completer {
(ctx: CompletionContext): Promisable<(string | CompletionItem)[]>;
}
export interface CompletionContext {
program: Program;
currentCmd?: Command;
compEnv: tabtab.TabtabEnv;
parserResult: ParserResult;
lastPartIsOpt: boolean;
lastPartIsKnownOpt: boolean;
currentOpt?: Option;
}
export type Completions = Map;
}
declare module "autocomplete/index" {
import { Program } from "program/index";
import { Argument, Option } from "types";
import { Completer, CompletionItem } from "autocomplete/types";
/**
* Register a completion handler
*
* @param {Argument|Option} arg_or_opt argument or option to complete
* @param {Function} completer
*/
export function registerCompletion(argOrOpt: Argument | Option, completer: Completer): void;
export function installCompletion(program: Program): Promise;
export function uninstallCompletion(program: Program): Promise;
/**
* Called by tabtab
*/
export function complete(program: Program, { env, argv }?: {
env: NodeJS.ProcessEnv;
argv: string[];
}): Promise;
}
declare module "option/index" {
/**
* @packageDocumentation
* @module caporal/option
*/
import { Option, CreateOptionProgramOpts, CreateOptionCommandOpts, Action, GlobalOptions, ParserProcessedResult } from "types";
import type { Command } from "command/index";
import type { Program } from "program/index";
/**
* Create an Option object
*
* @internal
* @param synopsis
* @param description
* @param options
*/
export function createOption(synopsis: string, description: string, options?: CreateOptionProgramOpts | CreateOptionCommandOpts): Option;
export { showHelp };
/**
* Display help. Return false to prevent further processing.
*
* @internal
*/
const showHelp: Action;
/**
* Get the list of registered global flags
*
* @internal
*/
export function getGlobalOptions(): GlobalOptions;
export function resetGlobalOptions(): GlobalOptions;
/**
* Disable a global option
*
* @param name Can be the option short/long name or notation
*/
export function disableGlobalOption(name: string): boolean;
/**
* Add a global option to the program.
* A global option is available at the program level,
* and associated with one given {@link Action}.
*
* @param a {@link Option} instance, for example created using {@link createOption()}
*/
export function addGlobalOption(opt: Option, action?: Action): GlobalOptions;
/**
* Process global options, if any
* @internal
*/
export function processGlobalOptions(parsed: ParserProcessedResult, program: Program, command?: Command): Promise;
/**
* Find a global Option action from the option name (short or long)
*
* @param name Short or long name
* @internal
*/
export function findGlobalOptAction(name: string): Action | undefined;
/**
* Find a global Option by it's name (short or long)
*
* @param name Short or long name
* @internal
*/
export function findGlobalOption(name: string): Option | undefined;
export function isOptionObject(obj: unknown): obj is Option;
}
declare module "utils/levenshtein" {
/**
* @packageDocumentation
* @internal
*/
export function levenshtein(a: string, b: string): number;
}
declare module "utils/suggest" {
/**
* Get autocomplete suggestions
*
* @param {String} input - User input
* @param {String[]} possibilities - Possibilities to retrieve suggestions from
*/
export function getSuggestions(input: string, possibilities: string[]): string[];
/**
* Make diff bolder in a string
*
* @param from original string
* @param to target string
*/
export function boldDiffString(from: string, to: string): string;
}
declare module "error/unknown-option" {
/**
* @packageDocumentation
* @internal
*/
import { BaseError } from "error/base";
import type { Command } from "command/index";
/**
* @todo Rewrite
*/
export class UnknownOptionError extends BaseError {
constructor(flag: string, command: Command);
}
}
declare module "error/unknown-command" {
/**
* @packageDocumentation
* @internal
*/
import { BaseError } from "error/base";
import type { Program } from "program/index";
/**
* @todo Rewrite
*/
export class UnknownOrUnspecifiedCommandError extends BaseError {
constructor(program: Program, command?: string);
}
}
declare module "error/validation" {
import { BaseError } from "error/base";
import { Validator, ParserTypes, Argument, Option } from "types";
interface ValidationErrorParameters {
value: ParserTypes | ParserTypes[];
error?: Error | string;
validator: Validator;
context: Argument | Option;
}
export class ValidationError extends BaseError {
constructor({ value, error, validator, context }: ValidationErrorParameters);
}
}
declare module "error/too-many-arguments" {
/**
* @packageDocumentation
* @internal
*/
import { BaseError } from "error/base";
import { ArgumentsRange } from "types";
import { Command } from "command/index";
export class TooManyArgumentsError extends BaseError {
constructor(cmd: Command, range: ArgumentsRange, argsCount: number);
}
}
declare module "error/index" {
/**
* @packageDocumentation
* @internal
*/
export * from "error/action";
export * from "error/base";
export * from "error/fatal";
export * from "error/invalid-validator";
export * from "error/missing-argument";
export * from "error/missing-flag";
export * from "error/multi-validation";
export * from "error/no-action";
export * from "error/option-synopsis-syntax";
export * from "error/unknown-option";
export * from "error/unknown-command";
export * from "error/validation";
export * from "error/too-many-arguments";
}
declare module "types" {
/**
* List of Caporal type aliases.
*
* @packageDocumentation
* @module caporal/types
*/
import { Logger as WinstonLogger } from "winston";
import { Program } from "program/index";
import { Command } from "command/index";
import { BaseError } from "error/index";
/**
* The Caporal logger interface. It extends the [Winston](https://github.com/winstonjs/winston) Logger interface
* and adds the following properties & methods.
* @noInheritDoc
*/
export interface Logger extends WinstonLogger {
/**
* Allow to force disabling colors.
*/
disableColors(): void;
/**
* Tells Caporal if colors are enabled or not.
*/
colorsEnabled: boolean;
}
export type GlobalOptions = Map