/** * @file Help * @module kronk/lib/Help */ import type HelpTextSection from '#interfaces/help-text-section'; import { type Colors } from '@flex-development/colors'; import type { Argument, Command, ExampleInfo, Helpable, HelpTextOptions, List, Numeric, Option, Parseable, UsageInfo } from '@flex-development/kronk'; import { type Config as WrapConfig, type Options as WrapOptions } from '@flex-development/string-wrap'; /** * Help text utility. * * @class */ declare class Help { #private; /** * An object containing methods for styling text. * * @see {@linkcode Colors} * * @protected * @instance * @member {Colors} style */ protected ansi: Colors; /** * The maximum number of columns to output. * * @default 110 * * @protected * @instance * @member {number} columns */ protected columns: number; /** * The character, or characters, used to mark the end of a line. * * @default '\n' * * @protected * @instance * @member {string} eol */ protected eol: string; /** * The example marker to use. * * @default '$' * * @protected * @instance * @member {string} exampleMarker */ protected exampleMarker: string; /** * Whether to show global options. * * @default true * * @protected * @instance * @member {boolean | null | undefined} showGlobalOptions */ protected showGlobalOptions?: boolean | null | undefined; /** * Create a new help text utility. * * @see {@linkcode HelpTextOptions} * * @param {HelpTextOptions | null | undefined} [options] * Options for formating help text */ constructor(options?: HelpTextOptions | null | undefined); /** * Check if a value is a boolean or stringified boolean. * * @protected * @static * * @param {unknown} value * The thing to check * @return {value is boolean | 'false' | 'true'} * `true` if `value` is boolean or stringified boolean, `false` otherwise */ protected static isBoolean(value: unknown): value is boolean | 'false' | 'true'; /** * Check if a value is a number or numeric. * * @see {@linkcode Numeric} * * @protected * @static * * @param {unknown} value * The thing to check * @return {value is Numeric | number} * `true` if `value` is number or numeric, `false` otherwise */ protected static isNumber(value: unknown): value is Numeric | number; /** * Get the list of aliases. * * @see {@linkcode Command} * @see {@linkcode HelpTextSection} * * @protected * @instance * * @param {Command} command * The command * @return {HelpTextSection} * Help text section */ protected aliases(command: Command): HelpTextSection; /** * Pretty print an argument. * * @see {@linkcode Argument} * @see {@linkcode Command} * * @protected * @instance * * @param {Argument} argument * The argument * @param {Command} command * The parent command * @return {string} * The formatted argument */ protected argument(argument: Argument, command: Command): string; /** * Get a description to show in the list of arguments. * * @see {@linkcode Argument} * * @protected * @instance * * @param {Argument} argument * The argument * @return {string} * The formatted description */ protected argumentDescription(argument: Argument): string; /** * Get a term to show in the list of arguments. * * @see {@linkcode Argument} * * @protected * @instance * * @param {Argument} argument * The argument * @return {string} * The formatted term */ protected argumentTerm(argument: Argument): string; /** * Get the list of arguments. * * @see {@linkcode Command} * @see {@linkcode HelpTextSection} * * @protected * @instance * * @param {Command} command * The command * @return {HelpTextSection} * Help text section */ protected arguments(command: Command): HelpTextSection; /** * Format a parse candidate choice. * * @protected * @instance * * @param {string} choice * One of the allowed candidate choices * @return {string} * The formatted choice */ protected choice(choice: string): string; /** * Get a list of parse candidate choices. * * @see {@linkcode Parseable} * * @protected * @instance * * @param {Parseable} candidate * The parse candidate * @return {string | null} * The formatted list of allowed candidate choices */ protected choices(candidate: Parseable): string | null; /** * Compare two strings. * * @see {@linkcode Intl.CollatorOptions} * @see {@linkcode Intl.LocalesArgument} * * @protected * @instance * * @param {string} a * The target string * @param {string} b * The string to compare to the target string * @param {Intl.LocalesArgument | null | undefined} [locale] * A locale string or array of locale strings containing * one or more language or locale tags * @param {Intl.CollatorOptions | null | undefined} [opts] * Comparision options * @param {'false' | 'lower' | 'upper' | undefined} [opts.caseFirst='upper'] * Case comparision options * @return {number} * The comparison result */ protected compare(a: string, b: string, locale?: Intl.LocalesArgument | null | undefined, opts?: Intl.CollatorOptions | null | undefined): number; /** * Compare two subcommands. * * @see {@linkcode Command} * * @protected * @instance * * @param {Command} a * The first subcommand * @param {Command} b * The subcommand to compare to `a` * @return {number} * The comparison result */ protected compareCommand(a: Command, b: Command): number; /** * Compare two options. * * @see {@linkcode Option} * * @protected * @instance * * @param {Option} a * The first option * @param {Option} b * The option to compare to `a` * @return {number} * The comparison result */ protected compareOption(a: Option, b: Option): number; /** * Format a conflicting option. * * @protected * @instance * * @param {string} conflict * The name of the conflicting option * @return {string} * The formatted conflicting option name */ protected conflict(conflict: string): string; /** * Get the list of conflicting options to show in an option description. * * @see {@linkcode Option} * * @protected * @instance * * @param {Option} option * The option * @return {string | null} * The formatted list of conflicting options */ protected conflicts(option: Option): string | null; /** * Get the default value configuration * to show in a parse candidate description. * * @see {@linkcode Parseable} * * @protected * @instance * * @param {Parseable} candidate * The parse candidate * @return {string | undefined} * The formatted default value configuration */ protected default(candidate: Parseable): string | undefined; /** * Format a default value. * * @protected * @instance * * @param {unknown} value * The default value * @return {string} * The formatted default value */ protected defaultValue(value: unknown): string; /** * Format a dependee option. * * @protected * @instance * * @param {string} dependee * The option reference * @return {string} * The formatted dependee option */ protected dependee(dependee: string): string; /** * Get the list of dependee options to show in an option description. * * @see {@linkcode Option} * * @protected * @instance * * @param {Option} option * The option * @return {string | null} * The formatted list of dependee options */ protected depends(option: Option): string | null; /** * Get the list of environment variables to show in an option description. * * @see {@linkcode Option} * * @protected * @instance * * @param {Option} option * The option * @return {string | null} * The formatted list of environment variable names */ protected env(option: Option): string | null; /** * Format an environment variable name. * * @protected * @instance * * @param {string} name * The environment variable name * @return {string} * The formatted environment variable name */ protected environment(name: string): string; /** * Pretty print an example. * * @see {@linkcode Command} * @see {@linkcode ExampleInfo} * * @protected * @instance * * @param {ExampleInfo} example * The example info * @param {Command} command * The parent command * @return {string} * The formatted example */ protected example(example: ExampleInfo, command: Command): string; /** * Get a term to show in the list of arguments. * * @see {@linkcode Command} * @see {@linkcode ExampleInfo} * * @protected * @instance * * @param {ExampleInfo} info * The example info * @param {Command} command * The command * @return {string} * The formatted term */ protected exampleTerm(info: ExampleInfo, command: Command): string; /** * Get the list of examples. * * @see {@linkcode Command} * @see {@linkcode HelpTextSection} * * @protected * @instance * * @param {Command} command * The command * @return {HelpTextSection} * Help text section */ protected examples(command: Command): HelpTextSection; /** * Filter and join a `list`. * * @see {@linkcode List} * * @protected * @instance * * @param {List} list * The list to filter * @param {string | null | undefined} [separator] * The string used to separate one element of `list` from the next in the * resulting string. If omitted, list items are separated with a space (` `). * @return {string} * Sifted and joined `list` */ protected filterJoin(list: List, separator?: string | null | undefined): string; /** * Pretty print a global option. * * @see {@linkcode Command} * @see {@linkcode Option} * * @protected * @instance * * @param {Option} option * The option * @param {Command} command * The parent command * @return {string} * The formatted option */ protected globalOption(option: Option, command: Command): string; /** * Get the description to show in the list of global options. * * @see {@linkcode Option} * * @protected * @instance * * @param {Option} option * The option * @return {string} * The formatted description */ protected globalOptionDescription(option: Option): string; /** * Get the term to show in the list of global options. * * @see {@linkcode Option} * * @protected * @instance * * @param {Option} option * The option * @return {string} * The formatted term */ protected globalOptionTerm(option: Option): string; /** * Get a list of global options. * * @see {@linkcode Command} * @see {@linkcode HelpTextSection} * * @protected * @instance * * @param {Command} command * The command * @return {HelpTextSection} * Help text section */ protected globalOptions(command: Command): HelpTextSection; /** * Get the help text header. * * @see {@linkcode Command} * @see {@linkcode HelpTextSection} * * @protected * @instance * * @param {Command} command * The command * @return {HelpTextSection} * Help text section */ protected header(command: Command): HelpTextSection; /** * Highlight inline code in a string. * * @protected * @instance * * @param {string} string * The target string * @return {string} * The string with inline code highlighted */ protected inlineCode(string: string): string; /** * Format an item, consisting of a term, * description, and optional description details. * * @protected * @instance * * @param {string} term * The item term * @param {number} longestTermWidth * The width of the longest term * @param {false | string | null | undefined} [description] * The item description * @param {(false | string | null | undefined)[]} [details] * A list of description details * @return {string} * The formatted item */ protected item(term: string, longestTermWidth: number, description?: false | string | null | undefined, ...details: (false | string | null | undefined)[]): string; /** * Get the width of the longest argument term. * * @see {@linkcode Command} * * @protected * @instance * * @param {Command} command * The command * @return {number} * The width of the longest visible argument term */ protected longestArgumentTerm(command: Command): number; /** * Get the width of the longest example term. * * @see {@linkcode Command} * * @protected * @instance * * @param {Command} command * The command * @return {number} * The width of the longest example term */ protected longestExampleTerm(command: Command): number; /** * Get the width of the longest global option term. * * @see {@linkcode Command} * * @protected * @instance * * @param {Command} command * The command * @return {number} * The width of the longest visible global option term */ protected longestGlobalOptionTerm(command: Command): number; /** * Get the width of the longest option term. * * @see {@linkcode Command} * * @protected * @instance * * @param {Command} command * The command * @return {number} * The width of the longest visible option term */ protected longestOptionTerm(command: Command): number; /** * Get the width of the longest subcommand term. * * @see {@linkcode Command} * * @protected * @instance * * @param {Command} command * The command * @return {number} * The width of the longest visible subcommand term */ protected longestSubcommandTerm(command: Command): number; /** * Get the width of the longest argument, option, or subcommand term. * * @see {@linkcode Command} * * @protected * @instance * * @param {Command} command * The command * @return {number} * The width of the longest term */ protected longestTerm(command: Command): number; /** * Append new lines to a string. * * @protected * @instance * * @param {string | null | undefined} [string=chars.empty] * The string to append line breaks to * @param {number | string | null | undefined} [count=1] * The number of line breaks to append * @return {string} * The string with line breaks appended */ protected newline(string?: string | null | undefined, count?: number | string | null | undefined): string; /** * Pretty print an option. * * @see {@linkcode Command} * @see {@linkcode Option} * * @protected * @instance * * @param {Option} option * The option * @param {Command} command * The parent command * @return {string} * The formatted option */ protected option(option: Option, command: Command): string; /** * Get the description to show in the list of options. * * @see {@linkcode Option} * * @protected * @instance * * @param {Option} option * The option * @return {string} * The formatted description */ protected optionDescription(option: Option): string; /** * Get the term to show in the list of options. * * @see {@linkcode Option} * * @protected * @instance * * @param {Option} option * The option * @return {string} * The formatted term */ protected optionTerm(option: Option): string; /** * Get a list of options. * * @see {@linkcode Command} * @see {@linkcode HelpTextSection} * * @protected * @instance * * @param {Command} command * The command * @return {HelpTextSection} * Help text section */ protected options(command: Command): HelpTextSection; /** * Prepare the help text context. * * @see {@linkcode HelpTextOptions} * * @public * @instance * * @param {HelpTextOptions | null | undefined} [options] * Options for formating help text * @return {this} * `this` help text utility */ prepare(options?: HelpTextOptions | null | undefined): this; /** * Pretty print an option preset. * * @see {@linkcode Option} * * @protected * @instance * * @param {Option} option * The option * @return {string | null} * The formatted preset */ protected preset(option: Option): string | null; /** * Format a preset option value. * * @protected * @instance * * @param {string} value * The preset value * @return {string} * The formatted preset value */ protected presetValue(value: string): string; /** * Wrap a string in quotes. * * @protected * @instance * * @param {string} string * The string to wrap * @param {string | null | undefined} [char='\''] * The quotation character to use * @return {string} * The quoted `string` */ protected quote(string: string, char?: string | null | undefined): string; /** * Format a list of sections. * * @see {@linkcode HelpTextSection} * @see {@linkcode List} * * @protected * @instance * * @param {List} list * The sections to format * @return {string} * The formatted list of sections */ protected sections(list: List): string; /** * Get a description to show in the list of subcommands. * * @see {@linkcode Command} * * @protected * @instance * * @param {Command} subcommand * The subcommand * @return {string} * The formatted description */ protected subcommandDescription(subcommand: Command): string; /** * Get the term to show in the list of subcommands. * * @see {@linkcode Command} * * @protected * @instance * * @param {Command} subcommand * The subcommand * @return {string} * The formatted term */ protected subcommandTerm(subcommand: Command): string; /** * Get the list of subcommands. * * @see {@linkcode Command} * @see {@linkcode HelpTextSection} * * @protected * @instance * * @param {Command} command * The command * @return {HelpTextSection} * Help text section */ protected subcommands(command: Command): HelpTextSection; /** * Generate help text for a command. * * @see {@linkcode Command} * * @public * @instance * * @param {Command} command * The command * @return {string} * Formatted help text */ text(command: Command): string; /** * Format a title. * * @protected * @instance * * @param {string} title * The title to format * @return {string} * Formatted title */ protected title(title: string): string; /** * Get a command usage description. * * @see {@linkcode Command} * * @protected * @instance * * @param {Command} command * The command * @return {string} * The formatted usage descriptor */ protected usage(command: Command): string; /** * Format a usage term. * * @see {@linkcode UsageInfo} * * @protected * @instance * * @param {string} term * The term to format * @param {keyof UsageInfo} type * The type of term to format * @return {string} * The formatted term */ protected usageTerm(term: string, type: keyof UsageInfo): string; /** * Check if a help text candidate should be shown in the help text. * * @see {@linkcode Helpable} * * @protected * @instance * * @param {Argument | Command | Option} candidate * The help text candidate to check * @return {boolean} * `true` if `candidate` should be displayed in help text, `false` otherwise */ protected visible(candidate: Helpable): boolean; /** * Get a list of visible arguments. * * @see {@linkcode Argument} * @see {@linkcode Command} * * @protected * @instance * * @param {Command} command * The command * @return {ReadonlyArray} * List of visible arguments */ protected visibleArguments(command: Command): readonly Argument[]; /** * Get a sorted list of visible subcommands. * * @see {@linkcode Command} * * @protected * @instance * * @param {Command} command * The command * @return {ReadonlyArray} * List of visible subcommands */ protected visibleCommands(command: Command): readonly Command[]; /** * Get a sorted list of visible global options. * * > 👉 **Note**: If visible, the `help` and `version` options will **always** * > be the last two options. * * @see {@linkcode Command} * @see {@linkcode Option} * * @protected * @instance * * @param {Command} command * The command * @return {ReadonlyArray