UNPKG

@clerc/plugin-help

Version:
135 lines (134 loc) 3.28 kB
import { Plugin } from "@clerc/core"; import { FlagDefaultValue, TypeValue } from "@clerc/parser"; //#region src/types.d.ts interface Formatters { formatTypeValue: (type: TypeValue) => string; formatFlagDefault: <T>(value: FlagDefaultValue<T>) => string; } /** * A group definition as a tuple of [key, displayName]. The key is used in help * options to assign items to groups. The displayName is shown in the help * output. */ type GroupDefinition = [key: string, name: string]; /** * Options for defining groups in help output. */ interface GroupsOptions { /** * Groups for commands. Each group is defined as `[key, name]`. */ commands?: GroupDefinition[]; /** * Groups for command-specific flags. Each group is defined as `[key, name]`. */ flags?: GroupDefinition[]; /** * Groups for global flags. Each group is defined as `[key, name]`. */ globalFlags?: GroupDefinition[]; } //#endregion //#region src/formatters.d.ts declare const defaultFormatters: Formatters; //#endregion //#region src/index.d.ts interface HelpOptions { /** * The group this item belongs to. The group must be defined in the `groups` * option of `helpPlugin()`. */ group?: string; } interface CommandHelpOptions extends HelpOptions { /** * Whether to show the command in help output. * * @default true */ show?: boolean; /** * Notes to show in the help output. */ notes?: string[]; /** * Examples to show in the help output. Each example is a tuple of `[command, * description]`. */ examples?: [string, string][]; } declare module "@clerc/core" { interface CommandCustomOptions { /** * Help options for the command. */ help?: CommandHelpOptions; } interface FlagCustomOptions { /** * Help options for the flag. */ help?: HelpOptions; } } interface HelpPluginOptions { /** * Whether to register the `help` command. * * @default true */ command?: boolean; /** * Whether to register the `--help` global flag. * * @default true */ flag?: boolean; /** * Whether to show help when no command is specified. * * @default true */ showHelpWhenNoCommandSpecified?: boolean; /** * Notes to show in the help output. */ notes?: string[]; /** * Examples to show in the help output. Each example is a tuple of `[command, * description]`. */ examples?: [string, string][]; /** * Header to show before the help output. */ header?: string; /** * Footer to show after the help output. */ footer?: string; /** * Custom formatters for rendering help. */ formatters?: Partial<Formatters>; /** * Group definitions for commands and flags. Groups allow organizing commands * and flags into logical sections in help output. Each group is defined as * `[key, name]` where `key` is the identifier used in help options and `name` * is the display name shown in help output. */ groups?: GroupsOptions; } declare const helpPlugin: ({ command, flag, showHelpWhenNoCommandSpecified, notes, examples, header, footer, formatters, groups }?: HelpPluginOptions) => Plugin; //#endregion export { CommandHelpOptions, type GroupDefinition, type GroupsOptions, HelpOptions, HelpPluginOptions, defaultFormatters, helpPlugin };