curtains
Version:
Build beautiful HTML presentations from Markdown with custom styling, containers, and keyboard navigation
4 lines • 2.15 MB
Source Map (JSON)
{
"version": 3,
"sources": ["../node_modules/commander/lib/error.js", "../node_modules/commander/lib/argument.js", "../node_modules/commander/lib/help.js", "../node_modules/commander/lib/option.js", "../node_modules/commander/lib/suggestSimilar.js", "../node_modules/commander/lib/command.js", "../node_modules/commander/index.js", "../node_modules/extend/index.js", "../src/libs/cli/main.ts", "../node_modules/commander/esm.mjs", "../src/libs/registry/registry.ts", "../src/libs/registry/helpers.ts", "../node_modules/zod/v4/classic/external.js", "../node_modules/zod/v4/core/index.js", "../node_modules/zod/v4/core/core.js", "../node_modules/zod/v4/core/util.js", "../node_modules/zod/v4/core/errors.js", "../node_modules/zod/v4/core/parse.js", "../node_modules/zod/v4/core/regexes.js", "../node_modules/zod/v4/core/checks.js", "../node_modules/zod/v4/core/doc.js", "../node_modules/zod/v4/core/versions.js", "../node_modules/zod/v4/core/schemas.js", "../node_modules/zod/v4/locales/index.js", "../node_modules/zod/v4/locales/ar.js", "../node_modules/zod/v4/locales/az.js", "../node_modules/zod/v4/locales/be.js", "../node_modules/zod/v4/locales/ca.js", "../node_modules/zod/v4/locales/cs.js", "../node_modules/zod/v4/locales/da.js", "../node_modules/zod/v4/locales/de.js", "../node_modules/zod/v4/locales/en.js", "../node_modules/zod/v4/locales/eo.js", "../node_modules/zod/v4/locales/es.js", "../node_modules/zod/v4/locales/fa.js", "../node_modules/zod/v4/locales/fi.js", "../node_modules/zod/v4/locales/fr.js", "../node_modules/zod/v4/locales/fr-CA.js", "../node_modules/zod/v4/locales/he.js", "../node_modules/zod/v4/locales/hu.js", "../node_modules/zod/v4/locales/id.js", "../node_modules/zod/v4/locales/is.js", "../node_modules/zod/v4/locales/it.js", "../node_modules/zod/v4/locales/ja.js", "../node_modules/zod/v4/locales/kh.js", "../node_modules/zod/v4/locales/ko.js", "../node_modules/zod/v4/locales/mk.js", "../node_modules/zod/v4/locales/ms.js", "../node_modules/zod/v4/locales/nl.js", "../node_modules/zod/v4/locales/no.js", "../node_modules/zod/v4/locales/ota.js", "../node_modules/zod/v4/locales/ps.js", "../node_modules/zod/v4/locales/pl.js", "../node_modules/zod/v4/locales/pt.js", "../node_modules/zod/v4/locales/ru.js", "../node_modules/zod/v4/locales/sl.js", "../node_modules/zod/v4/locales/sv.js", "../node_modules/zod/v4/locales/ta.js", "../node_modules/zod/v4/locales/th.js", "../node_modules/zod/v4/locales/tr.js", "../node_modules/zod/v4/locales/ua.js", "../node_modules/zod/v4/locales/ur.js", "../node_modules/zod/v4/locales/vi.js", "../node_modules/zod/v4/locales/zh-CN.js", "../node_modules/zod/v4/locales/zh-TW.js", "../node_modules/zod/v4/locales/yo.js", "../node_modules/zod/v4/core/registries.js", "../node_modules/zod/v4/core/api.js", "../node_modules/zod/v4/core/to-json-schema.js", "../node_modules/zod/v4/core/json-schema.js", "../node_modules/zod/v4/classic/iso.js", "../node_modules/zod/v4/classic/errors.js", "../node_modules/zod/v4/classic/parse.js", "../node_modules/zod/v4/classic/schemas.js", "../node_modules/zod/v4/classic/compat.js", "../node_modules/zod/v4/classic/coerce.js", "../node_modules/zod/index.js", "../src/libs/schemas/ast.ts", "../src/libs/schemas/parsers.ts", "../src/libs/schemas/transformers.ts", "../src/libs/schemas/stages.ts", "../src/libs/schemas/cli.ts", "../src/libs/schemas/registry.ts", "../src/libs/schemas/state.ts", "../src/libs/schemas/actions.ts", "../src/libs/registry/reducer.ts", "../src/libs/registry/store.ts", "../src/libs/registry/middleware.ts", "../src/libs/coordinator/handlers.ts", "../node_modules/mdast-util-to-string/lib/index.js", "../node_modules/ccount/index.js", "../node_modules/micromark-util-character/index.js", "../node_modules/mdast-util-find-and-replace/node_modules/escape-string-regexp/index.js", "../node_modules/unist-util-is/lib/index.js", "../node_modules/unist-util-visit-parents/lib/color.node.js", "../node_modules/unist-util-visit-parents/lib/index.js", "../node_modules/mdast-util-find-and-replace/lib/index.js", "../node_modules/mdast-util-gfm-autolink-literal/lib/index.js", "../node_modules/micromark-util-normalize-identifier/index.js", "../node_modules/mdast-util-gfm-footnote/lib/index.js", "../node_modules/mdast-util-gfm-strikethrough/lib/index.js", "../node_modules/markdown-table/index.js", "../node_modules/zwitch/index.js", "../node_modules/mdast-util-to-markdown/lib/handle/blockquote.js", "../node_modules/mdast-util-to-markdown/lib/util/pattern-in-scope.js", "../node_modules/mdast-util-to-markdown/lib/handle/break.js", "../node_modules/longest-streak/index.js", "../node_modules/mdast-util-to-markdown/lib/util/format-code-as-indented.js", "../node_modules/mdast-util-to-markdown/lib/util/check-fence.js", "../node_modules/mdast-util-to-markdown/lib/handle/code.js", "../node_modules/mdast-util-to-markdown/lib/util/check-quote.js", "../node_modules/mdast-util-to-markdown/lib/handle/definition.js", "../node_modules/mdast-util-to-markdown/lib/util/check-emphasis.js", "../node_modules/mdast-util-to-markdown/lib/util/encode-character-reference.js", "../node_modules/micromark-util-classify-character/index.js", "../node_modules/mdast-util-to-markdown/lib/util/encode-info.js", "../node_modules/mdast-util-to-markdown/lib/handle/emphasis.js", "../node_modules/unist-util-visit/lib/index.js", "../node_modules/mdast-util-to-markdown/lib/util/format-heading-as-setext.js", "../node_modules/mdast-util-to-markdown/lib/handle/heading.js", "../node_modules/mdast-util-to-markdown/lib/handle/html.js", "../node_modules/mdast-util-to-markdown/lib/handle/image.js", "../node_modules/mdast-util-to-markdown/lib/handle/image-reference.js", "../node_modules/mdast-util-to-markdown/lib/handle/inline-code.js", "../node_modules/mdast-util-to-markdown/lib/util/format-link-as-autolink.js", "../node_modules/mdast-util-to-markdown/lib/handle/link.js", "../node_modules/mdast-util-to-markdown/lib/handle/link-reference.js", "../node_modules/mdast-util-to-markdown/lib/util/check-bullet.js", "../node_modules/mdast-util-to-markdown/lib/util/check-bullet-other.js", "../node_modules/mdast-util-to-markdown/lib/util/check-bullet-ordered.js", "../node_modules/mdast-util-to-markdown/lib/util/check-rule.js", "../node_modules/mdast-util-to-markdown/lib/handle/list.js", "../node_modules/mdast-util-to-markdown/lib/util/check-list-item-indent.js", "../node_modules/mdast-util-to-markdown/lib/handle/list-item.js", "../node_modules/mdast-util-to-markdown/lib/handle/paragraph.js", "../node_modules/mdast-util-phrasing/lib/index.js", "../node_modules/mdast-util-to-markdown/lib/handle/root.js", "../node_modules/mdast-util-to-markdown/lib/util/check-strong.js", "../node_modules/mdast-util-to-markdown/lib/handle/strong.js", "../node_modules/mdast-util-to-markdown/lib/handle/text.js", "../node_modules/mdast-util-to-markdown/lib/util/check-rule-repetition.js", "../node_modules/mdast-util-to-markdown/lib/handle/thematic-break.js", "../node_modules/mdast-util-to-markdown/lib/handle/index.js", "../node_modules/character-entities/index.js", "../node_modules/decode-named-character-reference/index.js", "../node_modules/micromark-util-decode-numeric-character-reference/index.js", "../node_modules/micromark-util-decode-string/index.js", "../node_modules/mdast-util-gfm-table/lib/index.js", "../node_modules/mdast-util-gfm-task-list-item/lib/index.js", "../node_modules/mdast-util-gfm/lib/index.js", "../node_modules/micromark-util-chunked/index.js", "../node_modules/micromark-util-combine-extensions/index.js", "../node_modules/micromark-extension-gfm-autolink-literal/lib/syntax.js", "../node_modules/micromark-util-resolve-all/index.js", "../node_modules/micromark-core-commonmark/lib/attention.js", "../node_modules/micromark-core-commonmark/lib/autolink.js", "../node_modules/micromark-factory-space/index.js", "../node_modules/micromark-core-commonmark/lib/blank-line.js", "../node_modules/micromark-core-commonmark/lib/block-quote.js", "../node_modules/micromark-core-commonmark/lib/character-escape.js", "../node_modules/micromark-core-commonmark/lib/character-reference.js", "../node_modules/micromark-core-commonmark/lib/code-fenced.js", "../node_modules/micromark-core-commonmark/lib/code-indented.js", "../node_modules/micromark-core-commonmark/lib/code-text.js", "../node_modules/micromark-util-subtokenize/lib/splice-buffer.js", "../node_modules/micromark-util-subtokenize/index.js", "../node_modules/micromark-core-commonmark/lib/content.js", "../node_modules/micromark-factory-destination/index.js", "../node_modules/micromark-factory-label/index.js", "../node_modules/micromark-factory-title/index.js", "../node_modules/micromark-factory-whitespace/index.js", "../node_modules/micromark-core-commonmark/lib/definition.js", "../node_modules/micromark-core-commonmark/lib/hard-break-escape.js", "../node_modules/micromark-core-commonmark/lib/heading-atx.js", "../node_modules/micromark-util-html-tag-name/index.js", "../node_modules/micromark-core-commonmark/lib/html-flow.js", "../node_modules/micromark-core-commonmark/lib/html-text.js", "../node_modules/micromark-core-commonmark/lib/label-end.js", "../node_modules/micromark-core-commonmark/lib/label-start-image.js", "../node_modules/micromark-core-commonmark/lib/label-start-link.js", "../node_modules/micromark-core-commonmark/lib/line-ending.js", "../node_modules/micromark-core-commonmark/lib/thematic-break.js", "../node_modules/micromark-core-commonmark/lib/list.js", "../node_modules/micromark-core-commonmark/lib/setext-underline.js", "../node_modules/micromark-extension-gfm-footnote/lib/syntax.js", "../node_modules/micromark-extension-gfm-strikethrough/lib/syntax.js", "../node_modules/micromark-extension-gfm-table/lib/edit-map.js", "../node_modules/micromark-extension-gfm-table/lib/infer.js", "../node_modules/micromark-extension-gfm-table/lib/syntax.js", "../node_modules/micromark-extension-gfm-task-list-item/lib/syntax.js", "../node_modules/micromark-extension-gfm/index.js", "../node_modules/remark-gfm/lib/index.js", "../node_modules/micromark/lib/initialize/content.js", "../node_modules/micromark/lib/initialize/document.js", "../node_modules/micromark/lib/initialize/flow.js", "../node_modules/micromark/lib/initialize/text.js", "../node_modules/micromark/lib/constructs.js", "../node_modules/micromark/lib/create-tokenizer.js", "../node_modules/micromark/lib/parse.js", "../node_modules/micromark/lib/postprocess.js", "../node_modules/micromark/lib/preprocess.js", "../node_modules/unist-util-stringify-position/lib/index.js", "../node_modules/mdast-util-from-markdown/lib/index.js", "../node_modules/remark-parse/lib/index.js", "../node_modules/bail/index.js", "../node_modules/unified/lib/index.js", "../node_modules/is-plain-obj/index.js", "../node_modules/trough/lib/index.js", "../node_modules/vfile-message/lib/index.js", "../node_modules/vfile/lib/minpath.js", "../node_modules/vfile/lib/minproc.js", "../node_modules/vfile/lib/minurl.js", "../node_modules/vfile/lib/minurl.shared.js", "../node_modules/vfile/lib/index.js", "../node_modules/unified/lib/callable-instance.js", "../src/libs/pipeline/parse.ts", "../src/libs/pipeline/ast.ts", "../src/libs/schemas/renderers.ts", "../src/libs/pipeline/runtime.ts", "../src/libs/pipeline/style.css", "../src/libs/pipeline/render.ts", "../node_modules/property-information/lib/util/schema.js", "../node_modules/property-information/lib/util/merge.js", "../node_modules/property-information/lib/normalize.js", "../node_modules/property-information/lib/util/info.js", "../node_modules/property-information/lib/util/types.js", "../node_modules/property-information/lib/util/defined-info.js", "../node_modules/property-information/lib/util/create.js", "../node_modules/property-information/lib/aria.js", "../node_modules/property-information/lib/util/case-sensitive-transform.js", "../node_modules/property-information/lib/util/case-insensitive-transform.js", "../node_modules/property-information/lib/html.js", "../node_modules/property-information/lib/svg.js", "../node_modules/property-information/lib/xlink.js", "../node_modules/property-information/lib/xmlns.js", "../node_modules/property-information/lib/xml.js", "../node_modules/property-information/lib/find.js", "../node_modules/property-information/index.js", "../node_modules/comma-separated-tokens/index.js", "../node_modules/hast-util-parse-selector/lib/index.js", "../node_modules/space-separated-tokens/index.js", "../node_modules/hastscript/lib/create-h.js", "../node_modules/hastscript/lib/svg-case-sensitive-tag-names.js", "../node_modules/hastscript/lib/index.js", "../node_modules/html-void-elements/index.js", "../node_modules/stringify-entities/lib/core.js", "../node_modules/stringify-entities/lib/util/to-hexadecimal.js", "../node_modules/stringify-entities/lib/util/to-decimal.js", "../node_modules/character-entities-legacy/index.js", "../node_modules/character-entities-html4/index.js", "../node_modules/stringify-entities/lib/constant/dangerous.js", "../node_modules/stringify-entities/lib/util/to-named.js", "../node_modules/stringify-entities/lib/util/format-smart.js", "../node_modules/stringify-entities/lib/index.js", "../node_modules/hast-util-to-html/lib/handle/comment.js", "../node_modules/hast-util-to-html/lib/handle/doctype.js", "../node_modules/hast-util-whitespace/lib/index.js", "../node_modules/hast-util-to-html/lib/omission/util/siblings.js", "../node_modules/hast-util-to-html/lib/omission/omission.js", "../node_modules/hast-util-to-html/lib/omission/closing.js", "../node_modules/hast-util-to-html/lib/omission/opening.js", "../node_modules/hast-util-to-html/lib/handle/element.js", "../node_modules/hast-util-to-html/lib/handle/text.js", "../node_modules/hast-util-to-html/lib/handle/raw.js", "../node_modules/hast-util-to-html/lib/handle/root.js", "../node_modules/hast-util-to-html/lib/handle/index.js", "../node_modules/hast-util-to-html/lib/index.js", "../node_modules/rehype-stringify/lib/index.js", "../src/libs/pipeline/transform.ts", "../src/libs/coordinator/helpers.ts", "../src/libs/coordinator/execution.ts", "../src/libs/coordinator/coordinator.ts", "../src/libs/cli/commands/build.ts", "../src/libs/cli/utils/io.ts", "../src/libs/cli/utils/validation.ts", "../src/libs/cli/utils/wait.ts"],
"sourcesContent": ["/**\n * CommanderError class\n */\nclass CommanderError extends Error {\n /**\n * Constructs the CommanderError class\n * @param {number} exitCode suggested exit code which could be used with process.exit\n * @param {string} code an id string representing the error\n * @param {string} message human-readable description of the error\n */\n constructor(exitCode, code, message) {\n super(message);\n // properly capture stack trace in Node.js\n Error.captureStackTrace(this, this.constructor);\n this.name = this.constructor.name;\n this.code = code;\n this.exitCode = exitCode;\n this.nestedError = undefined;\n }\n}\n\n/**\n * InvalidArgumentError class\n */\nclass InvalidArgumentError extends CommanderError {\n /**\n * Constructs the InvalidArgumentError class\n * @param {string} [message] explanation of why argument is invalid\n */\n constructor(message) {\n super(1, 'commander.invalidArgument', message);\n // properly capture stack trace in Node.js\n Error.captureStackTrace(this, this.constructor);\n this.name = this.constructor.name;\n }\n}\n\nexports.CommanderError = CommanderError;\nexports.InvalidArgumentError = InvalidArgumentError;\n", "const { InvalidArgumentError } = require('./error.js');\n\nclass Argument {\n /**\n * Initialize a new command argument with the given name and description.\n * The default is that the argument is required, and you can explicitly\n * indicate this with <> around the name. Put [] around the name for an optional argument.\n *\n * @param {string} name\n * @param {string} [description]\n */\n\n constructor(name, description) {\n this.description = description || '';\n this.variadic = false;\n this.parseArg = undefined;\n this.defaultValue = undefined;\n this.defaultValueDescription = undefined;\n this.argChoices = undefined;\n\n switch (name[0]) {\n case '<': // e.g. <required>\n this.required = true;\n this._name = name.slice(1, -1);\n break;\n case '[': // e.g. [optional]\n this.required = false;\n this._name = name.slice(1, -1);\n break;\n default:\n this.required = true;\n this._name = name;\n break;\n }\n\n if (this._name.length > 3 && this._name.slice(-3) === '...') {\n this.variadic = true;\n this._name = this._name.slice(0, -3);\n }\n }\n\n /**\n * Return argument name.\n *\n * @return {string}\n */\n\n name() {\n return this._name;\n }\n\n /**\n * @package\n */\n\n _concatValue(value, previous) {\n if (previous === this.defaultValue || !Array.isArray(previous)) {\n return [value];\n }\n\n return previous.concat(value);\n }\n\n /**\n * Set the default value, and optionally supply the description to be displayed in the help.\n *\n * @param {*} value\n * @param {string} [description]\n * @return {Argument}\n */\n\n default(value, description) {\n this.defaultValue = value;\n this.defaultValueDescription = description;\n return this;\n }\n\n /**\n * Set the custom handler for processing CLI command arguments into argument values.\n *\n * @param {Function} [fn]\n * @return {Argument}\n */\n\n argParser(fn) {\n this.parseArg = fn;\n return this;\n }\n\n /**\n * Only allow argument value to be one of choices.\n *\n * @param {string[]} values\n * @return {Argument}\n */\n\n choices(values) {\n this.argChoices = values.slice();\n this.parseArg = (arg, previous) => {\n if (!this.argChoices.includes(arg)) {\n throw new InvalidArgumentError(\n `Allowed choices are ${this.argChoices.join(', ')}.`,\n );\n }\n if (this.variadic) {\n return this._concatValue(arg, previous);\n }\n return arg;\n };\n return this;\n }\n\n /**\n * Make argument required.\n *\n * @returns {Argument}\n */\n argRequired() {\n this.required = true;\n return this;\n }\n\n /**\n * Make argument optional.\n *\n * @returns {Argument}\n */\n argOptional() {\n this.required = false;\n return this;\n }\n}\n\n/**\n * Takes an argument and returns its human readable equivalent for help usage.\n *\n * @param {Argument} arg\n * @return {string}\n * @private\n */\n\nfunction humanReadableArgName(arg) {\n const nameOutput = arg.name() + (arg.variadic === true ? '...' : '');\n\n return arg.required ? '<' + nameOutput + '>' : '[' + nameOutput + ']';\n}\n\nexports.Argument = Argument;\nexports.humanReadableArgName = humanReadableArgName;\n", "const { humanReadableArgName } = require('./argument.js');\n\n/**\n * TypeScript import types for JSDoc, used by Visual Studio Code IntelliSense and `npm run typescript-checkJS`\n * https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#import-types\n * @typedef { import(\"./argument.js\").Argument } Argument\n * @typedef { import(\"./command.js\").Command } Command\n * @typedef { import(\"./option.js\").Option } Option\n */\n\n// Although this is a class, methods are static in style to allow override using subclass or just functions.\nclass Help {\n constructor() {\n this.helpWidth = undefined;\n this.minWidthToWrap = 40;\n this.sortSubcommands = false;\n this.sortOptions = false;\n this.showGlobalOptions = false;\n }\n\n /**\n * prepareContext is called by Commander after applying overrides from `Command.configureHelp()`\n * and just before calling `formatHelp()`.\n *\n * Commander just uses the helpWidth and the rest is provided for optional use by more complex subclasses.\n *\n * @param {{ error?: boolean, helpWidth?: number, outputHasColors?: boolean }} contextOptions\n */\n prepareContext(contextOptions) {\n this.helpWidth = this.helpWidth ?? contextOptions.helpWidth ?? 80;\n }\n\n /**\n * Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one.\n *\n * @param {Command} cmd\n * @returns {Command[]}\n */\n\n visibleCommands(cmd) {\n const visibleCommands = cmd.commands.filter((cmd) => !cmd._hidden);\n const helpCommand = cmd._getHelpCommand();\n if (helpCommand && !helpCommand._hidden) {\n visibleCommands.push(helpCommand);\n }\n if (this.sortSubcommands) {\n visibleCommands.sort((a, b) => {\n // @ts-ignore: because overloaded return type\n return a.name().localeCompare(b.name());\n });\n }\n return visibleCommands;\n }\n\n /**\n * Compare options for sort.\n *\n * @param {Option} a\n * @param {Option} b\n * @returns {number}\n */\n compareOptions(a, b) {\n const getSortKey = (option) => {\n // WYSIWYG for order displayed in help. Short used for comparison if present. No special handling for negated.\n return option.short\n ? option.short.replace(/^-/, '')\n : option.long.replace(/^--/, '');\n };\n return getSortKey(a).localeCompare(getSortKey(b));\n }\n\n /**\n * Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one.\n *\n * @param {Command} cmd\n * @returns {Option[]}\n */\n\n visibleOptions(cmd) {\n const visibleOptions = cmd.options.filter((option) => !option.hidden);\n // Built-in help option.\n const helpOption = cmd._getHelpOption();\n if (helpOption && !helpOption.hidden) {\n // Automatically hide conflicting flags. Bit dubious but a historical behaviour that is convenient for single-command programs.\n const removeShort = helpOption.short && cmd._findOption(helpOption.short);\n const removeLong = helpOption.long && cmd._findOption(helpOption.long);\n if (!removeShort && !removeLong) {\n visibleOptions.push(helpOption); // no changes needed\n } else if (helpOption.long && !removeLong) {\n visibleOptions.push(\n cmd.createOption(helpOption.long, helpOption.description),\n );\n } else if (helpOption.short && !removeShort) {\n visibleOptions.push(\n cmd.createOption(helpOption.short, helpOption.description),\n );\n }\n }\n if (this.sortOptions) {\n visibleOptions.sort(this.compareOptions);\n }\n return visibleOptions;\n }\n\n /**\n * Get an array of the visible global options. (Not including help.)\n *\n * @param {Command} cmd\n * @returns {Option[]}\n */\n\n visibleGlobalOptions(cmd) {\n if (!this.showGlobalOptions) return [];\n\n const globalOptions = [];\n for (\n let ancestorCmd = cmd.parent;\n ancestorCmd;\n ancestorCmd = ancestorCmd.parent\n ) {\n const visibleOptions = ancestorCmd.options.filter(\n (option) => !option.hidden,\n );\n globalOptions.push(...visibleOptions);\n }\n if (this.sortOptions) {\n globalOptions.sort(this.compareOptions);\n }\n return globalOptions;\n }\n\n /**\n * Get an array of the arguments if any have a description.\n *\n * @param {Command} cmd\n * @returns {Argument[]}\n */\n\n visibleArguments(cmd) {\n // Side effect! Apply the legacy descriptions before the arguments are displayed.\n if (cmd._argsDescription) {\n cmd.registeredArguments.forEach((argument) => {\n argument.description =\n argument.description || cmd._argsDescription[argument.name()] || '';\n });\n }\n\n // If there are any arguments with a description then return all the arguments.\n if (cmd.registeredArguments.find((argument) => argument.description)) {\n return cmd.registeredArguments;\n }\n return [];\n }\n\n /**\n * Get the command term to show in the list of subcommands.\n *\n * @param {Command} cmd\n * @returns {string}\n */\n\n subcommandTerm(cmd) {\n // Legacy. Ignores custom usage string, and nested commands.\n const args = cmd.registeredArguments\n .map((arg) => humanReadableArgName(arg))\n .join(' ');\n return (\n cmd._name +\n (cmd._aliases[0] ? '|' + cmd._aliases[0] : '') +\n (cmd.options.length ? ' [options]' : '') + // simplistic check for non-help option\n (args ? ' ' + args : '')\n );\n }\n\n /**\n * Get the option term to show in the list of options.\n *\n * @param {Option} option\n * @returns {string}\n */\n\n optionTerm(option) {\n return option.flags;\n }\n\n /**\n * Get the argument term to show in the list of arguments.\n *\n * @param {Argument} argument\n * @returns {string}\n */\n\n argumentTerm(argument) {\n return argument.name();\n }\n\n /**\n * Get the longest command term length.\n *\n * @param {Command} cmd\n * @param {Help} helper\n * @returns {number}\n */\n\n longestSubcommandTermLength(cmd, helper) {\n return helper.visibleCommands(cmd).reduce((max, command) => {\n return Math.max(\n max,\n this.displayWidth(\n helper.styleSubcommandTerm(helper.subcommandTerm(command)),\n ),\n );\n }, 0);\n }\n\n /**\n * Get the longest option term length.\n *\n * @param {Command} cmd\n * @param {Help} helper\n * @returns {number}\n */\n\n longestOptionTermLength(cmd, helper) {\n return helper.visibleOptions(cmd).reduce((max, option) => {\n return Math.max(\n max,\n this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))),\n );\n }, 0);\n }\n\n /**\n * Get the longest global option term length.\n *\n * @param {Command} cmd\n * @param {Help} helper\n * @returns {number}\n */\n\n longestGlobalOptionTermLength(cmd, helper) {\n return helper.visibleGlobalOptions(cmd).reduce((max, option) => {\n return Math.max(\n max,\n this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))),\n );\n }, 0);\n }\n\n /**\n * Get the longest argument term length.\n *\n * @param {Command} cmd\n * @param {Help} helper\n * @returns {number}\n */\n\n longestArgumentTermLength(cmd, helper) {\n return helper.visibleArguments(cmd).reduce((max, argument) => {\n return Math.max(\n max,\n this.displayWidth(\n helper.styleArgumentTerm(helper.argumentTerm(argument)),\n ),\n );\n }, 0);\n }\n\n /**\n * Get the command usage to be displayed at the top of the built-in help.\n *\n * @param {Command} cmd\n * @returns {string}\n */\n\n commandUsage(cmd) {\n // Usage\n let cmdName = cmd._name;\n if (cmd._aliases[0]) {\n cmdName = cmdName + '|' + cmd._aliases[0];\n }\n let ancestorCmdNames = '';\n for (\n let ancestorCmd = cmd.parent;\n ancestorCmd;\n ancestorCmd = ancestorCmd.parent\n ) {\n ancestorCmdNames = ancestorCmd.name() + ' ' + ancestorCmdNames;\n }\n return ancestorCmdNames + cmdName + ' ' + cmd.usage();\n }\n\n /**\n * Get the description for the command.\n *\n * @param {Command} cmd\n * @returns {string}\n */\n\n commandDescription(cmd) {\n // @ts-ignore: because overloaded return type\n return cmd.description();\n }\n\n /**\n * Get the subcommand summary to show in the list of subcommands.\n * (Fallback to description for backwards compatibility.)\n *\n * @param {Command} cmd\n * @returns {string}\n */\n\n subcommandDescription(cmd) {\n // @ts-ignore: because overloaded return type\n return cmd.summary() || cmd.description();\n }\n\n /**\n * Get the option description to show in the list of options.\n *\n * @param {Option} option\n * @return {string}\n */\n\n optionDescription(option) {\n const extraInfo = [];\n\n if (option.argChoices) {\n extraInfo.push(\n // use stringify to match the display of the default value\n `choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(', ')}`,\n );\n }\n if (option.defaultValue !== undefined) {\n // default for boolean and negated more for programmer than end user,\n // but show true/false for boolean option as may be for hand-rolled env or config processing.\n const showDefault =\n option.required ||\n option.optional ||\n (option.isBoolean() && typeof option.defaultValue === 'boolean');\n if (showDefault) {\n extraInfo.push(\n `default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`,\n );\n }\n }\n // preset for boolean and negated are more for programmer than end user\n if (option.presetArg !== undefined && option.optional) {\n extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);\n }\n if (option.envVar !== undefined) {\n extraInfo.push(`env: ${option.envVar}`);\n }\n if (extraInfo.length > 0) {\n const extraDescription = `(${extraInfo.join(', ')})`;\n if (option.description) {\n return `${option.description} ${extraDescription}`;\n }\n return extraDescription;\n }\n\n return option.description;\n }\n\n /**\n * Get the argument description to show in the list of arguments.\n *\n * @param {Argument} argument\n * @return {string}\n */\n\n argumentDescription(argument) {\n const extraInfo = [];\n if (argument.argChoices) {\n extraInfo.push(\n // use stringify to match the display of the default value\n `choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(', ')}`,\n );\n }\n if (argument.defaultValue !== undefined) {\n extraInfo.push(\n `default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`,\n );\n }\n if (extraInfo.length > 0) {\n const extraDescription = `(${extraInfo.join(', ')})`;\n if (argument.description) {\n return `${argument.description} ${extraDescription}`;\n }\n return extraDescription;\n }\n return argument.description;\n }\n\n /**\n * Format a list of items, given a heading and an array of formatted items.\n *\n * @param {string} heading\n * @param {string[]} items\n * @param {Help} helper\n * @returns string[]\n */\n formatItemList(heading, items, helper) {\n if (items.length === 0) return [];\n\n return [helper.styleTitle(heading), ...items, ''];\n }\n\n /**\n * Group items by their help group heading.\n *\n * @param {Command[] | Option[]} unsortedItems\n * @param {Command[] | Option[]} visibleItems\n * @param {Function} getGroup\n * @returns {Map<string, Command[] | Option[]>}\n */\n groupItems(unsortedItems, visibleItems, getGroup) {\n const result = new Map();\n // Add groups in order of appearance in unsortedItems.\n unsortedItems.forEach((item) => {\n const group = getGroup(item);\n if (!result.has(group)) result.set(group, []);\n });\n // Add items in order of appearance in visibleItems.\n visibleItems.forEach((item) => {\n const group = getGroup(item);\n if (!result.has(group)) {\n result.set(group, []);\n }\n result.get(group).push(item);\n });\n return result;\n }\n\n /**\n * Generate the built-in help text.\n *\n * @param {Command} cmd\n * @param {Help} helper\n * @returns {string}\n */\n\n formatHelp(cmd, helper) {\n const termWidth = helper.padWidth(cmd, helper);\n const helpWidth = helper.helpWidth ?? 80; // in case prepareContext() was not called\n\n function callFormatItem(term, description) {\n return helper.formatItem(term, termWidth, description, helper);\n }\n\n // Usage\n let output = [\n `${helper.styleTitle('Usage:')} ${helper.styleUsage(helper.commandUsage(cmd))}`,\n '',\n ];\n\n // Description\n const commandDescription = helper.commandDescription(cmd);\n if (commandDescription.length > 0) {\n output = output.concat([\n helper.boxWrap(\n helper.styleCommandDescription(commandDescription),\n helpWidth,\n ),\n '',\n ]);\n }\n\n // Arguments\n const argumentList = helper.visibleArguments(cmd).map((argument) => {\n return callFormatItem(\n helper.styleArgumentTerm(helper.argumentTerm(argument)),\n helper.styleArgumentDescription(helper.argumentDescription(argument)),\n );\n });\n output = output.concat(\n this.formatItemList('Arguments:', argumentList, helper),\n );\n\n // Options\n const optionGroups = this.groupItems(\n cmd.options,\n helper.visibleOptions(cmd),\n (option) => option.helpGroupHeading ?? 'Options:',\n );\n optionGroups.forEach((options, group) => {\n const optionList = options.map((option) => {\n return callFormatItem(\n helper.styleOptionTerm(helper.optionTerm(option)),\n helper.styleOptionDescription(helper.optionDescription(option)),\n );\n });\n output = output.concat(this.formatItemList(group, optionList, helper));\n });\n\n if (helper.showGlobalOptions) {\n const globalOptionList = helper\n .visibleGlobalOptions(cmd)\n .map((option) => {\n return callFormatItem(\n helper.styleOptionTerm(helper.optionTerm(option)),\n helper.styleOptionDescription(helper.optionDescription(option)),\n );\n });\n output = output.concat(\n this.formatItemList('Global Options:', globalOptionList, helper),\n );\n }\n\n // Commands\n const commandGroups = this.groupItems(\n cmd.commands,\n helper.visibleCommands(cmd),\n (sub) => sub.helpGroup() || 'Commands:',\n );\n commandGroups.forEach((commands, group) => {\n const commandList = commands.map((sub) => {\n return callFormatItem(\n helper.styleSubcommandTerm(helper.subcommandTerm(sub)),\n helper.styleSubcommandDescription(helper.subcommandDescription(sub)),\n );\n });\n output = output.concat(this.formatItemList(group, commandList, helper));\n });\n\n return output.join('\\n');\n }\n\n /**\n * Return display width of string, ignoring ANSI escape sequences. Used in padding and wrapping calculations.\n *\n * @param {string} str\n * @returns {number}\n */\n displayWidth(str) {\n return stripColor(str).length;\n }\n\n /**\n * Style the title for displaying in the help. Called with 'Usage:', 'Options:', etc.\n *\n * @param {string} str\n * @returns {string}\n */\n styleTitle(str) {\n return str;\n }\n\n styleUsage(str) {\n // Usage has lots of parts the user might like to color separately! Assume default usage string which is formed like:\n // command subcommand [options] [command] <foo> [bar]\n return str\n .split(' ')\n .map((word) => {\n if (word === '[options]') return this.styleOptionText(word);\n if (word === '[command]') return this.styleSubcommandText(word);\n if (word[0] === '[' || word[0] === '<')\n return this.styleArgumentText(word);\n return this.styleCommandText(word); // Restrict to initial words?\n })\n .join(' ');\n }\n styleCommandDescription(str) {\n return this.styleDescriptionText(str);\n }\n styleOptionDescription(str) {\n return this.styleDescriptionText(str);\n }\n styleSubcommandDescription(str) {\n return this.styleDescriptionText(str);\n }\n styleArgumentDescription(str) {\n return this.styleDescriptionText(str);\n }\n styleDescriptionText(str) {\n return str;\n }\n styleOptionTerm(str) {\n return this.styleOptionText(str);\n }\n styleSubcommandTerm(str) {\n // This is very like usage with lots of parts! Assume default string which is formed like:\n // subcommand [options] <foo> [bar]\n return str\n .split(' ')\n .map((word) => {\n if (word === '[options]') return this.styleOptionText(word);\n if (word[0] === '[' || word[0] === '<')\n return this.styleArgumentText(word);\n return this.styleSubcommandText(word); // Restrict to initial words?\n })\n .join(' ');\n }\n styleArgumentTerm(str) {\n return this.styleArgumentText(str);\n }\n styleOptionText(str) {\n return str;\n }\n styleArgumentText(str) {\n return str;\n }\n styleSubcommandText(str) {\n return str;\n }\n styleCommandText(str) {\n return str;\n }\n\n /**\n * Calculate the pad width from the maximum term length.\n *\n * @param {Command} cmd\n * @param {Help} helper\n * @returns {number}\n */\n\n padWidth(cmd, helper) {\n return Math.max(\n helper.longestOptionTermLength(cmd, helper),\n helper.longestGlobalOptionTermLength(cmd, helper),\n helper.longestSubcommandTermLength(cmd, helper),\n helper.longestArgumentTermLength(cmd, helper),\n );\n }\n\n /**\n * Detect manually wrapped and indented strings by checking for line break followed by whitespace.\n *\n * @param {string} str\n * @returns {boolean}\n */\n preformatted(str) {\n return /\\n[^\\S\\r\\n]/.test(str);\n }\n\n /**\n * Format the \"item\", which consists of a term and description. Pad the term and wrap the description, indenting the following lines.\n *\n * So \"TTT\", 5, \"DDD DDDD DD DDD\" might be formatted for this.helpWidth=17 like so:\n * TTT DDD DDDD\n * DD DDD\n *\n * @param {string} term\n * @param {number} termWidth\n * @param {string} description\n * @param {Help} helper\n * @returns {string}\n */\n formatItem(term, termWidth, description, helper) {\n const itemIndent = 2;\n const itemIndentStr = ' '.repeat(itemIndent);\n if (!description) return itemIndentStr + term;\n\n // Pad the term out to a consistent width, so descriptions are aligned.\n const paddedTerm = term.padEnd(\n termWidth + term.length - helper.displayWidth(term),\n );\n\n // Format the description.\n const spacerWidth = 2; // between term and description\n const helpWidth = this.helpWidth ?? 80; // in case prepareContext() was not called\n const remainingWidth = helpWidth - termWidth - spacerWidth - itemIndent;\n let formattedDescription;\n if (\n remainingWidth < this.minWidthToWrap ||\n helper.preformatted(description)\n ) {\n formattedDescription = description;\n } else {\n const wrappedDescription = helper.boxWrap(description, remainingWidth);\n formattedDescription = wrappedDescription.replace(\n /\\n/g,\n '\\n' + ' '.repeat(termWidth + spacerWidth),\n );\n }\n\n // Construct and overall indent.\n return (\n itemIndentStr +\n paddedTerm +\n ' '.repeat(spacerWidth) +\n formattedDescription.replace(/\\n/g, `\\n${itemIndentStr}`)\n );\n }\n\n /**\n * Wrap a string at whitespace, preserving existing line breaks.\n * Wrapping is skipped if the width is less than `minWidthToWrap`.\n *\n * @param {string} str\n * @param {number} width\n * @returns {string}\n */\n boxWrap(str, width) {\n if (width < this.minWidthToWrap) return str;\n\n const rawLines = str.split(/\\r\\n|\\n/);\n // split up text by whitespace\n const chunkPattern = /[\\s]*[^\\s]+/g;\n const wrappedLines = [];\n rawLines.forEach((line) => {\n const chunks = line.match(chunkPattern);\n if (chunks === null) {\n wrappedLines.push('');\n return;\n }\n\n let sumChunks = [chunks.shift()];\n let sumWidth = this.displayWidth(sumChunks[0]);\n chunks.forEach((chunk) => {\n const visibleWidth = this.displayWidth(chunk);\n // Accumulate chunks while they fit into width.\n if (sumWidth + visibleWidth <= width) {\n sumChunks.push(chunk);\n sumWidth += visibleWidth;\n return;\n }\n wrappedLines.push(sumChunks.join(''));\n\n const nextChunk = chunk.trimStart(); // trim space at line break\n sumChunks = [nextChunk];\n sumWidth = this.displayWidth(nextChunk);\n });\n wrappedLines.push(sumChunks.join(''));\n });\n\n return wrappedLines.join('\\n');\n }\n}\n\n/**\n * Strip style ANSI escape sequences from the string. In particular, SGR (Select Graphic Rendition) codes.\n *\n * @param {string} str\n * @returns {string}\n * @package\n */\n\nfunction stripColor(str) {\n // eslint-disable-next-line no-control-regex\n const sgrPattern = /\\x1b\\[\\d*(;\\d*)*m/g;\n return str.replace(sgrPattern, '');\n}\n\nexports.Help = Help;\nexports.stripColor = stripColor;\n", "const { InvalidArgumentError } = require('./error.js');\n\nclass Option {\n /**\n * Initialize a new `Option` with the given `flags` and `description`.\n *\n * @param {string} flags\n * @param {string} [description]\n */\n\n constructor(flags, description) {\n this.flags = flags;\n this.description = description || '';\n\n this.required = flags.includes('<'); // A value must be supplied when the option is specified.\n this.optional = flags.includes('['); // A value is optional when the option is specified.\n // variadic test ignores <value,...> et al which might be used to describe custom splitting of single argument\n this.variadic = /\\w\\.\\.\\.[>\\]]$/.test(flags); // The option can take multiple values.\n this.mandatory = false; // The option must have a value after parsing, which usually means it must be specified on command line.\n const optionFlags = splitOptionFlags(flags);\n this.short = optionFlags.shortFlag; // May be a short flag, undefined, or even a long flag (if option has two long flags).\n this.long = optionFlags.longFlag;\n this.negate = false;\n if (this.long) {\n this.negate = this.long.startsWith('--no-');\n }\n this.defaultValue = undefined;\n this.defaultValueDescription = undefined;\n this.presetArg = undefined;\n this.envVar = undefined;\n this.parseArg = undefined;\n this.hidden = false;\n this.argChoices = undefined;\n this.conflictsWith = [];\n this.implied = undefined;\n this.helpGroupHeading = undefined; // soft initialised when option added to command\n }\n\n /**\n * Set the default value, and optionally supply the description to be displayed in the help.\n *\n * @param {*} value\n * @param {string} [description]\n * @return {Option}\n */\n\n default(value, description) {\n this.defaultValue = value;\n this.defaultValueDescription = description;\n return this;\n }\n\n /**\n * Preset to use when option used without option-argument, especially optional but also boolean and negated.\n * The custom processing (parseArg) is called.\n *\n * @example\n * new Option('--color').default('GREYSCALE').preset('RGB');\n * new Option('--donate [amount]').preset('20').argParser(parseFloat);\n *\n * @param {*} arg\n * @return {Option}\n */\n\n preset(arg) {\n this.presetArg = arg;\n return this;\n }\n\n /**\n * Add option name(s) that conflict with this option.\n * An error will be displayed if conflicting options are found during parsing.\n *\n * @example\n * new Option('--rgb').conflicts('cmyk');\n * new Option('--js').conflicts(['ts', 'jsx']);\n *\n * @param {(string | string[])} names\n * @return {Option}\n */\n\n conflicts(names) {\n this.conflictsWith = this.conflictsWith.concat(names);\n return this;\n }\n\n /**\n * Specify implied option values for when this option is set and the implied options are not.\n *\n * The custom processing (parseArg) is not called on the implied values.\n *\n * @example\n * program\n * .addOption(new Option('--log', 'write logging information to file'))\n * .addOption(new Option('--trace', 'log extra details').implies({ log: 'trace.txt' }));\n *\n * @param {object} impliedOptionValues\n * @return {Option}\n */\n implies(impliedOptionValues) {\n let newImplied = impliedOptionValues;\n if (typeof impliedOptionValues === 'string') {\n // string is not documented, but easy mistake and we can do what user probably intended.\n newImplied = { [impliedOptionValues]: true };\n }\n this.implied = Object.assign(this.implied || {}, newImplied);\n return this;\n }\n\n /**\n * Set environment variable to check for option value.\n *\n * An environment variable is only used if when processed the current option value is\n * undefined, or the source of the current value is 'default' or 'config' or 'env'.\n *\n * @param {string} name\n * @return {Option}\n */\n\n env(name) {\n this.envVar = name;\n return this;\n }\n\n /**\n * Set the custom handler for processing CLI option arguments into option values.\n *\n * @param {Function} [fn]\n * @return {Option}\n */\n\n argParser(fn) {\n this.parseArg = fn;\n return this;\n }\n\n /**\n * Whether the option is mandatory and must have a value after parsing.\n *\n * @param {boolean} [mandatory=true]\n * @return {Option}\n */\n\n makeOptionMandatory(mandatory = true) {\n this.mandatory = !!mandatory;\n return this;\n }\n\n /**\n * Hide option in help.\n *\n * @param {boolean} [hide=true]\n * @return {Option}\n */\n\n hideHelp(hide = true) {\n this.hidden = !!hide;\n return this;\n }\n\n /**\n * @package\n */\n\n _concatValue(value, previous) {\n if (previous === this.defaultValue || !Array.isArray(previous)) {\n return [value];\n }\n\n return previous.concat(value);\n }\n\n /**\n * Only allow option value to be one of choices.\n *\n * @param {string[]} values\n * @return {Option}\n */\n\n choices(values) {\n this.argChoices = values.slice();\n this.parseArg = (arg, previous) => {\n if (!this.argChoices.includes(arg)) {\n throw new InvalidArgumentError(\n `Allowed choices are ${this.argChoices.join(', ')}.`,\n );\n }\n if (this.variadic) {\n return this._concatValue(arg, previous);\n }\n return arg;\n };\n return this;\n }\n\n /**\n * Return option name.\n *\n * @return {string}\n */\n\n name() {\n if (this.long) {\n return this.long.replace(/^--/, '');\n }\n return this.short.replace(/^-/, '');\n }\n\n /**\n * Return option name, in a camelcase format that can be used\n * as an object attribute key.\n *\n * @return {string}\n */\n\n attributeName() {\n if (this.negate) {\n return camelcase(this.name().replace(/^no-/, ''));\n }\n return camelcase(this.name());\n }\n\n /**\n * Set the help group heading.\n *\n * @param {string} heading\n * @return {Option}\n */\n helpGroup(heading) {\n this.helpGroupHeading = heading;\n return this;\n }\n\n /**\n * Check if `arg` matches the short or long flag.\n *\n * @param {string} arg\n * @return {boolean}\n * @package\n */\n\n is(arg) {\n return this.short === arg || this.long === arg;\n }\n\n /**\n * Return whether a boolean option.\n *\n * Options are one of boolean, negated, required argument, or optional argument.\n *\n * @return {boolean}\n * @package\n */\n\n isBoolean() {\n return !this.required && !this.optional && !this.negate;\n }\n}\n\n/**\n * This class is to make it easier to work with dual options, without changing the existing\n * implementation. We support separate dual options for separate positive and negative options,\n * like `--build` and `--no-build`, which share a single option value. This works nicely for some\n * use cases, but is tricky for others where we want separate behaviours despite\n * the single shared option value.\n */\nclass DualOptions {\n /**\n * @param {Option[]} options\n */\n constructor(options) {\n this.positiveOptions = new Map();\n this.negativeOptions = new Map();\n this.dualOptions = new Set();\n options.forEach((option) => {\n if (option.negate) {\n this.negativeOptions.set(option.attributeName(), option);\n } else {\n this.positiveOptions.set(option.attributeName(), option);\n }\n });\n this.negativeOptions.forEach((value, key) => {\n if (this.positiveOptions.has(key)) {\n this.dualOptions.add(key);\n }\n });\n }\n\n /**\n * Did the value come from the option, and not from possible matching dual option?\n *\n * @param {*} value\n * @param {Option} option\n * @returns {boolean}\n */\n valueFromOption(value, option) {\n const optionKey = option.attributeName();\n if (!this.dualOptions.has(optionKey)) return true;\n\n // Use the value to deduce if (probably) came from the option.\n const preset = this.negativeOptions.get(optionKey).presetArg;\n const negativeValue = preset !== undefined ? preset : false;\n return option.negate === (negativeValue === value);\n }\n}\n\n/**\n * Convert string from kebab-case to camelCase.\n *\n * @param {string} str\n * @return {string}\n * @private\n */\n\nfunction camelcase(str) {\n return str.split('-').reduce((str, word) => {\n return str + word[0].toUpperCase() + word.slice(1);\n });\n}\n\n/**\n * Split the short and long flag out of something like '-m,--mixed <value>'\n *\n * @private\n */\n\nfunction splitOptionFlags(flags) {\n let shortFlag;\n let longFlag;\n // short flag, single dash and single character\n const shortFlagExp = /^-[^-]$/;\n // long flag, double dash and at least one character\n const longFlagExp = /^--[^-]/;\n\n const flagParts = flags.split(/[ |,]+/).concat('guard');\n // Normal is short and/or long.\n if (shortFlagExp.test(flagParts[0])) shortFlag = flagParts.shift();\n if (longFlagExp.test(flagParts[0])) longFlag = flagParts.shift();\n // Long then short. Rarely used but fine.\n if (!shortFlag && shortFla