burgee/commander/v14
Every export of burgee/commander/v14, with its signature and doc comment: Command, program, createCommand, Argument, humanReadableArgName, useColor and 8 more, plus 16 types.
burgee/commander/v14 — burgee/commander for a program on commander 14, the entry
burgee migrate writes for one (previous-majors R1, R6). The one difference commander
14.0.3's own suite measures: its excess-arguments message stops at the count, where 15
names the surplus arguments. Kept out of command.ts, so a 15 program bundles none of it.
import { Command, program, createCommand, … } from 'burgee/commander/v14';Functions
humanReadableArgName
<name> / [name] / <name...> for usage strings.
function humanReadableArgName(arg: Argument): string;| Parameter | Type |
|---|---|
arg | Argument |
Returns string
useColor
The common colour conventions: NO_COLOR and FORCE_COLOR=0/false disable, FORCE_COLOR and CLICOLOR_FORCE enable, otherwise undecided (the stream's TTY-ness decides).
function useColor(): boolean | undefined;Returns boolean \| undefined
Classes
Argument
class Argument {
description: string;
variadic: boolean;
parseArg: ParseArg | undefined;
defaultValue: unknown;
defaultValueDescription: string | undefined;
argChoices: string[] | undefined;
required: boolean;
_name: string;
/** `<required>`, `[optional]`, bare = required; a trailing `...` makes it variadic. */
constructor(name: string, description?: string);
name(): string;
_collectValue(value: unknown, previous: unknown): unknown[];
default(value: unknown, description?: string): this;
argParser(fn?: ParseArg): this;
choices(values: readonly string[]): this;
argRequired(): this;
argOptional(): this;
}Command
class Command extends Current {
createCommand(name?: string): Command;
_excessArguments(args: string[]): void;
}CommanderError
commander's error classes, byte-for-byte in shape: code, exitCode, nestedError.
class CommanderError extends Error {
code: string;
exitCode: number;
nestedError: unknown;
constructor(exitCode: number, code: string, message?: string);
}DualOptions
--build and --no-build share one value. This works out which of the pair a
value (probably) came from, so implied values are only applied for the right one.
class DualOptions {
positiveOptions: Map<string, Option>;
negativeOptions: Map<string, Option>;
dualOptions: Set<string>;
constructor(options: Option[]);
valueFromOption(value: unknown, option: Option): boolean;
}Help
Methods are static in style so a subclass, or plain functions via configureHelp, can override them.
class Help {
helpWidth: number | undefined;
minWidthToWrap: number;
sortSubcommands: boolean;
sortOptions: boolean;
showGlobalOptions: boolean;
/** Called after `configureHelp` overrides are applied and just before `formatHelp`. */
prepareContext(contextOptions: HelpContext): void;
visibleCommands(cmd: Command): Command[];
compareOptions(a: Option, b: Option): number;
visibleOptions(cmd: Command): Option[];
visibleGlobalOptions(cmd: Command): Option[];
visibleArguments(cmd: Command): Argument[];
subcommandTerm(cmd: Command): string;
optionTerm(option: Option): string;
argumentTerm(argument: Argument): string;
longestSubcommandTermLength(cmd: Command, helper: Help): number;
longestOptionTermLength(cmd: Command, helper: Help): number;
longestGlobalOptionTermLength(cmd: Command, helper: Help): number;
longestArgumentTermLength(cmd: Command, helper: Help): number;
commandUsage(cmd: Command): string;
commandDescription(cmd: Command): string;
/** Summary, falling back to description for backwards compatibility. */
subcommandDescription(cmd: Command): string;
optionDescription(option: Option): string;
argumentDescription(argument: Argument): string;
formatItemList(heading: string, items: string[], helper: Help): string[];
/** Groups in order of first appearance among all items; members in order of the visible items. */
groupItems<T>(unsortedItems: T[], visibleItems: T[], getGroup: (item: T) => string): Map<string, T[]>;
formatHelp(cmd: Command, helper: Help): string;
/** Width ignoring ANSI escapes, for padding and wrapping. */
displayWidth(str: string): number;
styleTitle(str: string): string;
styleUsage(str: string): string;
styleCommandDescription(str: string): string;
styleOptionDescription(str: string): string;
styleSubcommandDescription(str: string): string;
styleArgumentDescription(str: string): string;
styleDescriptionText(str: string): string;
styleOptionTerm(str: string): string;
styleSubcommandTerm(str: string): string;
styleArgumentTerm(str: string): string;
styleOptionText(str: string): string;
styleArgumentText(str: string): string;
styleSubcommandText(str: string): string;
styleCommandText(str: string): string;
padWidth(cmd: Command, helper: Help): number;
/** Manually wrapped text: a line break followed by whitespace. */
preformatted(str: string): boolean;
/**
* Pad the term and wrap the description, indenting the following lines:
* TTT DDD DDDD
* DD DDD
*/
formatItem(term: string, termWidth: number, description: string, helper: Help): string;
/** Wrap at whitespace, preserving existing line breaks; skipped below `minWidthToWrap`. */
boxWrap(str: string, width: number): string;
}InvalidArgumentError
class InvalidArgumentError extends CommanderError {
constructor(message?: string);
}InvalidOptionArgumentError
class InvalidArgumentError extends CommanderError {
constructor(message?: string);
}Option
class Option {
flags: string;
description: string;
required: boolean;
optional: boolean;
variadic: boolean;
mandatory: boolean;
short: string | undefined;
long: string | undefined;
negate: boolean;
defaultValue: unknown;
defaultValueDescription: string | undefined;
presetArg: unknown;
envVar: string | undefined;
parseArg: ParseArg | undefined;
hidden: boolean;
argChoices: string[] | undefined;
conflictsWith: string[];
implied: Record<string, unknown> | undefined;
helpGroupHeading: string | undefined;
constructor(flags: string, description?: string);
default(value: unknown, description?: string): this;
/** Value used when the option appears without an option-argument. `parseArg` still runs. */
preset(arg: unknown): this;
conflicts(names: string | string[]): this;
/** Values implied for other options when this one is set and they are not. `parseArg` does not run on them. */
implies(impliedOptionValues: string | Record<string, unknown>): this;
env(name: string): this;
argParser(fn?: ParseArg): this;
makeOptionMandatory(mandatory?: boolean): this;
hideHelp(hide?: boolean): this;
_collectValue(value: unknown, previous: unknown): unknown[];
choices(values: readonly string[]): this;
name(): string;
/** camelCase key used on the options object; `--no-foo` shares `foo` with `--foo`. */
attributeName(): string;
helpGroup(heading: string): this;
is(arg: string): boolean;
/** Options are one of boolean, negated, required-argument or optional-argument. */
isBoolean(): boolean;
}Constants
createArgument
const createArgument: (name: string, description?: string) => Argument;createCommand
const createCommand: (name?: string) => Command;createOption
const createOption: (flags: string, description?: string) => Option;program
const program: Command;Interfaces
BurgeeParseOptions
burgee's additions: inject the streams and the exit, and get E1 exit codes back (T1).
interface BurgeeParseOptions extends ParseOptions {
stdout?: Writer;
stderr?: Writer;
exit?: (code: number) => void;
}CommandOptions
interface CommandOptions {
hidden?: boolean;
isDefault?: boolean;
/** @deprecated since v7, replaced by hidden */
noHelp?: boolean;
}ErrorOptions
interface ErrorOptions {
code?: string;
exitCode?: number;
}ExecutableCommandOptions
interface ExecutableCommandOptions extends CommandOptions {
executableFile?: string;
}HelpContext
interface HelpContext {
error?: boolean;
helpWidth?: number;
outputHasColors?: boolean;
}OutputContext
interface OutputContext {
error?: boolean;
}ParseOptions
interface ParseOptions {
from?: 'node' | 'electron' | 'user' | 'eval';
}ParseOptionsResult
.parseOptions()'s split of an argv into operands and unknown options.
interface ParseOptionsResult {
operands: string[];
unknown: string[];
}Types
AddHelpTextContext
type AddHelpTextContext = {
error: boolean;
command: Command;
};AddHelpTextPosition
type AddHelpTextPosition = 'beforeAll' | 'before' | 'after' | 'afterAll';HelpConfiguration
What .configureHelp() takes: any subset of Help's methods and settings.
type HelpConfiguration = Partial<Help>;HookEvent
type HookEvent = 'preSubcommand' | 'preAction' | 'postAction';HookListener
type HookListener = (thisCommand: Command, actionCommand: Command) => void | Promise<void>;OptionValues
commander's option-value types, as typings/index.d.ts declares them. any is
commander's choice and the point: program.opts().port is usable without a cast, and
opts<T>() narrows it — a program written against commander's types relies on both;
unknown here breaks every opts().x such a program reads.
type OptionValues = Record<string, any>;OptionValueSource
Where an option's value came from. A string, so an author can define their own; the known ones autocomplete.
type OptionValueSource = 'default' | 'config' | 'env' | 'cli' | 'implied' | (string & Record<never, never>) | undefined;OutputConfiguration
commander's OutputConfiguration: every member optional, because .configureOutput()
takes any subset of them and a typed program annotates exactly that subset. What
.configureOutput() hands back is the resolved, complete one.
type OutputConfiguration = Partial<ResolvedOutputConfiguration>;burgee/commander/extra-typings
burgee/commander/extra-typings is a drop-in for @commander-js/extra-typings: the same API, documented by @commander-js/extra-typings itself. Every name it exports, and where its reference lives.
burgee/meow
burgee/meow is a drop-in for meow: the same API, documented by meow itself. Every name it exports, and where its reference lives.