cli-kiss 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +28 -13
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/Command.ts +75 -52
- package/src/lib/Operation.ts +16 -8
- package/src/lib/Option.ts +17 -12
- package/src/lib/Positional.ts +15 -8
- package/src/lib/Reader.ts +2 -5
- package/src/lib/Run.ts +32 -31
- package/src/lib/Type.ts +2 -2
- package/src/lib/Usage.ts +47 -41
- package/tests/unit.command.execute.ts +3 -2
- package/tests/unit.command.usage.ts +15 -20
- package/tests/{unit.runner.test1.ts → unit.runner.cycle.ts} +102 -68
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/lib/Typo.ts","../src/lib/Command.ts","../src/lib/Operation.ts","../src/lib/Type.ts","../src/lib/Option.ts","../src/lib/Positional.ts","../src/lib/Reader.ts","../src/lib/Usage.ts","../src/lib/Run.ts"],"sourcesContent":["export * from \"./lib/Command\";\nexport * from \"./lib/Operation\";\nexport * from \"./lib/Option\";\nexport * from \"./lib/Positional\";\nexport * from \"./lib/Reader\";\nexport * from \"./lib/Run\";\nexport * from \"./lib/Type\";\nexport * from \"./lib/Typo\";\nexport * from \"./lib/Usage\";\n","export type TypoColor =\n | \"darkBlack\"\n | \"darkRed\"\n | \"darkGreen\"\n | \"darkYellow\"\n | \"darkBlue\"\n | \"darkMagenta\"\n | \"darkCyan\"\n | \"darkWhite\"\n | \"brightBlack\"\n | \"brightRed\"\n | \"brightGreen\"\n | \"brightYellow\"\n | \"brightBlue\"\n | \"brightMagenta\"\n | \"brightCyan\"\n | \"brightWhite\";\n\nexport type TypoStyle = {\n fgColor?: TypoColor;\n bgColor?: TypoColor;\n dim?: boolean;\n bold?: boolean;\n italic?: boolean;\n underline?: boolean;\n strikethrough?: boolean;\n};\n\nexport const typoStyleConstants: TypoStyle = {\n fgColor: \"darkCyan\",\n bold: true,\n};\nexport const typoStyleUserInput: TypoStyle = {\n fgColor: \"darkBlue\",\n bold: true,\n};\nexport const typoStyleFailure: TypoStyle = {\n fgColor: \"darkRed\",\n bold: true,\n};\n\nexport class TypoString {\n #value: string;\n #typoStyle: TypoStyle;\n constructor(value: string, typoStyle: TypoStyle = {}) {\n this.#value = value;\n this.#typoStyle = typoStyle;\n }\n getRawString(): string {\n return this.#value;\n }\n computeStyledString(typoSupport: TypoSupport): string {\n return typoSupport.computeStyledString(this.#value, this.#typoStyle);\n }\n}\n\nexport class TypoText {\n #typoStrings: Array<TypoString>;\n constructor(...typoParts: Array<TypoText | TypoString | string>) {\n this.#typoStrings = [];\n for (const typoPart of typoParts) {\n if (typoPart instanceof TypoText) {\n this.pushText(typoPart);\n } else if (typoPart instanceof TypoString) {\n this.pushString(typoPart);\n } else if (typeof typoPart === \"string\") {\n this.pushString(new TypoString(typoPart));\n }\n }\n }\n pushString(typoString: TypoString) {\n this.#typoStrings.push(typoString);\n }\n pushText(typoText: TypoText) {\n for (const typoString of typoText.#typoStrings) {\n this.#typoStrings.push(typoString);\n }\n }\n computeStyledString(typoSupport: TypoSupport): string {\n return this.#typoStrings\n .map((t) => t.computeStyledString(typoSupport))\n .join(\"\");\n }\n computeRawString(): string {\n return this.#typoStrings.map((t) => t.getRawString()).join(\"\");\n }\n computeRawLength(): number {\n let length = 0;\n for (const typoString of this.#typoStrings) {\n length += typoString.getRawString().length;\n }\n return length;\n }\n}\n\nexport class TypoGrid {\n #typoRows: Array<Array<TypoText>>;\n constructor() {\n this.#typoRows = [];\n }\n pushRow(cells: Array<TypoText>) {\n this.#typoRows.push(cells);\n }\n computeStyledGrid(typoSupport: TypoSupport): Array<Array<string>> {\n const widths = new Array<number>();\n const printableGrid = new Array<Array<string>>();\n for (const typoGridRow of this.#typoRows) {\n for (\n let typoGridColumnIndex = 0;\n typoGridColumnIndex < typoGridRow.length;\n typoGridColumnIndex++\n ) {\n const typoGridCell = typoGridRow[typoGridColumnIndex]!;\n const width = typoGridCell.computeRawLength();\n if (\n widths[typoGridColumnIndex] === undefined ||\n width > widths[typoGridColumnIndex]!\n ) {\n widths[typoGridColumnIndex] = width;\n }\n }\n }\n for (const typoGridRow of this.#typoRows) {\n const printableGridRow = new Array<string>();\n for (\n let typoGridColumnIndex = 0;\n typoGridColumnIndex < typoGridRow.length;\n typoGridColumnIndex++\n ) {\n const typoGridCell = typoGridRow[typoGridColumnIndex]!;\n const printableGridCell = typoGridCell.computeStyledString(typoSupport);\n printableGridRow.push(printableGridCell);\n if (typoGridColumnIndex < typoGridRow.length - 1) {\n const width = typoGridCell.computeRawLength();\n const padding = \" \".repeat(widths[typoGridColumnIndex]! - width);\n printableGridRow.push(padding);\n }\n }\n printableGrid.push(printableGridRow);\n }\n return printableGrid;\n }\n}\n\nexport class TypoError extends Error {\n #typoText: TypoText;\n constructor(currentTypoText: TypoText, source?: unknown) {\n const typoText = new TypoText();\n typoText.pushText(currentTypoText);\n if (source instanceof Error) {\n typoText.pushString(new TypoString(`: ${source.message}`));\n } else if (source instanceof TypoError) {\n typoText.pushString(new TypoString(\": \"));\n typoText.pushText(source.#typoText);\n } else if (source !== undefined) {\n typoText.pushString(new TypoString(`: ${String(source)}`));\n }\n super(typoText.computeRawString());\n this.#typoText = typoText;\n }\n computeStyledString(typoSupport: TypoSupport): string {\n return this.#typoText.computeStyledString(typoSupport);\n }\n}\n\nexport class TypoSupport {\n #kind: \"none\" | \"tty\" | \"mock\";\n private constructor(kind: \"none\" | \"tty\" | \"mock\") {\n this.#kind = kind;\n }\n static none(): TypoSupport {\n return new TypoSupport(\"none\");\n }\n static tty(): TypoSupport {\n return new TypoSupport(\"tty\");\n }\n static mock(): TypoSupport {\n return new TypoSupport(\"mock\");\n }\n static inferFromProcess(): TypoSupport {\n if (!process) {\n return TypoSupport.none();\n }\n if (process.env) {\n if (process.env[\"FORCE_COLOR\"] === \"0\") {\n return TypoSupport.none();\n }\n if (process.env[\"FORCE_COLOR\"]) {\n return TypoSupport.tty();\n }\n if (\"NO_COLOR\" in process.env) {\n return TypoSupport.none();\n }\n }\n if (!process.stdout || !process.stdout.isTTY) {\n return TypoSupport.none();\n }\n return TypoSupport.tty();\n }\n computeStyledString(value: string, typoStyle: TypoStyle): string {\n if (this.#kind === \"none\") {\n return value;\n }\n if (this.#kind === \"tty\") {\n const fgColorCode = typoStyle.fgColor\n ? ttyCodeFgColors[typoStyle.fgColor]\n : \"\";\n const bgColorCode = typoStyle.bgColor\n ? ttyCodeBgColors[typoStyle.bgColor]\n : \"\";\n const boldCode = typoStyle.bold ? ttyCodeBold : \"\";\n const dimCode = typoStyle.dim ? ttyCodeDim : \"\";\n const italicCode = typoStyle.italic ? ttyCodeItalic : \"\";\n const underlineCode = typoStyle.underline ? ttyCodeUnderline : \"\";\n const strikethroughCode = typoStyle.strikethrough\n ? ttyCodeStrikethrough\n : \"\";\n return `${fgColorCode}${bgColorCode}${boldCode}${dimCode}${italicCode}${underlineCode}${strikethroughCode}${value}${ttyCodeReset}`;\n }\n if (this.#kind === \"mock\") {\n const fgColorPart = typoStyle.fgColor\n ? `{${value}}@${typoStyle.fgColor}`\n : value;\n const bgColorPart = typoStyle.bgColor\n ? `{${fgColorPart}}#${typoStyle.bgColor}`\n : fgColorPart;\n const boldPart = typoStyle.bold ? `{${bgColorPart}}+` : bgColorPart;\n const dimPart = typoStyle.dim ? `{${boldPart}}-` : boldPart;\n const italicPart = typoStyle.italic ? `{${dimPart}}*` : dimPart;\n const underlinePart = typoStyle.underline\n ? `{${italicPart}}_`\n : italicPart;\n const strikethroughPart = typoStyle.strikethrough\n ? `{${underlinePart}}~`\n : underlinePart;\n return strikethroughPart;\n }\n throw new Error(`Unknown TypoSupport kind: ${this.#kind}`);\n }\n computeStyledErrorMessage(error: unknown): string {\n return [\n this.computeStyledString(\"Error:\", typoStyleFailure),\n error instanceof TypoError\n ? error.computeStyledString(this)\n : error instanceof Error\n ? error.message\n : String(error),\n ].join(\" \");\n }\n}\n\nconst ttyCodeReset = \"\\x1b[0m\";\nconst ttyCodeBold = \"\\x1b[1m\";\nconst ttyCodeDim = \"\\x1b[2m\";\nconst ttyCodeItalic = \"\\x1b[3m\";\nconst ttyCodeUnderline = \"\\x1b[4m\";\nconst ttyCodeStrikethrough = \"\\x1b[9m\";\nconst ttyCodeFgColors: Record<TypoColor, string> = {\n darkBlack: \"\\x1b[30m\",\n darkRed: \"\\x1b[31m\",\n darkGreen: \"\\x1b[32m\",\n darkYellow: \"\\x1b[33m\",\n darkBlue: \"\\x1b[34m\",\n darkMagenta: \"\\x1b[35m\",\n darkCyan: \"\\x1b[36m\",\n darkWhite: \"\\x1b[37m\",\n brightBlack: \"\\x1b[90m\",\n brightRed: \"\\x1b[91m\",\n brightGreen: \"\\x1b[92m\",\n brightYellow: \"\\x1b[93m\",\n brightBlue: \"\\x1b[94m\",\n brightMagenta: \"\\x1b[95m\",\n brightCyan: \"\\x1b[96m\",\n brightWhite: \"\\x1b[97m\",\n};\nconst ttyCodeBgColors: Record<TypoColor, string> = {\n darkBlack: \"\\x1b[40m\",\n darkRed: \"\\x1b[41m\",\n darkGreen: \"\\x1b[42m\",\n darkYellow: \"\\x1b[43m\",\n darkBlue: \"\\x1b[44m\",\n darkMagenta: \"\\x1b[45m\",\n darkCyan: \"\\x1b[46m\",\n darkWhite: \"\\x1b[47m\",\n brightBlack: \"\\x1b[100m\",\n brightRed: \"\\x1b[101m\",\n brightGreen: \"\\x1b[102m\",\n brightYellow: \"\\x1b[103m\",\n brightBlue: \"\\x1b[104m\",\n brightMagenta: \"\\x1b[105m\",\n brightCyan: \"\\x1b[106m\",\n brightWhite: \"\\x1b[107m\",\n};\n","import { Operation } from \"./Operation\";\nimport { OptionUsage } from \"./Option\";\nimport { PositionalUsage } from \"./Positional\";\nimport { ReaderArgs } from \"./Reader\";\nimport { TypoError, TypoString, typoStyleConstants, TypoText } from \"./Typo\";\n\nexport type Command<Context, Result> = {\n getDescription(): string | undefined;\n createRunnerFromArgs(readerArgs: ReaderArgs): CommandRunner<Context, Result>;\n};\n\nexport type CommandRunner<Context, Result> = {\n generateUsage(): CommandUsage;\n executeWithContext(context: Context): Promise<Result>;\n};\n\nexport type CommandMetadata = {\n description: string;\n details?: string;\n // TODO - printable examples ?\n};\n\nexport type CommandUsage = {\n metadata: CommandMetadata;\n breadcrumbs: Array<CommandUsageBreadcrumb>;\n positionals: Array<PositionalUsage>;\n subcommands: Array<CommandUsageSubcommand>;\n options: Array<OptionUsage>;\n};\n\nexport type CommandUsageBreadcrumb =\n | { positional: string }\n | { command: string };\n\nexport type CommandUsageSubcommand = {\n name: string;\n description: string | undefined;\n};\n\nexport function command<Context, Result>(\n metadata: CommandMetadata,\n operation: Operation<Context, Result>,\n): Command<Context, Result> {\n return {\n getDescription() {\n return metadata.description;\n },\n createRunnerFromArgs(readerArgs: ReaderArgs) {\n function generateUsage(): CommandUsage {\n const operationUsage = operation.generateUsage();\n return {\n metadata,\n breadcrumbs: operationUsage.positionals.map((positional) =>\n breadcrumbPositional(positional.label),\n ),\n positionals: operationUsage.positionals,\n subcommands: [],\n options: operationUsage.options,\n };\n }\n try {\n const operationRunner = operation.createRunnerFromArgs(readerArgs);\n const endPositional = readerArgs.consumePositional();\n if (endPositional !== undefined) {\n throw Error(`Unexpected argument: \"${endPositional}\"`);\n }\n return {\n generateUsage,\n async executeWithContext(context: Context) {\n return operationRunner.executeWithContext(context);\n },\n };\n } catch (error) {\n return {\n generateUsage,\n async executeWithContext() {\n throw error;\n },\n };\n }\n },\n };\n}\n\nexport function commandWithSubcommands<Context, Payload, Result>(\n metadata: CommandMetadata,\n operation: Operation<Context, Payload>,\n subcommands: { [subcommand: Lowercase<string>]: Command<Payload, Result> },\n): Command<Context, Result> {\n return {\n getDescription() {\n return metadata.description;\n },\n createRunnerFromArgs(readerArgs: ReaderArgs) {\n try {\n const operationRunner = operation.createRunnerFromArgs(readerArgs);\n const subcommandName = readerArgs.consumePositional();\n if (subcommandName === undefined) {\n throw new TypoError(\n new TypoText(\n new TypoString(`Missing required positional argument: `),\n new TypoString(`SUBCOMMAND`, typoStyleConstants),\n ),\n );\n }\n const subcommandInput =\n subcommands[subcommandName as Lowercase<string>];\n if (subcommandInput === undefined) {\n throw new TypoError(\n new TypoText(\n new TypoString(`Invalid value for positional argument: `),\n new TypoString(`SUBCOMMAND`, typoStyleConstants),\n new TypoString(`: \"${subcommandName}\"`),\n ),\n );\n }\n const subcommandRunner =\n subcommandInput.createRunnerFromArgs(readerArgs);\n return {\n generateUsage() {\n const operationUsage = operation.generateUsage();\n const subcommandUsage = subcommandRunner.generateUsage();\n return {\n metadata: subcommandUsage.metadata,\n breadcrumbs: operationUsage.positionals\n .map((positional) => breadcrumbPositional(positional.label))\n .concat([breadcrumbCommand(subcommandName)])\n .concat(subcommandUsage.breadcrumbs),\n positionals: operationUsage.positionals.concat(\n subcommandUsage.positionals,\n ),\n subcommands: subcommandUsage.subcommands,\n options: operationUsage.options.concat(subcommandUsage.options),\n };\n },\n async executeWithContext(context: Context) {\n return await subcommandRunner.executeWithContext(\n await operationRunner.executeWithContext(context),\n );\n },\n };\n } catch (error) {\n return {\n generateUsage() {\n const operationUsage = operation.generateUsage();\n return {\n metadata,\n breadcrumbs: operationUsage.positionals\n .map((positional) => breadcrumbPositional(positional.label))\n .concat([breadcrumbCommand(\"<SUBCOMMAND>\")]),\n positionals: operationUsage.positionals,\n subcommands: Object.entries(subcommands).map(\n ([name, subcommand]) => ({\n name,\n description: subcommand.getDescription(),\n }),\n ),\n options: operationUsage.options,\n };\n },\n async executeWithContext() {\n throw error;\n },\n };\n }\n },\n };\n}\n\nexport function commandChained<Context, Payload, Result>(\n metadata: CommandMetadata,\n operation: Operation<Context, Payload>,\n nextCommand: Command<Payload, Result>,\n): Command<Context, Result> {\n return {\n getDescription() {\n return metadata.description;\n },\n createRunnerFromArgs(readerArgs: ReaderArgs) {\n const operationRunner = operation.createRunnerFromArgs(readerArgs);\n const nextCommandRunner = nextCommand.createRunnerFromArgs(readerArgs);\n return {\n generateUsage() {\n const operationUsage = operation.generateUsage();\n const nextCommandUsage = nextCommandRunner.generateUsage();\n return {\n metadata: nextCommandUsage.metadata,\n breadcrumbs: operationUsage.positionals\n .map((positional) => breadcrumbPositional(positional.label))\n .concat(nextCommandUsage.breadcrumbs),\n positionals: operationUsage.positionals.concat(\n nextCommandUsage.positionals,\n ),\n subcommands: nextCommandUsage.subcommands,\n options: operationUsage.options.concat(nextCommandUsage.options),\n };\n },\n async executeWithContext(context: Context) {\n return await nextCommandRunner.executeWithContext(\n await operationRunner.executeWithContext(context),\n );\n },\n };\n },\n };\n}\n\nfunction breadcrumbPositional(value: string): CommandUsageBreadcrumb {\n return { positional: value };\n}\n\nfunction breadcrumbCommand(value: string): CommandUsageBreadcrumb {\n return { command: value };\n}\n","import { Option, OptionUsage } from \"./Option\";\nimport { Positional, PositionalUsage } from \"./Positional\";\nimport { ReaderArgs } from \"./Reader\";\n\nexport type Operation<Input, Output> = {\n generateUsage(): OperationUsage;\n createRunnerFromArgs(readerArgs: ReaderArgs): OperationRunner<Input, Output>;\n};\n\nexport type OperationRunner<Input, Output> = {\n executeWithContext(input: Input): Promise<Output>;\n};\n\nexport type OperationUsage = {\n options: Array<OptionUsage>;\n positionals: Array<PositionalUsage>;\n};\n\nexport function operation<\n Context,\n Result,\n Options extends { [option: string]: any },\n const Positionals extends Array<any>,\n>(\n inputs: {\n options: { [K in keyof Options]: Option<Options[K]> };\n positionals: { [K in keyof Positionals]: Positional<Positionals[K]> };\n },\n handler: (\n context: Context,\n inputs: { options: Options; positionals: Positionals },\n ) => Promise<Result>,\n): Operation<Context, Result> {\n return {\n generateUsage() {\n const optionsUsage = new Array<OptionUsage>();\n for (const optionKey in inputs.options) {\n const optionInput = inputs.options[optionKey]!;\n if (optionInput) {\n optionsUsage.push(optionInput.generateUsage());\n }\n }\n const positionalsUsage = new Array<PositionalUsage>();\n for (const positionalInput of inputs.positionals) {\n positionalsUsage.push(positionalInput.generateUsage());\n }\n return { options: optionsUsage, positionals: positionalsUsage };\n },\n createRunnerFromArgs(readerArgs: ReaderArgs) {\n const optionsGetters: any = {};\n for (const optionKey in inputs.options) {\n const optionInput = inputs.options[optionKey]!;\n optionsGetters[optionKey] = optionInput.createGetter(readerArgs);\n }\n const positionalsValues: any = [];\n for (const positionalInput of inputs.positionals) {\n positionalsValues.push(positionalInput.consumePositionals(readerArgs));\n }\n return {\n executeWithContext(context: Context) {\n const optionsValues: any = {};\n for (const optionKey in optionsGetters) {\n optionsValues[optionKey] = optionsGetters[optionKey]!.getValue();\n }\n return handler(context, {\n options: optionsValues,\n positionals: positionalsValues,\n });\n },\n };\n },\n };\n}\n","import { TypoError, TypoString, typoStyleUserInput, TypoText } from \"./Typo\";\n\nexport type Type<Value> = {\n // TODO - maybe include an optional hint ??\n label: Uppercase<string>; // TODO - is there a better way to enforce uppercase labels?\n decoder(value: string): Value;\n};\n\nexport const typeBoolean: Type<boolean> = {\n label: \"BOOLEAN\",\n decoder(value: string) {\n const lowerValue = value.toLowerCase();\n if (lowerValue === \"true\" || lowerValue === \"yes\") {\n return true;\n }\n if (lowerValue === \"false\" || lowerValue === \"no\") {\n return false;\n }\n throw new Error(`Invalid value: \"${value}\"`);\n },\n};\n\nexport const typeDate: Type<Date> = {\n label: \"DATE\",\n decoder(value: string) {\n const timestamp = Date.parse(value);\n if (isNaN(timestamp)) {\n throw new Error(`Invalid ISO_8601 value: \"${value}\"`);\n }\n return new Date(timestamp);\n },\n};\n\nexport const typeUrl: Type<URL> = {\n label: \"URL\",\n decoder(value: string) {\n return new URL(value);\n },\n};\n\nexport const typeString: Type<string> = {\n label: \"STRING\",\n decoder(value: string) {\n return value;\n },\n};\n\nexport const typeNumber: Type<number> = {\n label: \"NUMBER\",\n decoder(value: string) {\n return Number(value);\n },\n};\n\nexport const typeBigInt: Type<bigint> = {\n label: \"BIGINT\",\n decoder(value: string) {\n return BigInt(value);\n },\n};\n\nexport function typeMapped<Before, After>(\n before: Type<Before>,\n after: {\n label: Uppercase<string>;\n decoder: (value: Before) => After;\n },\n): Type<After> {\n return {\n label: after.label,\n decoder: (value: string) => {\n return after.decoder(\n typeDecode(\n before,\n value,\n () => new TypoText(new TypoString(before.label, typoStyleUserInput)),\n ),\n );\n },\n };\n}\n\nexport function typeOneOf<Value>(\n type: Type<Value>,\n values: Array<Value>,\n): Type<Value> {\n const valuesSet = new Set(values);\n return {\n label: type.label,\n decoder(value: string) {\n const decoded = typeDecode(\n type,\n value,\n () => new TypoText(new TypoString(type.label, typoStyleUserInput)),\n );\n if (valuesSet.has(decoded)) {\n return decoded;\n }\n const valuesDesc = values.map((v) => `\"${v}\"`).join(\"|\");\n throw new Error(`Unexpected value: \"${value}\" (expected: ${valuesDesc})`);\n },\n };\n}\n\nexport function typeTuple<const Elements extends Array<any>>(\n elementTypes: { [K in keyof Elements]: Type<Elements[K]> },\n separator: string = \",\",\n): Type<Elements> {\n return {\n label: elementTypes\n .map((elementType) => elementType.label)\n .join(separator) as Uppercase<string>,\n decoder(value: string) {\n const parts = value.split(separator, elementTypes.length);\n if (parts.length !== elementTypes.length) {\n throw new Error(`Invalid tuple parts: ${JSON.stringify(parts)}`);\n }\n return parts.map((part, index) =>\n typeDecode(\n elementTypes[index]!,\n part,\n () =>\n new TypoText(\n new TypoString(elementTypes[index]!.label, typoStyleUserInput),\n new TypoString(` at position ${index}`),\n ),\n ),\n ) as Elements;\n },\n };\n}\n\nexport function typeList<Value>(\n elementType: Type<Value>,\n separator: string = \",\",\n): Type<Array<Value>> {\n return {\n label:\n `${elementType.label}[${separator}${elementType.label}]...` as Uppercase<string>,\n decoder(value: string) {\n return value\n .split(separator)\n .map((part, index) =>\n typeDecode(\n elementType,\n part,\n () =>\n new TypoText(\n new TypoString(elementType.label, typoStyleUserInput),\n new TypoString(` at position ${index}`),\n ),\n ),\n );\n },\n };\n}\n\nexport function typeDecode<Value>(\n type: Type<Value>,\n value: string,\n context: () => TypoText,\n): Value {\n try {\n return type.decoder(value);\n } catch (error) {\n throw new TypoError(context(), error);\n }\n}\n","import { ReaderArgs as ReaderOptions } from \"./Reader\";\nimport { Type, typeBoolean, typeDecode } from \"./Type\";\nimport {\n TypoError,\n TypoString,\n typoStyleConstants,\n typoStyleUserInput,\n TypoText,\n} from \"./Typo\";\n\nexport type Option<Value> = {\n generateUsage(): OptionUsage;\n createGetter(readerOptions: ReaderOptions): OptionGetter<Value>;\n};\n\nexport type OptionUsage = {\n description: string | undefined;\n long: Lowercase<string>; // TODO - better type for long option names ?\n short: string | undefined;\n label: Uppercase<string> | undefined;\n // TODO - default value for usage ? but it can be dynamic, so maybe not\n};\n\nexport type OptionGetter<Value> = {\n getValue(): Value;\n};\n\nexport function optionFlag(definition: {\n long: Lowercase<string>;\n short?: string;\n description?: string;\n aliases?: { longs?: Array<Lowercase<string>>; shorts?: Array<string> };\n default?: () => boolean;\n}): Option<boolean> {\n return {\n generateUsage() {\n return {\n description: definition.description,\n long: definition.long,\n short: definition.short,\n label: undefined,\n };\n },\n createGetter(readerOptions: ReaderOptions) {\n const key = registerOption(readerOptions, {\n ...definition,\n valued: false,\n });\n return {\n getValue() {\n const optionValues = readerOptions.getOptionValues(key);\n if (optionValues.length > 1) {\n throw new TypoError(\n new TypoText(\n new TypoString(`Option value for: `),\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: must not be set multiple times`),\n ),\n );\n }\n const optionValue = optionValues[0];\n if (optionValue === undefined) {\n // TODO - scoped error util\n try {\n return definition.default ? definition.default() : false;\n } catch (error) {\n throw new TypoError(\n new TypoText(\n new TypoString(`Failed to compute default value for: `),\n new TypoString(`--${definition.long}`, typoStyleConstants),\n ),\n error,\n );\n }\n }\n return typeDecode(\n typeBoolean,\n optionValue,\n () =>\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: `),\n new TypoString(typeBoolean.label, typoStyleUserInput),\n ),\n );\n },\n };\n },\n };\n}\n\nexport function optionSingleValue<Value>(definition: {\n long: Lowercase<string>;\n short?: string;\n description?: string;\n aliases?: { longs?: Array<Lowercase<string>>; shorts?: Array<string> };\n label?: Uppercase<string>;\n type: Type<Value>;\n default: () => Value;\n}): Option<Value> {\n const label = definition.label ?? definition.type.label;\n return {\n generateUsage() {\n return {\n description: definition.description,\n long: definition.long,\n short: definition.short,\n label: `<${label}>` as Uppercase<string>,\n };\n },\n createGetter(readerOptions: ReaderOptions) {\n const key = registerOption(readerOptions, {\n ...definition,\n valued: true,\n });\n return {\n getValue() {\n const optionValues = readerOptions.getOptionValues(key);\n if (optionValues.length > 1) {\n throw new TypoError(\n new TypoText(\n new TypoString(`Option value for: `),\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: must not be set multiple times`),\n ),\n );\n }\n const optionValue = optionValues[0];\n if (optionValue === undefined) {\n try {\n return definition.default();\n } catch (error) {\n throw new TypoError(\n new TypoText(\n new TypoString(`Failed to compute default value for: `),\n new TypoString(`--${definition.long}`, typoStyleConstants),\n ),\n error,\n );\n }\n }\n return typeDecode(\n definition.type,\n optionValue,\n () =>\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: `),\n new TypoString(label, typoStyleUserInput),\n ),\n );\n },\n };\n },\n };\n}\n\nexport function optionRepeatable<Value>(definition: {\n long: Lowercase<string>;\n short?: string;\n description?: string;\n aliases?: { longs?: Array<Lowercase<string>>; shorts?: Array<string> };\n label?: Uppercase<string>;\n type: Type<Value>;\n}): Option<Array<Value>> {\n const label = definition.label ?? definition.type.label;\n return {\n generateUsage() {\n // TODO - showcase that it can be repeated ?\n return {\n description: definition.description,\n long: definition.long,\n short: definition.short,\n label: `<${label}>` as Uppercase<string>,\n };\n },\n createGetter(readerOptions: ReaderOptions) {\n const key = registerOption(readerOptions, {\n ...definition,\n valued: true,\n });\n return {\n getValue() {\n return readerOptions\n .getOptionValues(key)\n .map((value) =>\n typeDecode(\n definition.type,\n value,\n () =>\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: `),\n new TypoString(label, typoStyleUserInput),\n ),\n ),\n );\n },\n };\n },\n };\n}\n\nfunction registerOption(\n readerOptions: ReaderOptions,\n definition: {\n long: Lowercase<string>;\n short?: string;\n aliases?: { longs?: Array<Lowercase<string>>; shorts?: Array<string> };\n valued: boolean;\n },\n) {\n const { long, short, aliases, valued } = definition;\n const longs = long ? [long] : [];\n if (aliases?.longs) {\n longs.push(...aliases?.longs);\n }\n const shorts = short ? [short] : [];\n if (aliases?.shorts) {\n shorts.push(...aliases?.shorts);\n }\n return readerOptions.registerOption({ longs, shorts, valued });\n}\n","import { ReaderPositionals } from \"./Reader\";\nimport { Type, typeDecode } from \"./Type\";\nimport { TypoError, TypoString, typoStyleUserInput, TypoText } from \"./Typo\";\n\nexport type Positional<Value> = {\n generateUsage(): PositionalUsage;\n consumePositionals(readerPositionals: ReaderPositionals): Value;\n};\n\nexport type PositionalUsage = {\n description: string | undefined;\n label: Uppercase<string>;\n};\n\nexport function positionalRequired<Value>(definition: {\n description?: string;\n label?: Uppercase<string>;\n type: Type<Value>;\n}): Positional<Value> {\n const label = definition.label ?? definition.type.label;\n return {\n generateUsage() {\n return {\n description: definition.description,\n label: `<${label}>` as Uppercase<string>,\n };\n },\n consumePositionals(readerPositionals: ReaderPositionals) {\n const positional = readerPositionals.consumePositional();\n if (positional === undefined) {\n throw new TypoError(\n new TypoText(\n new TypoString(`Missing required positional argument: `),\n new TypoString(label, typoStyleUserInput),\n ),\n );\n }\n return typeDecode(\n definition.type,\n positional,\n () => new TypoText(new TypoString(label, typoStyleUserInput)),\n );\n },\n };\n}\n\nexport function positionalOptional<Value>(definition: {\n description?: string;\n label?: Uppercase<string>;\n type: Type<Value>;\n default: () => Value;\n}): Positional<Value> {\n const label = definition.label ?? definition.type.label;\n return {\n generateUsage() {\n return {\n description: definition.description,\n label: `[${label}]` as Uppercase<string>,\n };\n },\n consumePositionals(readerPositionals: ReaderPositionals) {\n const positional = readerPositionals.consumePositional();\n if (positional === undefined) {\n try {\n return definition.default();\n } catch (error) {\n throw new TypoError(\n new TypoText(\n new TypoString(`Failed to compute default value for: `),\n new TypoString(label, typoStyleUserInput),\n ),\n error,\n );\n }\n }\n return typeDecode(\n definition.type,\n positional,\n () => new TypoText(new TypoString(label, typoStyleUserInput)),\n );\n },\n };\n}\n\nexport function positionalVariadics<Value>(definition: {\n endDelimiter?: string;\n description?: string;\n label?: Uppercase<string>;\n type: Type<Value>;\n}): Positional<Array<Value>> {\n const label = definition.label ?? definition.type.label;\n return {\n generateUsage() {\n return {\n description: definition.description,\n label: (`[${label}]...` +\n (definition.endDelimiter\n ? `[\"${definition.endDelimiter}\"]`\n : \"\")) as Uppercase<string>,\n };\n },\n consumePositionals(readerPositionals: ReaderPositionals) {\n const positionals: Array<Value> = [];\n while (true) {\n const positional = readerPositionals.consumePositional();\n if (\n positional === undefined ||\n positional === definition.endDelimiter\n ) {\n break;\n }\n positionals.push(\n typeDecode(\n definition.type,\n positional,\n () => new TypoText(new TypoString(label, typoStyleUserInput)),\n ),\n );\n }\n return positionals;\n },\n };\n}\n","import { TypoError, TypoString, typoStyleConstants, TypoText } from \"./Typo\";\n\nexport type ReaderOptionKey = (string | { __brand: \"ReaderOptionKey\" }) & {\n __brand: \"ReaderOptionKey\";\n};\n\nexport type ReaderOptions = {\n registerOption(definition: {\n longs: Array<string>;\n shorts: Array<string>;\n valued: boolean;\n }): ReaderOptionKey;\n getOptionValues(key: ReaderOptionKey): Array<string>;\n};\n\nexport type ReaderPositionals = {\n consumePositional(): string | undefined;\n};\n\nexport class ReaderArgs {\n #args: ReadonlyArray<string>;\n #parsedIndex: number;\n #parsedDouble: boolean;\n #keyByLong: Map<string, ReaderOptionKey>;\n #keyByShort: Map<string, ReaderOptionKey>;\n #valuedByKey: Map<ReaderOptionKey, boolean>;\n #resultByKey: Map<ReaderOptionKey, Array<string>>;\n\n constructor(args: ReadonlyArray<string>) {\n this.#args = args;\n this.#parsedIndex = 0;\n this.#parsedDouble = false;\n this.#keyByLong = new Map();\n this.#keyByShort = new Map();\n this.#valuedByKey = new Map();\n this.#resultByKey = new Map();\n }\n\n registerOption(definition: {\n longs: Array<string>;\n shorts: Array<string>;\n valued: boolean;\n }) {\n const key = [\n ...definition.longs.map((long) => `--${long}`),\n ...definition.shorts.map((short) => `-${short}`),\n ].join(\", \") as ReaderOptionKey;\n for (const long of definition.longs) {\n if (this.#keyByLong.has(long)) {\n throw new Error(`Option already registered: --${long}`);\n }\n this.#keyByLong.set(long, key);\n }\n for (const short of definition.shorts) {\n if (this.#keyByShort.has(short)) {\n throw new Error(`Option already registered: -${short}`);\n }\n for (let i = 0; i < short.length; i++) {\n const shortSlice = short.slice(0, i);\n if (this.#keyByShort.has(shortSlice)) {\n throw new Error(\n `Option -${short} overlap with shorter option: -${shortSlice}`,\n );\n }\n }\n for (const shortOther of this.#keyByShort.keys()) {\n if (shortOther.startsWith(short)) {\n throw new Error(\n `Option -${short} overlap with longer option: -${shortOther}`,\n );\n }\n }\n this.#keyByShort.set(short, key);\n }\n this.#valuedByKey.set(key, definition.valued);\n this.#resultByKey.set(key, new Array<string>());\n return key;\n }\n\n getOptionValues(key: ReaderOptionKey): Array<string> {\n const optionResult = this.#resultByKey.get(key);\n if (optionResult === undefined) {\n throw new Error(`Unregistered option: ${key}`);\n }\n return optionResult;\n }\n\n consumePositional(): string | undefined {\n while (true) {\n const arg = this.#consumeArg();\n if (arg === null) {\n return undefined;\n }\n if (this.#processedAsPositional(arg)) {\n return arg;\n }\n }\n }\n\n #consumeArg(): string | null {\n const arg = this.#args[this.#parsedIndex];\n if (arg === undefined) {\n return null;\n }\n this.#parsedIndex++;\n if (!this.#parsedDouble) {\n if (arg === \"--\") {\n this.#parsedDouble = true;\n return this.#consumeArg();\n }\n }\n return arg;\n }\n\n #processedAsPositional(arg: string): boolean {\n if (this.#parsedDouble) {\n return true;\n }\n if (arg.startsWith(\"--\")) {\n const valueIndexStart = arg.indexOf(\"=\");\n if (valueIndexStart === -1) {\n this.#consumeOptionLong(arg.slice(2), null);\n } else {\n this.#consumeOptionLong(\n arg.slice(2, valueIndexStart),\n arg.slice(valueIndexStart + 1),\n );\n }\n return false;\n }\n if (arg.startsWith(\"-\")) {\n let shortIndexStart = 1;\n let shortIndexEnd = 2;\n while (shortIndexEnd <= arg.length) {\n const result = this.#tryConsumeOptionShort(\n arg.slice(shortIndexStart, shortIndexEnd),\n arg.slice(shortIndexEnd),\n );\n if (result === true) {\n return false;\n }\n if (result === false) {\n shortIndexStart = shortIndexEnd;\n }\n shortIndexEnd++;\n }\n throw new TypoError(\n new TypoText(\n new TypoString(`Unknown option: `),\n new TypoString(`-${arg.slice(shortIndexStart)}`, typoStyleConstants),\n ),\n );\n }\n return true;\n }\n\n #consumeOptionLong(long: string, direct: string | null): void {\n const constant = `--${long}`;\n const key = this.#keyByLong.get(long);\n if (key !== undefined) {\n if (direct !== null) {\n return this.#acknowledgeOption(key, direct);\n }\n const valued = this.#valuedByKey.get(key);\n if (valued) {\n return this.#acknowledgeOption(key, this.#consumeOptionValue(constant));\n }\n return this.#acknowledgeOption(key, \"true\");\n }\n throw new TypoError(\n new TypoText(\n new TypoString(`Unknown option: `),\n new TypoString(constant, typoStyleConstants),\n ),\n );\n }\n\n #tryConsumeOptionShort(short: string, rest: string): boolean | null {\n const key = this.#keyByShort.get(short);\n if (key !== undefined) {\n if (rest.startsWith(\"=\")) {\n this.#acknowledgeOption(key, rest.slice(1));\n return true;\n }\n const valued = this.#valuedByKey.get(key);\n if (valued) {\n if (rest === \"\") {\n this.#acknowledgeOption(key, this.#consumeOptionValue(`-${short}`));\n } else {\n this.#acknowledgeOption(key, rest);\n }\n return true;\n }\n this.#acknowledgeOption(key, \"true\");\n return rest === \"\";\n }\n return null;\n }\n\n #consumeOptionValue(constant: string) {\n const arg = this.#consumeArg();\n if (arg === null) {\n throw new TypoError(\n new TypoText(\n new TypoString(`Option parsing: `),\n new TypoString(constant, typoStyleConstants),\n new TypoString(`: requires a value, but got end of input`),\n ),\n );\n }\n if (this.#parsedDouble) {\n throw new TypoError(\n new TypoText(\n new TypoString(`Option parsing: `),\n new TypoString(constant, typoStyleConstants),\n new TypoString(`: requires a value before \"--\"`),\n ),\n );\n }\n // TODO - is that weird, could a valid value start with dash ?\n if (arg.startsWith(\"-\")) {\n throw new TypoError(\n new TypoText(\n new TypoString(`Option parsing: `),\n new TypoString(constant, typoStyleConstants),\n new TypoString(`: requires a value, but got: \"${arg}\"`),\n ),\n );\n }\n return arg;\n }\n\n #acknowledgeOption(key: ReaderOptionKey, value: string) {\n this.getOptionValues(key).push(value);\n }\n}\n","import { CommandUsage } from \"./Command\";\nimport {\n TypoGrid,\n TypoString,\n typoStyleConstants,\n typoStyleUserInput,\n TypoSupport,\n TypoText,\n} from \"./Typo\";\n\nexport function usageToStyledLines(params: {\n cliName: Lowercase<string>;\n commandUsage: CommandUsage;\n typoSupport: TypoSupport;\n}) {\n const { cliName, commandUsage, typoSupport } = params;\n\n const lines = new Array<string>();\n\n // TODO - description stacking for subcommands ?\n lines.push(\n textOverview(commandUsage.metadata.description).computeStyledString(\n typoSupport,\n ),\n );\n if (commandUsage.metadata.details) {\n lines.push(\n textSubtleInfo(commandUsage.metadata.details).computeStyledString(\n typoSupport,\n ),\n );\n }\n\n lines.push(\"\");\n const breadcrumbs = [\n textUsageTitle(\"Usage:\").computeStyledString(typoSupport),\n textConstants(cliName).computeStyledString(typoSupport),\n ].concat(\n commandUsage.breadcrumbs.map((breadcrumb) => {\n if (\"positional\" in breadcrumb) {\n return textUserInput(breadcrumb.positional).computeStyledString(\n typoSupport,\n );\n }\n if (\"command\" in breadcrumb) {\n return textConstants(breadcrumb.command).computeStyledString(\n typoSupport,\n );\n }\n throw new Error(`Unknown breadcrumb: ${JSON.stringify(breadcrumb)}`);\n }),\n );\n lines.push(breadcrumbs.join(\" \"));\n\n if (commandUsage.positionals.length > 0) {\n lines.push(\"\");\n lines.push(textBlockTitle(\"Positionals:\").computeStyledString(typoSupport));\n const typoGrid = new TypoGrid();\n for (const positionalUsage of commandUsage.positionals) {\n const typoGridRow = new Array<TypoText>();\n typoGridRow.push(new TypoText(textDelimiter()));\n typoGridRow.push(new TypoText(textUserInput(positionalUsage.label)));\n if (positionalUsage.description) {\n typoGridRow.push(new TypoText(textDelimiter()));\n typoGridRow.push(\n new TypoText(textUsefulInfo(positionalUsage.description)),\n );\n }\n typoGrid.pushRow(typoGridRow);\n }\n lines.push(\n ...typoGrid.computeStyledGrid(typoSupport).map((row) => row.join(\"\")),\n );\n }\n\n if (commandUsage.subcommands.length > 0) {\n lines.push(\"\");\n lines.push(textBlockTitle(\"Subcommands:\").computeStyledString(typoSupport));\n const typoGrid = new TypoGrid();\n for (const subcommand of commandUsage.subcommands) {\n const typoGridRow = new Array<TypoText>();\n typoGridRow.push(new TypoText(textDelimiter()));\n typoGridRow.push(new TypoText(textConstants(subcommand.name)));\n if (subcommand.description) {\n typoGridRow.push(new TypoText(textDelimiter()));\n typoGridRow.push(new TypoText(textUsefulInfo(subcommand.description)));\n }\n typoGrid.pushRow(typoGridRow);\n }\n lines.push(\n ...typoGrid.computeStyledGrid(typoSupport).map((row) => row.join(\"\")),\n );\n }\n\n if (commandUsage.options.length > 0) {\n lines.push(\"\");\n lines.push(textBlockTitle(\"Options:\").computeStyledString(typoSupport));\n const typoGrid = new TypoGrid();\n for (const optionUsage of commandUsage.options) {\n const typoGridRow = new Array<TypoText>();\n typoGridRow.push(new TypoText(textDelimiter()));\n if (optionUsage.short) {\n typoGridRow.push(\n new TypoText(\n textConstants(`-${optionUsage.short}`),\n textDelimiter(\", \"),\n ),\n );\n } else {\n typoGridRow.push(new TypoText());\n }\n if (optionUsage.label) {\n typoGridRow.push(\n new TypoText(\n textConstants(`--${optionUsage.long}`),\n textDelimiter(\" \"),\n textUserInput(optionUsage.label),\n ),\n );\n } else {\n typoGridRow.push(\n new TypoText(\n textConstants(`--${optionUsage.long}`),\n textSubtleInfo(\"[=no]\"),\n ),\n );\n }\n if (optionUsage.description) {\n typoGridRow.push(new TypoText(textDelimiter()));\n typoGridRow.push(new TypoText(textUsefulInfo(optionUsage.description)));\n }\n typoGrid.pushRow(typoGridRow);\n }\n lines.push(\n ...typoGrid.computeStyledGrid(typoSupport).map((row) => row.join(\"\")),\n );\n }\n\n lines.push(\"\");\n return lines;\n}\n\nfunction textOverview(value: string): TypoString {\n return new TypoString(value, { bold: true });\n}\n\nfunction textUsefulInfo(value: string): TypoString {\n return new TypoString(value);\n}\n\nfunction textSubtleInfo(value: string): TypoString {\n return new TypoString(value, { italic: true, dim: true });\n}\n\nfunction textUsageTitle(value: string): TypoString {\n return new TypoString(value, { fgColor: \"darkMagenta\", bold: true });\n}\n\nfunction textBlockTitle(value: string): TypoString {\n return new TypoString(value, { fgColor: \"darkGreen\", bold: true });\n}\n\nfunction textConstants(value: string): TypoString {\n return new TypoString(value, typoStyleConstants);\n}\n\nfunction textUserInput(value: string): TypoString {\n return new TypoString(value, typoStyleUserInput);\n}\n\nfunction textDelimiter(value?: string): TypoString {\n return new TypoString(value ?? \" \");\n}\n","import { Command, CommandRunner } from \"./Command\";\nimport { ReaderArgs } from \"./Reader\";\nimport { TypoSupport } from \"./Typo\";\nimport { usageToStyledLines } from \"./Usage\";\n\nexport async function runAsCliAndExit<Context>(\n cliName: Lowercase<string>,\n cliArgs: ReadonlyArray<string>,\n context: Context,\n command: Command<Context, void>,\n application?: {\n usageOnError?: boolean | undefined;\n usageOnHelp?: boolean | undefined;\n buildVersion?: string | undefined;\n useColors?: boolean | undefined;\n onLogStdOut?: ((message: string) => void) | undefined; // TODO - this is a problem, deep commands use console\n onLogStdErr?: ((message: string) => void) | undefined;\n onExit?: ((code: number) => never) | undefined;\n onError?: ((error: unknown) => void) | undefined;\n },\n): Promise<never> {\n // TODO - can those flags could be implemented as a chained command ??\n const readerArgs = new ReaderArgs(cliArgs);\n const buildVersion = application?.buildVersion;\n if (buildVersion) {\n readerArgs.registerOption({\n shorts: [],\n longs: [\"version\"],\n valued: false,\n });\n }\n const usageOnHelp = application?.usageOnHelp ?? true;\n if (usageOnHelp) {\n readerArgs.registerOption({\n shorts: [],\n longs: [\"help\"],\n valued: false,\n });\n }\n /*\n // TODO - handle completions ?\n readerArgs.registerFlag({\n key: \"completion\",\n shorts: [],\n longs: [\"completion\"],\n });\n */\n const commandRunner = command.createRunnerFromArgs(readerArgs);\n while (true) {\n const positional = readerArgs.consumePositional();\n if (positional === undefined) {\n break;\n }\n }\n const onLogStdOut = application?.onLogStdOut ?? console.log;\n const onExit = application?.onExit ?? process.exit;\n if (buildVersion) {\n if (readerArgs.getOptionValues(\"--version\" as any).length > 0) {\n onLogStdOut([cliName, buildVersion].join(\" \"));\n return onExit(0);\n }\n }\n if (usageOnHelp) {\n if (readerArgs.getOptionValues(\"--help\" as any).length > 0) {\n const typoSupport = chooseTypoSupport(application?.useColors);\n onLogStdOut(computeUsageString(cliName, commandRunner, typoSupport));\n return onExit(0);\n }\n }\n try {\n await commandRunner.executeWithContext(context);\n return onExit(0);\n } catch (error) {\n if (application?.onError) {\n application.onError(error);\n } else {\n const onLogStdErr = application?.onLogStdErr ?? console.error;\n const typoSupport = chooseTypoSupport(application?.useColors);\n if (application?.usageOnError ?? true) {\n onLogStdErr(computeUsageString(cliName, commandRunner, typoSupport));\n }\n onLogStdErr(typoSupport.computeStyledErrorMessage(error));\n }\n return onExit(1);\n }\n}\n\nfunction computeUsageString<Context, Result>(\n cliName: Lowercase<string>,\n commandRunner: CommandRunner<Context, Result>,\n typoSupport: TypoSupport,\n) {\n return usageToStyledLines({\n cliName,\n commandUsage: commandRunner.generateUsage(),\n typoSupport,\n }).join(\"\\n\");\n}\n\nfunction chooseTypoSupport(useColors?: boolean): TypoSupport {\n if (useColors === undefined) {\n return TypoSupport.inferFromProcess();\n }\n return useColors ? TypoSupport.tty() : TypoSupport.none();\n}\n"],"mappings":"m3BAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,gBAAAE,EAAA,cAA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IAAI,EAAIA,EAAY,KAAK,CAC1D","names":["index_exports","__export","ReaderArgs","TypoError","TypoGrid","TypoString","TypoSupport","TypoText","command","commandChained","commandWithSubcommands","operation","optionFlag","optionRepeatable","optionSingleValue","positionalOptional","positionalRequired","positionalVariadics","runAsCliAndExit","typeBigInt","typeBoolean","typeDate","typeDecode","typeList","typeMapped","typeNumber","typeOneOf","typeString","typeTuple","typeUrl","typoStyleConstants","typoStyleFailure","typoStyleUserInput","usageToStyledLines","__toCommonJS","typoStyleConstants","typoStyleUserInput","typoStyleFailure","_value","_typoStyle","TypoString","value","typoStyle","__privateAdd","__privateSet","__privateGet","typoSupport","_typoStrings","_TypoText","typoParts","typoPart","typoString","typoText","t","length","TypoText","_typoRows","TypoGrid","cells","widths","printableGrid","typoGridRow","typoGridColumnIndex","width","printableGridRow","typoGridCell","printableGridCell","padding","_typoText","_TypoError","currentTypoText","source","TypoError","_kind","_TypoSupport","kind","fgColorCode","ttyCodeFgColors","bgColorCode","ttyCodeBgColors","boldCode","ttyCodeBold","dimCode","ttyCodeDim","italicCode","ttyCodeItalic","underlineCode","ttyCodeUnderline","strikethroughCode","ttyCodeStrikethrough","ttyCodeReset","fgColorPart","bgColorPart","boldPart","dimPart","italicPart","underlinePart","error","TypoSupport","command","metadata","operation","readerArgs","generateUsage","operationUsage","positional","breadcrumbPositional","operationRunner","endPositional","context","error","commandWithSubcommands","subcommands","subcommandName","TypoError","TypoText","TypoString","typoStyleConstants","subcommandInput","subcommandRunner","subcommandUsage","breadcrumbCommand","name","subcommand","commandChained","nextCommand","nextCommandRunner","nextCommandUsage","value","operation","inputs","handler","optionsUsage","optionKey","optionInput","positionalsUsage","positionalInput","readerArgs","optionsGetters","positionalsValues","context","optionsValues","typeBoolean","value","lowerValue","typeDate","timestamp","typeUrl","typeString","typeNumber","typeBigInt","typeMapped","before","after","typeDecode","TypoText","TypoString","typoStyleUserInput","typeOneOf","type","values","valuesSet","decoded","valuesDesc","v","typeTuple","elementTypes","separator","elementType","parts","part","index","typeList","context","error","TypoError","optionFlag","definition","readerOptions","key","registerOption","optionValues","TypoError","TypoText","TypoString","typoStyleConstants","optionValue","error","typeDecode","typeBoolean","typoStyleUserInput","optionSingleValue","label","optionRepeatable","value","long","short","aliases","valued","longs","shorts","positionalRequired","definition","label","readerPositionals","positional","TypoError","TypoText","TypoString","typoStyleUserInput","typeDecode","positionalOptional","error","positionalVariadics","positionals","_args","_parsedIndex","_parsedDouble","_keyByLong","_keyByShort","_valuedByKey","_resultByKey","_ReaderArgs_instances","consumeArg_fn","processedAsPositional_fn","consumeOptionLong_fn","tryConsumeOptionShort_fn","consumeOptionValue_fn","acknowledgeOption_fn","ReaderArgs","args","__privateAdd","__privateSet","definition","key","long","short","__privateGet","i","shortSlice","shortOther","optionResult","arg","__privateMethod","__privateWrapper","valueIndexStart","shortIndexStart","shortIndexEnd","result","TypoError","TypoText","TypoString","typoStyleConstants","direct","constant","rest","value","usageToStyledLines","params","cliName","commandUsage","typoSupport","lines","textOverview","textSubtleInfo","breadcrumbs","textUsageTitle","textConstants","breadcrumb","textUserInput","textBlockTitle","typoGrid","TypoGrid","positionalUsage","typoGridRow","TypoText","textDelimiter","textUsefulInfo","row","subcommand","optionUsage","value","TypoString","typoStyleConstants","typoStyleUserInput","runAsCliAndExit","cliName","cliArgs","context","command","application","readerArgs","ReaderArgs","buildVersion","usageOnHelp","commandRunner","onLogStdOut","onExit","typoSupport","chooseTypoSupport","computeUsageString","error","onLogStdErr","usageToStyledLines","useColors","TypoSupport"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/lib/Typo.ts","../src/lib/Command.ts","../src/lib/Operation.ts","../src/lib/Type.ts","../src/lib/Option.ts","../src/lib/Positional.ts","../src/lib/Reader.ts","../src/lib/Usage.ts","../src/lib/Run.ts"],"sourcesContent":["export * from \"./lib/Command\";\nexport * from \"./lib/Operation\";\nexport * from \"./lib/Option\";\nexport * from \"./lib/Positional\";\nexport * from \"./lib/Reader\";\nexport * from \"./lib/Run\";\nexport * from \"./lib/Type\";\nexport * from \"./lib/Typo\";\nexport * from \"./lib/Usage\";\n","export type TypoColor =\n | \"darkBlack\"\n | \"darkRed\"\n | \"darkGreen\"\n | \"darkYellow\"\n | \"darkBlue\"\n | \"darkMagenta\"\n | \"darkCyan\"\n | \"darkWhite\"\n | \"brightBlack\"\n | \"brightRed\"\n | \"brightGreen\"\n | \"brightYellow\"\n | \"brightBlue\"\n | \"brightMagenta\"\n | \"brightCyan\"\n | \"brightWhite\";\n\nexport type TypoStyle = {\n fgColor?: TypoColor;\n bgColor?: TypoColor;\n dim?: boolean;\n bold?: boolean;\n italic?: boolean;\n underline?: boolean;\n strikethrough?: boolean;\n};\n\nexport const typoStyleConstants: TypoStyle = {\n fgColor: \"darkCyan\",\n bold: true,\n};\nexport const typoStyleUserInput: TypoStyle = {\n fgColor: \"darkBlue\",\n bold: true,\n};\nexport const typoStyleFailure: TypoStyle = {\n fgColor: \"darkRed\",\n bold: true,\n};\n\nexport class TypoString {\n #value: string;\n #typoStyle: TypoStyle;\n constructor(value: string, typoStyle: TypoStyle = {}) {\n this.#value = value;\n this.#typoStyle = typoStyle;\n }\n getRawString(): string {\n return this.#value;\n }\n computeStyledString(typoSupport: TypoSupport): string {\n return typoSupport.computeStyledString(this.#value, this.#typoStyle);\n }\n}\n\nexport class TypoText {\n #typoStrings: Array<TypoString>;\n constructor(...typoParts: Array<TypoText | TypoString | string>) {\n this.#typoStrings = [];\n for (const typoPart of typoParts) {\n if (typoPart instanceof TypoText) {\n this.pushText(typoPart);\n } else if (typoPart instanceof TypoString) {\n this.pushString(typoPart);\n } else if (typeof typoPart === \"string\") {\n this.pushString(new TypoString(typoPart));\n }\n }\n }\n pushString(typoString: TypoString) {\n this.#typoStrings.push(typoString);\n }\n pushText(typoText: TypoText) {\n for (const typoString of typoText.#typoStrings) {\n this.#typoStrings.push(typoString);\n }\n }\n computeStyledString(typoSupport: TypoSupport): string {\n return this.#typoStrings\n .map((t) => t.computeStyledString(typoSupport))\n .join(\"\");\n }\n computeRawString(): string {\n return this.#typoStrings.map((t) => t.getRawString()).join(\"\");\n }\n computeRawLength(): number {\n let length = 0;\n for (const typoString of this.#typoStrings) {\n length += typoString.getRawString().length;\n }\n return length;\n }\n}\n\nexport class TypoGrid {\n #typoRows: Array<Array<TypoText>>;\n constructor() {\n this.#typoRows = [];\n }\n pushRow(cells: Array<TypoText>) {\n this.#typoRows.push(cells);\n }\n computeStyledGrid(typoSupport: TypoSupport): Array<Array<string>> {\n const widths = new Array<number>();\n const printableGrid = new Array<Array<string>>();\n for (const typoGridRow of this.#typoRows) {\n for (\n let typoGridColumnIndex = 0;\n typoGridColumnIndex < typoGridRow.length;\n typoGridColumnIndex++\n ) {\n const typoGridCell = typoGridRow[typoGridColumnIndex]!;\n const width = typoGridCell.computeRawLength();\n if (\n widths[typoGridColumnIndex] === undefined ||\n width > widths[typoGridColumnIndex]!\n ) {\n widths[typoGridColumnIndex] = width;\n }\n }\n }\n for (const typoGridRow of this.#typoRows) {\n const printableGridRow = new Array<string>();\n for (\n let typoGridColumnIndex = 0;\n typoGridColumnIndex < typoGridRow.length;\n typoGridColumnIndex++\n ) {\n const typoGridCell = typoGridRow[typoGridColumnIndex]!;\n const printableGridCell = typoGridCell.computeStyledString(typoSupport);\n printableGridRow.push(printableGridCell);\n if (typoGridColumnIndex < typoGridRow.length - 1) {\n const width = typoGridCell.computeRawLength();\n const padding = \" \".repeat(widths[typoGridColumnIndex]! - width);\n printableGridRow.push(padding);\n }\n }\n printableGrid.push(printableGridRow);\n }\n return printableGrid;\n }\n}\n\nexport class TypoError extends Error {\n #typoText: TypoText;\n constructor(currentTypoText: TypoText, source?: unknown) {\n const typoText = new TypoText();\n typoText.pushText(currentTypoText);\n if (source instanceof Error) {\n typoText.pushString(new TypoString(`: ${source.message}`));\n } else if (source instanceof TypoError) {\n typoText.pushString(new TypoString(\": \"));\n typoText.pushText(source.#typoText);\n } else if (source !== undefined) {\n typoText.pushString(new TypoString(`: ${String(source)}`));\n }\n super(typoText.computeRawString());\n this.#typoText = typoText;\n }\n computeStyledString(typoSupport: TypoSupport): string {\n return this.#typoText.computeStyledString(typoSupport);\n }\n}\n\nexport class TypoSupport {\n #kind: \"none\" | \"tty\" | \"mock\";\n private constructor(kind: \"none\" | \"tty\" | \"mock\") {\n this.#kind = kind;\n }\n static none(): TypoSupport {\n return new TypoSupport(\"none\");\n }\n static tty(): TypoSupport {\n return new TypoSupport(\"tty\");\n }\n static mock(): TypoSupport {\n return new TypoSupport(\"mock\");\n }\n static inferFromProcess(): TypoSupport {\n if (!process) {\n return TypoSupport.none();\n }\n if (process.env) {\n if (process.env[\"FORCE_COLOR\"] === \"0\") {\n return TypoSupport.none();\n }\n if (process.env[\"FORCE_COLOR\"]) {\n return TypoSupport.tty();\n }\n if (\"NO_COLOR\" in process.env) {\n return TypoSupport.none();\n }\n }\n if (!process.stdout || !process.stdout.isTTY) {\n return TypoSupport.none();\n }\n return TypoSupport.tty();\n }\n computeStyledString(value: string, typoStyle: TypoStyle): string {\n if (this.#kind === \"none\") {\n return value;\n }\n if (this.#kind === \"tty\") {\n const fgColorCode = typoStyle.fgColor\n ? ttyCodeFgColors[typoStyle.fgColor]\n : \"\";\n const bgColorCode = typoStyle.bgColor\n ? ttyCodeBgColors[typoStyle.bgColor]\n : \"\";\n const boldCode = typoStyle.bold ? ttyCodeBold : \"\";\n const dimCode = typoStyle.dim ? ttyCodeDim : \"\";\n const italicCode = typoStyle.italic ? ttyCodeItalic : \"\";\n const underlineCode = typoStyle.underline ? ttyCodeUnderline : \"\";\n const strikethroughCode = typoStyle.strikethrough\n ? ttyCodeStrikethrough\n : \"\";\n return `${fgColorCode}${bgColorCode}${boldCode}${dimCode}${italicCode}${underlineCode}${strikethroughCode}${value}${ttyCodeReset}`;\n }\n if (this.#kind === \"mock\") {\n const fgColorPart = typoStyle.fgColor\n ? `{${value}}@${typoStyle.fgColor}`\n : value;\n const bgColorPart = typoStyle.bgColor\n ? `{${fgColorPart}}#${typoStyle.bgColor}`\n : fgColorPart;\n const boldPart = typoStyle.bold ? `{${bgColorPart}}+` : bgColorPart;\n const dimPart = typoStyle.dim ? `{${boldPart}}-` : boldPart;\n const italicPart = typoStyle.italic ? `{${dimPart}}*` : dimPart;\n const underlinePart = typoStyle.underline\n ? `{${italicPart}}_`\n : italicPart;\n const strikethroughPart = typoStyle.strikethrough\n ? `{${underlinePart}}~`\n : underlinePart;\n return strikethroughPart;\n }\n throw new Error(`Unknown TypoSupport kind: ${this.#kind}`);\n }\n computeStyledErrorMessage(error: unknown): string {\n return [\n this.computeStyledString(\"Error:\", typoStyleFailure),\n error instanceof TypoError\n ? error.computeStyledString(this)\n : error instanceof Error\n ? error.message\n : String(error),\n ].join(\" \");\n }\n}\n\nconst ttyCodeReset = \"\\x1b[0m\";\nconst ttyCodeBold = \"\\x1b[1m\";\nconst ttyCodeDim = \"\\x1b[2m\";\nconst ttyCodeItalic = \"\\x1b[3m\";\nconst ttyCodeUnderline = \"\\x1b[4m\";\nconst ttyCodeStrikethrough = \"\\x1b[9m\";\nconst ttyCodeFgColors: Record<TypoColor, string> = {\n darkBlack: \"\\x1b[30m\",\n darkRed: \"\\x1b[31m\",\n darkGreen: \"\\x1b[32m\",\n darkYellow: \"\\x1b[33m\",\n darkBlue: \"\\x1b[34m\",\n darkMagenta: \"\\x1b[35m\",\n darkCyan: \"\\x1b[36m\",\n darkWhite: \"\\x1b[37m\",\n brightBlack: \"\\x1b[90m\",\n brightRed: \"\\x1b[91m\",\n brightGreen: \"\\x1b[92m\",\n brightYellow: \"\\x1b[93m\",\n brightBlue: \"\\x1b[94m\",\n brightMagenta: \"\\x1b[95m\",\n brightCyan: \"\\x1b[96m\",\n brightWhite: \"\\x1b[97m\",\n};\nconst ttyCodeBgColors: Record<TypoColor, string> = {\n darkBlack: \"\\x1b[40m\",\n darkRed: \"\\x1b[41m\",\n darkGreen: \"\\x1b[42m\",\n darkYellow: \"\\x1b[43m\",\n darkBlue: \"\\x1b[44m\",\n darkMagenta: \"\\x1b[45m\",\n darkCyan: \"\\x1b[46m\",\n darkWhite: \"\\x1b[47m\",\n brightBlack: \"\\x1b[100m\",\n brightRed: \"\\x1b[101m\",\n brightGreen: \"\\x1b[102m\",\n brightYellow: \"\\x1b[103m\",\n brightBlue: \"\\x1b[104m\",\n brightMagenta: \"\\x1b[105m\",\n brightCyan: \"\\x1b[106m\",\n brightWhite: \"\\x1b[107m\",\n};\n","import { Operation } from \"./Operation\";\nimport { OptionUsage } from \"./Option\";\nimport { PositionalUsage } from \"./Positional\";\nimport { ReaderArgs } from \"./Reader\";\nimport { TypoError, TypoString, typoStyleConstants, TypoText } from \"./Typo\";\n\nexport type Command<Context, Result> = {\n getInformation(): CommandInformation;\n createFactory(readerArgs: ReaderArgs): CommandFactory<Context, Result>;\n};\n\nexport type CommandFactory<Context, Result> = {\n generateUsage(): CommandUsage;\n createInstance(): CommandInstance<Context, Result>;\n};\n\nexport type CommandInstance<Context, Result> = {\n executeWithContext(context: Context): Promise<Result>;\n};\n\nexport type CommandInformation = {\n description: string;\n hint?: string;\n details?: string;\n // TODO - printable examples ?\n};\n\nexport type CommandUsage = {\n breadcrumbs: Array<CommandUsageBreadcrumb>;\n information: CommandInformation;\n positionals: Array<PositionalUsage>;\n subcommands: Array<CommandUsageSubcommand>;\n options: Array<OptionUsage>;\n};\n\nexport type CommandUsageBreadcrumb =\n | { positional: string }\n | { command: string };\n\nexport type CommandUsageSubcommand = {\n name: string;\n description: string | undefined;\n hint: string | undefined;\n};\n\nexport function command<Context, Result>(\n information: CommandInformation,\n operation: Operation<Context, Result>,\n): Command<Context, Result> {\n return {\n getInformation() {\n return information;\n },\n createFactory(readerArgs: ReaderArgs) {\n function generateUsage(): CommandUsage {\n const operationUsage = operation.generateUsage();\n return {\n breadcrumbs: operationUsage.positionals.map((positional) =>\n breadcrumbPositional(positional.label),\n ),\n information: information,\n positionals: operationUsage.positionals,\n subcommands: [],\n options: operationUsage.options,\n };\n }\n try {\n const operationFactory = operation.createFactory(readerArgs);\n const endPositional = readerArgs.consumePositional();\n if (endPositional !== undefined) {\n throw Error(`Unexpected argument: \"${endPositional}\"`);\n }\n return {\n generateUsage,\n createInstance() {\n const operationInstance = operationFactory.createInstance();\n return {\n async executeWithContext(context: Context) {\n return await operationInstance.executeWithContext(context);\n },\n };\n },\n };\n } catch (error) {\n return {\n generateUsage,\n createInstance() {\n throw error;\n },\n };\n }\n },\n };\n}\n\nexport function commandWithSubcommands<Context, Payload, Result>(\n information: CommandInformation,\n operation: Operation<Context, Payload>,\n subcommands: { [subcommand: Lowercase<string>]: Command<Payload, Result> },\n): Command<Context, Result> {\n return {\n getInformation() {\n return information;\n },\n createFactory(readerArgs: ReaderArgs) {\n try {\n const operationFactory = operation.createFactory(readerArgs);\n const subcommandName = readerArgs.consumePositional();\n if (subcommandName === undefined) {\n throw new TypoError(\n new TypoText(\n new TypoString(`<SUBCOMMAND>`, typoStyleConstants),\n new TypoString(`: Is required, but was not provided`),\n ),\n );\n }\n const subcommandInput =\n subcommands[subcommandName as Lowercase<string>];\n if (subcommandInput === undefined) {\n throw new TypoError(\n new TypoText(\n new TypoString(`<SUBCOMMAND>`, typoStyleConstants),\n new TypoString(`: Invalid value: \"${subcommandName}\"`),\n ),\n );\n }\n const subcommandFactory = subcommandInput.createFactory(readerArgs);\n return {\n generateUsage() {\n const operationUsage = operation.generateUsage();\n const subcommandUsage = subcommandFactory.generateUsage();\n return {\n breadcrumbs: operationUsage.positionals\n .map((positional) => breadcrumbPositional(positional.label))\n .concat([breadcrumbCommand(subcommandName)])\n .concat(subcommandUsage.breadcrumbs),\n information: subcommandUsage.information,\n positionals: operationUsage.positionals.concat(\n subcommandUsage.positionals,\n ),\n subcommands: subcommandUsage.subcommands,\n options: operationUsage.options.concat(subcommandUsage.options),\n };\n },\n createInstance() {\n const operationInstance = operationFactory.createInstance();\n const subcommandInstance = subcommandFactory.createInstance();\n return {\n async executeWithContext(context: Context) {\n return await subcommandInstance.executeWithContext(\n await operationInstance.executeWithContext(context),\n );\n },\n };\n },\n };\n } catch (error) {\n return {\n generateUsage() {\n const operationUsage = operation.generateUsage();\n return {\n breadcrumbs: operationUsage.positionals\n .map((positional) => breadcrumbPositional(positional.label))\n .concat([breadcrumbCommand(\"<SUBCOMMAND>\")]),\n information: information,\n positionals: operationUsage.positionals,\n subcommands: Object.entries(subcommands).map((subcommand) => {\n const metadata = subcommand[1].getInformation();\n return {\n name: subcommand[0],\n description: metadata.description,\n hint: metadata.hint,\n };\n }),\n options: operationUsage.options,\n };\n },\n createInstance() {\n throw error;\n },\n };\n }\n },\n };\n}\n\nexport function commandChained<Context, Payload, Result>(\n metadata: CommandInformation,\n operation: Operation<Context, Payload>,\n nextCommand: Command<Payload, Result>,\n): Command<Context, Result> {\n return {\n getInformation() {\n return metadata;\n },\n createFactory(readerArgs: ReaderArgs) {\n const operationFactory = operation.createFactory(readerArgs);\n const nextCommandFactory = nextCommand.createFactory(readerArgs);\n return {\n generateUsage() {\n const operationUsage = operation.generateUsage();\n const nextCommandUsage = nextCommandFactory.generateUsage();\n return {\n information: nextCommandUsage.information,\n breadcrumbs: operationUsage.positionals\n .map((positional) => breadcrumbPositional(positional.label))\n .concat(nextCommandUsage.breadcrumbs),\n positionals: operationUsage.positionals.concat(\n nextCommandUsage.positionals,\n ),\n subcommands: nextCommandUsage.subcommands,\n options: operationUsage.options.concat(nextCommandUsage.options),\n };\n },\n createInstance() {\n const operationInstance = operationFactory.createInstance();\n const nextCommandInstance = nextCommandFactory.createInstance();\n return {\n async executeWithContext(context: Context) {\n return await nextCommandInstance.executeWithContext(\n await operationInstance.executeWithContext(context),\n );\n },\n };\n },\n };\n },\n };\n}\n\nfunction breadcrumbPositional(value: string): CommandUsageBreadcrumb {\n return { positional: value };\n}\n\nfunction breadcrumbCommand(value: string): CommandUsageBreadcrumb {\n return { command: value };\n}\n","import { Option, OptionUsage } from \"./Option\";\nimport { Positional, PositionalUsage } from \"./Positional\";\nimport { ReaderArgs } from \"./Reader\";\n\nexport type Operation<Input, Output> = {\n generateUsage(): OperationUsage;\n createFactory(readerArgs: ReaderArgs): OperationFactory<Input, Output>;\n};\n\nexport type OperationFactory<Input, Output> = {\n createInstance(): OperationInstance<Input, Output>;\n};\n\nexport type OperationInstance<Input, Output> = {\n executeWithContext(input: Input): Promise<Output>;\n};\n\nexport type OperationUsage = {\n options: Array<OptionUsage>;\n positionals: Array<PositionalUsage>;\n};\n\nexport function operation<\n Context,\n Result,\n Options extends { [option: string]: any },\n const Positionals extends Array<any>,\n>(\n inputs: {\n options: { [K in keyof Options]: Option<Options[K]> };\n positionals: { [K in keyof Positionals]: Positional<Positionals[K]> };\n },\n handler: (\n context: Context,\n inputs: { options: Options; positionals: Positionals },\n ) => Promise<Result>,\n): Operation<Context, Result> {\n return {\n generateUsage() {\n const optionsUsage = new Array<OptionUsage>();\n for (const optionKey in inputs.options) {\n const optionInput = inputs.options[optionKey]!;\n if (optionInput) {\n optionsUsage.push(optionInput.generateUsage());\n }\n }\n const positionalsUsage = new Array<PositionalUsage>();\n for (const positionalInput of inputs.positionals) {\n positionalsUsage.push(positionalInput.generateUsage());\n }\n return { options: optionsUsage, positionals: positionalsUsage };\n },\n createFactory(readerArgs: ReaderArgs) {\n const optionsGetters: any = {};\n for (const optionKey in inputs.options) {\n const optionInput = inputs.options[optionKey]!;\n optionsGetters[optionKey] = optionInput.createGetter(readerArgs);\n }\n const positionalsValues: any = [];\n for (const positionalInput of inputs.positionals) {\n positionalsValues.push(positionalInput.consumePositionals(readerArgs));\n }\n return {\n createInstance() {\n const optionsValues: any = {};\n for (const optionKey in optionsGetters) {\n optionsValues[optionKey] = optionsGetters[optionKey]!.getValue();\n }\n return {\n executeWithContext(context: Context) {\n return handler(context, {\n options: optionsValues,\n positionals: positionalsValues,\n });\n },\n };\n },\n };\n },\n };\n}\n","import { TypoError, TypoString, typoStyleUserInput, TypoText } from \"./Typo\";\n\nexport type Type<Value> = {\n // TODO - maybe include an optional hint ??\n label: Uppercase<string>; // TODO - is there a better way to enforce uppercase labels?\n decoder(value: string): Value;\n};\n\nexport const typeBoolean: Type<boolean> = {\n label: \"BOOLEAN\",\n decoder(value: string) {\n const lowerValue = value.toLowerCase();\n if (lowerValue === \"true\" || lowerValue === \"yes\") {\n return true;\n }\n if (lowerValue === \"false\" || lowerValue === \"no\") {\n return false;\n }\n throw new Error(`Invalid value: \"${value}\"`);\n },\n};\n\nexport const typeDate: Type<Date> = {\n label: \"DATE\",\n decoder(value: string) {\n const timestamp = Date.parse(value);\n if (isNaN(timestamp)) {\n throw new Error(`Invalid ISO_8601 value: \"${value}\"`);\n }\n return new Date(timestamp);\n },\n};\n\nexport const typeUrl: Type<URL> = {\n label: \"URL\",\n decoder(value: string) {\n return new URL(value);\n },\n};\n\nexport const typeString: Type<string> = {\n label: \"STRING\",\n decoder(value: string) {\n return value;\n },\n};\n\nexport const typeNumber: Type<number> = {\n label: \"NUMBER\",\n decoder(value: string) {\n return Number(value);\n },\n};\n\nexport const typeBigInt: Type<bigint> = {\n label: \"BIGINT\",\n decoder(value: string) {\n return BigInt(value);\n },\n};\n\nexport function typeMapped<Before, After>(\n before: Type<Before>,\n after: {\n label: Uppercase<string>;\n decoder: (value: Before) => After;\n },\n): Type<After> {\n return {\n label: after.label,\n decoder: (value: string) => {\n return after.decoder(\n typeDecode(\n before,\n value,\n () => new TypoText(new TypoString(before.label, typoStyleUserInput)),\n ),\n );\n },\n };\n}\n\nexport function typeOneOf<Value>(\n type: Type<Value>,\n values: Array<Value>,\n): Type<Value> {\n const valuesSet = new Set(values);\n return {\n label: type.label,\n decoder(value: string) {\n const decoded = typeDecode(\n type,\n value,\n () => new TypoText(new TypoString(type.label, typoStyleUserInput)),\n );\n if (valuesSet.has(decoded)) {\n return decoded;\n }\n const valuesDesc = values.map((v) => `\"${v}\"`).join(\"|\");\n throw new Error(`Unexpected value: \"${value}\" (expected: ${valuesDesc})`);\n },\n };\n}\n\nexport function typeTuple<const Elements extends Array<any>>(\n elementTypes: { [K in keyof Elements]: Type<Elements[K]> },\n separator: string = \",\",\n): Type<Elements> {\n return {\n label: elementTypes\n .map((elementType) => elementType.label)\n .join(separator) as Uppercase<string>,\n decoder(value: string) {\n const parts = value.split(separator, elementTypes.length);\n if (parts.length !== elementTypes.length) {\n throw new Error(`Invalid tuple parts: ${JSON.stringify(parts)}`);\n }\n return parts.map((part, index) =>\n typeDecode(\n elementTypes[index]!,\n part,\n () =>\n new TypoText(\n new TypoString(elementTypes[index]!.label, typoStyleUserInput),\n new TypoString(`@${index}`),\n ),\n ),\n ) as Elements;\n },\n };\n}\n\nexport function typeList<Value>(\n elementType: Type<Value>,\n separator: string = \",\",\n): Type<Array<Value>> {\n return {\n label:\n `${elementType.label}[${separator}${elementType.label}]...` as Uppercase<string>,\n decoder(value: string) {\n return value\n .split(separator)\n .map((part, index) =>\n typeDecode(\n elementType,\n part,\n () =>\n new TypoText(\n new TypoString(elementType.label, typoStyleUserInput),\n new TypoString(`@${index}`),\n ),\n ),\n );\n },\n };\n}\n\nexport function typeDecode<Value>(\n type: Type<Value>,\n value: string,\n context: () => TypoText,\n): Value {\n try {\n return type.decoder(value);\n } catch (error) {\n throw new TypoError(context(), error);\n }\n}\n","import { ReaderArgs as ReaderOptions } from \"./Reader\";\nimport { Type, typeBoolean, typeDecode } from \"./Type\";\nimport {\n TypoError,\n TypoString,\n typoStyleConstants,\n typoStyleUserInput,\n TypoText,\n} from \"./Typo\";\n\nexport type Option<Value> = {\n generateUsage(): OptionUsage;\n createGetter(readerOptions: ReaderOptions): OptionGetter<Value>;\n};\n\nexport type OptionUsage = {\n description: string | undefined;\n hint: string | undefined;\n long: Lowercase<string>; // TODO - better type for long option names ?\n short: string | undefined;\n label: Uppercase<string> | undefined;\n};\n\nexport type OptionGetter<Value> = {\n getValue(): Value;\n};\n\nexport function optionFlag(definition: {\n long: Lowercase<string>;\n short?: string;\n description?: string;\n hint?: string;\n aliases?: { longs?: Array<Lowercase<string>>; shorts?: Array<string> };\n default?: () => boolean;\n}): Option<boolean> {\n const label = `<${typeBoolean.label}>` as Uppercase<string>;\n return {\n generateUsage() {\n return {\n description: definition.description,\n hint: definition.hint,\n long: definition.long,\n short: definition.short,\n label: undefined,\n };\n },\n createGetter(readerOptions: ReaderOptions) {\n const key = registerOption(readerOptions, {\n ...definition,\n valued: false,\n });\n return {\n getValue() {\n const optionValues = readerOptions.getOptionValues(key);\n if (optionValues.length > 1) {\n throw new TypoError(\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: Must not be set multiple times`),\n ),\n );\n }\n const optionValue = optionValues[0];\n if (optionValue === undefined) {\n // TODO - scoped error util\n try {\n return definition.default ? definition.default() : false;\n } catch (error) {\n throw new TypoError(\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: Failed to compute default value`),\n ),\n error,\n );\n }\n }\n return typeDecode(\n typeBoolean,\n optionValue,\n () =>\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: `),\n new TypoString(label, typoStyleUserInput),\n ),\n );\n },\n };\n },\n };\n}\n\nexport function optionSingleValue<Value>(definition: {\n long: Lowercase<string>;\n short?: string;\n description?: string;\n hint?: string;\n aliases?: { longs?: Array<Lowercase<string>>; shorts?: Array<string> };\n label?: Uppercase<string>;\n type: Type<Value>;\n default: () => Value;\n}): Option<Value> {\n const label = `<${definition.label ?? definition.type.label}>`;\n return {\n generateUsage() {\n return {\n description: definition.description,\n hint: definition.hint,\n long: definition.long,\n short: definition.short,\n label: label as Uppercase<string>,\n };\n },\n createGetter(readerOptions: ReaderOptions) {\n const key = registerOption(readerOptions, {\n ...definition,\n valued: true,\n });\n return {\n getValue() {\n const optionValues = readerOptions.getOptionValues(key);\n if (optionValues.length > 1) {\n throw new TypoError(\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: Must not be set multiple times`),\n ),\n );\n }\n const optionValue = optionValues[0];\n if (optionValue === undefined) {\n try {\n return definition.default();\n } catch (error) {\n throw new TypoError(\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: Failed to compute default value`),\n ),\n error,\n );\n }\n }\n return typeDecode(\n definition.type,\n optionValue,\n () =>\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: `),\n new TypoString(label, typoStyleUserInput),\n ),\n );\n },\n };\n },\n };\n}\n\nexport function optionRepeatable<Value>(definition: {\n long: Lowercase<string>;\n short?: string;\n description?: string;\n hint?: string;\n aliases?: { longs?: Array<Lowercase<string>>; shorts?: Array<string> };\n label?: Uppercase<string>;\n type: Type<Value>;\n}): Option<Array<Value>> {\n const label = `<${definition.label ?? definition.type.label}>`;\n return {\n generateUsage() {\n // TODO - showcase that it can be repeated ?\n return {\n description: definition.description,\n hint: definition.hint,\n long: definition.long,\n short: definition.short,\n label: label as Uppercase<string>,\n };\n },\n createGetter(readerOptions: ReaderOptions) {\n const key = registerOption(readerOptions, {\n ...definition,\n valued: true,\n });\n return {\n getValue() {\n return readerOptions\n .getOptionValues(key)\n .map((value) =>\n typeDecode(\n definition.type,\n value,\n () =>\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: `),\n new TypoString(label, typoStyleUserInput),\n ),\n ),\n );\n },\n };\n },\n };\n}\n\nfunction registerOption(\n readerOptions: ReaderOptions,\n definition: {\n long: Lowercase<string>;\n short?: string;\n aliases?: { longs?: Array<Lowercase<string>>; shorts?: Array<string> };\n valued: boolean;\n },\n) {\n const { long, short, aliases, valued } = definition;\n const longs = long ? [long] : [];\n if (aliases?.longs) {\n longs.push(...aliases?.longs);\n }\n const shorts = short ? [short] : [];\n if (aliases?.shorts) {\n shorts.push(...aliases?.shorts);\n }\n return readerOptions.registerOption({ longs, shorts, valued });\n}\n","import { ReaderPositionals } from \"./Reader\";\nimport { Type, typeDecode } from \"./Type\";\nimport { TypoError, TypoString, typoStyleUserInput, TypoText } from \"./Typo\";\n\nexport type Positional<Value> = {\n generateUsage(): PositionalUsage;\n consumePositionals(readerPositionals: ReaderPositionals): Value;\n};\n\nexport type PositionalUsage = {\n description: string | undefined;\n hint: string | undefined;\n label: Uppercase<string>;\n};\n\nexport function positionalRequired<Value>(definition: {\n description?: string;\n hint?: string;\n label?: Uppercase<string>;\n type: Type<Value>;\n}): Positional<Value> {\n const label = `<${definition.label ?? definition.type.label}>`;\n return {\n generateUsage() {\n return {\n description: definition.description,\n hint: definition.hint,\n label: label as Uppercase<string>,\n };\n },\n consumePositionals(readerPositionals: ReaderPositionals) {\n const positional = readerPositionals.consumePositional();\n if (positional === undefined) {\n throw new TypoError(\n new TypoText(\n new TypoString(label, typoStyleUserInput),\n new TypoString(`: Is required, but was not provided`),\n ),\n );\n }\n return typeDecode(\n definition.type,\n positional,\n () => new TypoText(new TypoString(label, typoStyleUserInput)),\n );\n },\n };\n}\n\nexport function positionalOptional<Value>(definition: {\n description?: string;\n hint?: string;\n label?: Uppercase<string>;\n type: Type<Value>;\n default: () => Value;\n}): Positional<Value> {\n const label = `[${definition.label ?? definition.type.label}]`;\n return {\n generateUsage() {\n return {\n description: definition.description,\n hint: definition.hint,\n label: label as Uppercase<string>,\n };\n },\n consumePositionals(readerPositionals: ReaderPositionals) {\n const positional = readerPositionals.consumePositional();\n if (positional === undefined) {\n try {\n return definition.default();\n } catch (error) {\n throw new TypoError(\n new TypoText(\n new TypoString(label, typoStyleUserInput),\n new TypoString(`: Failed to compute default value`),\n ),\n error,\n );\n }\n }\n return typeDecode(\n definition.type,\n positional,\n () => new TypoText(new TypoString(label, typoStyleUserInput)),\n );\n },\n };\n}\n\nexport function positionalVariadics<Value>(definition: {\n endDelimiter?: string;\n description?: string;\n hint?: string;\n label?: Uppercase<string>;\n type: Type<Value>;\n}): Positional<Array<Value>> {\n const label = `[${definition.label ?? definition.type.label}]`;\n return {\n generateUsage() {\n return {\n description: definition.description,\n hint: definition.hint,\n label: (`${label}...` +\n (definition.endDelimiter\n ? `[\"${definition.endDelimiter}\"]`\n : \"\")) as Uppercase<string>,\n };\n },\n consumePositionals(readerPositionals: ReaderPositionals) {\n const positionals: Array<Value> = [];\n while (true) {\n const positional = readerPositionals.consumePositional();\n if (\n positional === undefined ||\n positional === definition.endDelimiter\n ) {\n break;\n }\n positionals.push(\n typeDecode(\n definition.type,\n positional,\n () => new TypoText(new TypoString(label, typoStyleUserInput)),\n ),\n );\n }\n return positionals;\n },\n };\n}\n","import { TypoError, TypoString, typoStyleConstants, TypoText } from \"./Typo\";\n\nexport type ReaderOptionKey = (string | { __brand: \"ReaderOptionKey\" }) & {\n __brand: \"ReaderOptionKey\";\n};\n\nexport type ReaderOptions = {\n registerOption(definition: {\n longs: Array<string>;\n shorts: Array<string>;\n valued: boolean;\n }): ReaderOptionKey;\n getOptionValues(key: ReaderOptionKey): Array<string>;\n};\n\nexport type ReaderPositionals = {\n consumePositional(): string | undefined;\n};\n\nexport class ReaderArgs {\n #args: ReadonlyArray<string>;\n #parsedIndex: number;\n #parsedDouble: boolean;\n #keyByLong: Map<string, ReaderOptionKey>;\n #keyByShort: Map<string, ReaderOptionKey>;\n #valuedByKey: Map<ReaderOptionKey, boolean>;\n #resultByKey: Map<ReaderOptionKey, Array<string>>;\n\n constructor(args: ReadonlyArray<string>) {\n this.#args = args;\n this.#parsedIndex = 0;\n this.#parsedDouble = false;\n this.#keyByLong = new Map();\n this.#keyByShort = new Map();\n this.#valuedByKey = new Map();\n this.#resultByKey = new Map();\n }\n\n registerOption(definition: {\n longs: Array<string>;\n shorts: Array<string>;\n valued: boolean;\n }) {\n const key = [\n ...definition.longs.map((long) => `--${long}`),\n ...definition.shorts.map((short) => `-${short}`),\n ].join(\", \") as ReaderOptionKey;\n for (const long of definition.longs) {\n if (this.#keyByLong.has(long)) {\n throw new Error(`Option already registered: --${long}`);\n }\n this.#keyByLong.set(long, key);\n }\n for (const short of definition.shorts) {\n if (this.#keyByShort.has(short)) {\n throw new Error(`Option already registered: -${short}`);\n }\n for (let i = 0; i < short.length; i++) {\n const shortSlice = short.slice(0, i);\n if (this.#keyByShort.has(shortSlice)) {\n throw new Error(\n `Option -${short} overlap with shorter option: -${shortSlice}`,\n );\n }\n }\n for (const shortOther of this.#keyByShort.keys()) {\n if (shortOther.startsWith(short)) {\n throw new Error(\n `Option -${short} overlap with longer option: -${shortOther}`,\n );\n }\n }\n this.#keyByShort.set(short, key);\n }\n this.#valuedByKey.set(key, definition.valued);\n this.#resultByKey.set(key, new Array<string>());\n return key;\n }\n\n getOptionValues(key: ReaderOptionKey): Array<string> {\n const optionResult = this.#resultByKey.get(key);\n if (optionResult === undefined) {\n throw new Error(`Unregistered option: ${key}`);\n }\n return optionResult;\n }\n\n consumePositional(): string | undefined {\n while (true) {\n const arg = this.#consumeArg();\n if (arg === null) {\n return undefined;\n }\n if (this.#processedAsPositional(arg)) {\n return arg;\n }\n }\n }\n\n #consumeArg(): string | null {\n const arg = this.#args[this.#parsedIndex];\n if (arg === undefined) {\n return null;\n }\n this.#parsedIndex++;\n if (!this.#parsedDouble) {\n if (arg === \"--\") {\n this.#parsedDouble = true;\n return this.#consumeArg();\n }\n }\n return arg;\n }\n\n #processedAsPositional(arg: string): boolean {\n if (this.#parsedDouble) {\n return true;\n }\n if (arg.startsWith(\"--\")) {\n const valueIndexStart = arg.indexOf(\"=\");\n if (valueIndexStart === -1) {\n this.#consumeOptionLong(arg.slice(2), null);\n } else {\n this.#consumeOptionLong(\n arg.slice(2, valueIndexStart),\n arg.slice(valueIndexStart + 1),\n );\n }\n return false;\n }\n if (arg.startsWith(\"-\")) {\n let shortIndexStart = 1;\n let shortIndexEnd = 2;\n while (shortIndexEnd <= arg.length) {\n const result = this.#tryConsumeOptionShort(\n arg.slice(shortIndexStart, shortIndexEnd),\n arg.slice(shortIndexEnd),\n );\n if (result === true) {\n return false;\n }\n if (result === false) {\n shortIndexStart = shortIndexEnd;\n }\n shortIndexEnd++;\n }\n throw new TypoError(\n new TypoText(\n new TypoString(`-${arg.slice(shortIndexStart)}`, typoStyleConstants),\n new TypoString(`: Unexpected unknown option`),\n ),\n );\n }\n return true;\n }\n\n #consumeOptionLong(long: string, direct: string | null): void {\n const constant = `--${long}`;\n const key = this.#keyByLong.get(long);\n if (key !== undefined) {\n if (direct !== null) {\n return this.#acknowledgeOption(key, direct);\n }\n const valued = this.#valuedByKey.get(key);\n if (valued) {\n return this.#acknowledgeOption(key, this.#consumeOptionValue(constant));\n }\n return this.#acknowledgeOption(key, \"true\");\n }\n throw new TypoError(\n new TypoText(\n new TypoString(constant, typoStyleConstants),\n new TypoString(`: Unexpected unknown option`),\n ),\n );\n }\n\n #tryConsumeOptionShort(short: string, rest: string): boolean | null {\n const key = this.#keyByShort.get(short);\n if (key !== undefined) {\n if (rest.startsWith(\"=\")) {\n this.#acknowledgeOption(key, rest.slice(1));\n return true;\n }\n const valued = this.#valuedByKey.get(key);\n if (valued) {\n if (rest === \"\") {\n this.#acknowledgeOption(key, this.#consumeOptionValue(`-${short}`));\n } else {\n this.#acknowledgeOption(key, rest);\n }\n return true;\n }\n this.#acknowledgeOption(key, \"true\");\n return rest === \"\";\n }\n return null;\n }\n\n #consumeOptionValue(constant: string) {\n const arg = this.#consumeArg();\n if (arg === null) {\n throw new TypoError(\n new TypoText(\n new TypoString(constant, typoStyleConstants),\n new TypoString(`: requires a value, but got end of input`),\n ),\n );\n }\n if (this.#parsedDouble) {\n throw new TypoError(\n new TypoText(\n new TypoString(constant, typoStyleConstants),\n new TypoString(`: requires a value before \"--\"`),\n ),\n );\n }\n // TODO - is that weird, could a valid value start with dash ?\n if (arg.startsWith(\"-\")) {\n throw new TypoError(\n new TypoText(\n new TypoString(constant, typoStyleConstants),\n new TypoString(`: requires a value, but got: \"${arg}\"`),\n ),\n );\n }\n return arg;\n }\n\n #acknowledgeOption(key: ReaderOptionKey, value: string) {\n this.getOptionValues(key).push(value);\n }\n}\n","import { CommandUsage } from \"./Command\";\nimport {\n TypoGrid,\n TypoString,\n typoStyleConstants,\n typoStyleUserInput,\n TypoSupport,\n TypoText,\n} from \"./Typo\";\n\nexport function usageToStyledLines(params: {\n cliName: Lowercase<string>;\n commandUsage: CommandUsage;\n typoSupport: TypoSupport;\n}) {\n const { cliName, commandUsage, typoSupport } = params;\n\n const lines = new Array<string>();\n\n const breadcrumbs = [\n textUsageTitle(\"Usage:\").computeStyledString(typoSupport),\n textConstants(cliName).computeStyledString(typoSupport),\n ].concat(\n commandUsage.breadcrumbs.map((breadcrumb) => {\n if (\"positional\" in breadcrumb) {\n return textUserInput(breadcrumb.positional).computeStyledString(\n typoSupport,\n );\n }\n if (\"command\" in breadcrumb) {\n return textConstants(breadcrumb.command).computeStyledString(\n typoSupport,\n );\n }\n throw new Error(`Unknown breadcrumb: ${JSON.stringify(breadcrumb)}`);\n }),\n );\n lines.push(breadcrumbs.join(\" \"));\n\n lines.push(\"\");\n const infoText = new TypoText();\n infoText.pushString(textUsageIntro(commandUsage.information.description));\n if (commandUsage.information.hint) {\n infoText.pushString(textDelimiter(\" \"));\n infoText.pushString(textSubtleInfo(`(${commandUsage.information.hint})`));\n }\n lines.push(infoText.computeStyledString(typoSupport));\n if (commandUsage.information.details) {\n const detailsString = textSubtleInfo(commandUsage.information.details);\n lines.push(detailsString.computeStyledString(typoSupport));\n }\n\n if (commandUsage.positionals.length > 0) {\n lines.push(\"\");\n lines.push(textBlockTitle(\"Positionals:\").computeStyledString(typoSupport));\n const typoGrid = new TypoGrid();\n for (const positionalUsage of commandUsage.positionals) {\n const typoGridRow = new Array<TypoText>();\n typoGridRow.push(new TypoText(textDelimiter(\" \")));\n typoGridRow.push(new TypoText(textUserInput(positionalUsage.label)));\n typoGridRow.push(...createInformationals(positionalUsage));\n typoGrid.pushRow(typoGridRow);\n }\n lines.push(\n ...typoGrid.computeStyledGrid(typoSupport).map((row) => row.join(\"\")),\n );\n }\n\n if (commandUsage.subcommands.length > 0) {\n lines.push(\"\");\n lines.push(textBlockTitle(\"Subcommands:\").computeStyledString(typoSupport));\n const typoGrid = new TypoGrid();\n for (const subcommandUsage of commandUsage.subcommands) {\n const typoGridRow = new Array<TypoText>();\n typoGridRow.push(new TypoText(textDelimiter(\" \")));\n typoGridRow.push(new TypoText(textConstants(subcommandUsage.name)));\n typoGridRow.push(...createInformationals(subcommandUsage));\n typoGrid.pushRow(typoGridRow);\n }\n lines.push(\n ...typoGrid.computeStyledGrid(typoSupport).map((row) => row.join(\"\")),\n );\n }\n\n if (commandUsage.options.length > 0) {\n lines.push(\"\");\n lines.push(textBlockTitle(\"Options:\").computeStyledString(typoSupport));\n const typoGrid = new TypoGrid();\n for (const optionUsage of commandUsage.options) {\n const typoGridRow = new Array<TypoText>();\n typoGridRow.push(new TypoText(textDelimiter(\" \")));\n if (optionUsage.short) {\n typoGridRow.push(\n new TypoText(\n textConstants(`-${optionUsage.short}`),\n textDelimiter(\", \"),\n ),\n );\n } else {\n typoGridRow.push(new TypoText());\n }\n if (optionUsage.label) {\n typoGridRow.push(\n new TypoText(\n textConstants(`--${optionUsage.long}`),\n textDelimiter(\" \"),\n textUserInput(optionUsage.label),\n ),\n );\n } else {\n typoGridRow.push(\n new TypoText(\n textConstants(`--${optionUsage.long}`),\n textSubtleInfo(\"[=no]\"),\n ),\n );\n }\n typoGridRow.push(...createInformationals(optionUsage));\n typoGrid.pushRow(typoGridRow);\n }\n lines.push(\n ...typoGrid.computeStyledGrid(typoSupport).map((row) => row.join(\"\")),\n );\n }\n\n lines.push(\"\");\n return lines;\n}\n\nfunction createInformationals(usage: {\n description: string | undefined;\n hint: string | undefined;\n}): Array<TypoText> {\n const informationals = [];\n if (usage.description) {\n informationals.push(textDelimiter(\" \"));\n informationals.push(textUsefulInfo(usage.description));\n }\n if (usage.hint) {\n informationals.push(textDelimiter(\" \"));\n informationals.push(textSubtleInfo(`(${usage.hint})`));\n }\n if (informationals.length > 0) {\n return [new TypoText(textDelimiter(\" \"), ...informationals)];\n }\n return [];\n}\n\nfunction textUsageIntro(value: string): TypoString {\n return new TypoString(value, { bold: true });\n}\n\nfunction textUsageTitle(value: string): TypoString {\n return new TypoString(value, { fgColor: \"darkMagenta\", bold: true });\n}\n\nfunction textUsefulInfo(value: string): TypoString {\n return new TypoString(value);\n}\n\nfunction textSubtleInfo(value: string): TypoString {\n return new TypoString(value, { italic: true, dim: true });\n}\n\nfunction textBlockTitle(value: string): TypoString {\n return new TypoString(value, { fgColor: \"darkGreen\", bold: true });\n}\n\nfunction textConstants(value: string): TypoString {\n return new TypoString(value, typoStyleConstants);\n}\n\nfunction textUserInput(value: string): TypoString {\n return new TypoString(value, typoStyleUserInput);\n}\n\nfunction textDelimiter(value: string): TypoString {\n return new TypoString(value);\n}\n","import { Command, CommandFactory } from \"./Command\";\nimport { ReaderArgs } from \"./Reader\";\nimport { TypoSupport } from \"./Typo\";\nimport { usageToStyledLines } from \"./Usage\";\n\nexport async function runAsCliAndExit<Context>(\n cliName: Lowercase<string>,\n cliArgs: ReadonlyArray<string>,\n context: Context,\n command: Command<Context, void>,\n application?: {\n usageOnHelp?: boolean | undefined;\n buildVersion?: string | undefined;\n useColors?: boolean | undefined;\n onExecutionError?: ((error: unknown) => void) | undefined;\n onLogStdOut?: ((message: string) => void) | undefined; // TODO - this is a problem, deep commands use console\n onLogStdErr?: ((message: string) => void) | undefined;\n onExit?: ((code: number) => never) | undefined;\n },\n): Promise<never> {\n const readerArgs = new ReaderArgs(cliArgs);\n const usageOnHelp = application?.usageOnHelp ?? true;\n if (usageOnHelp) {\n readerArgs.registerOption({\n shorts: [],\n longs: [\"help\"],\n valued: false,\n });\n }\n const buildVersion = application?.buildVersion;\n if (buildVersion) {\n readerArgs.registerOption({\n shorts: [],\n longs: [\"version\"],\n valued: false,\n });\n }\n /*\n // TODO - handle completions ?\n readerArgs.registerFlag({\n key: \"completion\",\n shorts: [],\n longs: [\"completion\"],\n });\n */\n const commandFactory = command.createFactory(readerArgs);\n while (true) {\n const positional = readerArgs.consumePositional();\n if (positional === undefined) {\n break;\n }\n }\n const typoSupport = chooseTypoSupport(application?.useColors);\n const onLogStdOut = application?.onLogStdOut ?? console.log;\n const onLogStdErr = application?.onLogStdErr ?? console.error;\n const onExit = application?.onExit ?? process.exit;\n if (usageOnHelp) {\n if (readerArgs.getOptionValues(\"--help\" as any).length > 0) {\n onLogStdOut(computeUsageString(cliName, commandFactory, typoSupport));\n return onExit(0);\n }\n }\n if (buildVersion) {\n if (readerArgs.getOptionValues(\"--version\" as any).length > 0) {\n onLogStdOut([cliName, buildVersion].join(\" \"));\n return onExit(0);\n }\n }\n try {\n const commandInstance = commandFactory.createInstance();\n try {\n await commandInstance.executeWithContext(context);\n return onExit(0);\n } catch (error) {\n if (application?.onExecutionError) {\n application.onExecutionError(error);\n } else {\n onLogStdErr(typoSupport.computeStyledErrorMessage(error));\n }\n return onExit(1);\n }\n } catch (error) {\n onLogStdErr(computeUsageString(cliName, commandFactory, typoSupport));\n onLogStdErr(typoSupport.computeStyledErrorMessage(error));\n return onExit(1);\n }\n}\n\nfunction computeUsageString<Context, Result>(\n cliName: Lowercase<string>,\n commandFactory: CommandFactory<Context, Result>,\n typoSupport: TypoSupport,\n) {\n return usageToStyledLines({\n cliName,\n commandUsage: commandFactory.generateUsage(),\n typoSupport,\n }).join(\"\\n\");\n}\n\nfunction chooseTypoSupport(useColors?: boolean): TypoSupport {\n if (useColors === undefined) {\n return TypoSupport.inferFromProcess();\n }\n return useColors ? TypoSupport.tty() : TypoSupport.none();\n}\n"],"mappings":"m3BAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,gBAAAE,EAAA,cAAAC,EAAA,aAAAC,EAAA,eAAAC,EAAA,gBAAAC,EAAA,aAAAC,EAAA,YAAAC,GAAA,mBAAAC,GAAA,2BAAAC,GAAA,cAAAC,GAAA,eAAAC,GAAA,qBAAAC,GAAA,sBAAAC,GAAA,uBAAAC,GAAA,uBAAAC,GAAA,wBAAAC,GAAA,oBAAAC,GAAA,eAAAC,GAAA,gBAAAC,EAAA,aAAAC,GAAA,eAAAC,EAAA,aAAAC,GAAA,eAAAC,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,EAEnDH,EAAO,CAAC,CACjB,CACF,OAASG,EAAO,CACd,OAAAJ,EAAYE,GAAmBf,EAASS,EAAgBC,CAAW,CAAC,EACpEG,EAAYH,EAAY,0BAA0BO,CAAK,CAAC,EACjDH,EAAO,CAAC,CACjB,CACF,CAEA,SAASC,GACPf,EACAS,EACAC,EACA,CACA,OAAOQ,GAAmB,CACxB,QAAAlB,EACA,aAAcS,EAAe,cAAc,EAC3C,YAAAC,CACF,CAAC,EAAE,KAAK;AAAA,CAAI,CACd,CAEA,SAASC,GAAkBQ,EAAkC,CAC3D,OAAIA,IAAc,OACTC,EAAY,iBAAiB,EAE/BD,EAAYC,EAAY,IAAI,EAAIA,EAAY,KAAK,CAC1D","names":["index_exports","__export","ReaderArgs","TypoError","TypoGrid","TypoString","TypoSupport","TypoText","command","commandChained","commandWithSubcommands","operation","optionFlag","optionRepeatable","optionSingleValue","positionalOptional","positionalRequired","positionalVariadics","runAsCliAndExit","typeBigInt","typeBoolean","typeDate","typeDecode","typeList","typeMapped","typeNumber","typeOneOf","typeString","typeTuple","typeUrl","typoStyleConstants","typoStyleFailure","typoStyleUserInput","usageToStyledLines","__toCommonJS","typoStyleConstants","typoStyleUserInput","typoStyleFailure","_value","_typoStyle","TypoString","value","typoStyle","__privateAdd","__privateSet","__privateGet","typoSupport","_typoStrings","_TypoText","typoParts","typoPart","typoString","typoText","t","length","TypoText","_typoRows","TypoGrid","cells","widths","printableGrid","typoGridRow","typoGridColumnIndex","width","printableGridRow","typoGridCell","printableGridCell","padding","_typoText","_TypoError","currentTypoText","source","TypoError","_kind","_TypoSupport","kind","fgColorCode","ttyCodeFgColors","bgColorCode","ttyCodeBgColors","boldCode","ttyCodeBold","dimCode","ttyCodeDim","italicCode","ttyCodeItalic","underlineCode","ttyCodeUnderline","strikethroughCode","ttyCodeStrikethrough","ttyCodeReset","fgColorPart","bgColorPart","boldPart","dimPart","italicPart","underlinePart","error","TypoSupport","command","information","operation","readerArgs","generateUsage","operationUsage","positional","breadcrumbPositional","operationFactory","endPositional","operationInstance","context","error","commandWithSubcommands","subcommands","subcommandName","TypoError","TypoText","TypoString","typoStyleConstants","subcommandInput","subcommandFactory","subcommandUsage","breadcrumbCommand","subcommandInstance","subcommand","metadata","commandChained","nextCommand","nextCommandFactory","nextCommandUsage","nextCommandInstance","value","operation","inputs","handler","optionsUsage","optionKey","optionInput","positionalsUsage","positionalInput","readerArgs","optionsGetters","positionalsValues","optionsValues","context","typeBoolean","value","lowerValue","typeDate","timestamp","typeUrl","typeString","typeNumber","typeBigInt","typeMapped","before","after","typeDecode","TypoText","TypoString","typoStyleUserInput","typeOneOf","type","values","valuesSet","decoded","valuesDesc","v","typeTuple","elementTypes","separator","elementType","parts","part","index","typeList","context","error","TypoError","optionFlag","definition","label","typeBoolean","readerOptions","key","registerOption","optionValues","TypoError","TypoText","TypoString","typoStyleConstants","optionValue","error","typeDecode","typoStyleUserInput","optionSingleValue","optionRepeatable","value","long","short","aliases","valued","longs","shorts","positionalRequired","definition","label","readerPositionals","positional","TypoError","TypoText","TypoString","typoStyleUserInput","typeDecode","positionalOptional","error","positionalVariadics","positionals","_args","_parsedIndex","_parsedDouble","_keyByLong","_keyByShort","_valuedByKey","_resultByKey","_ReaderArgs_instances","consumeArg_fn","processedAsPositional_fn","consumeOptionLong_fn","tryConsumeOptionShort_fn","consumeOptionValue_fn","acknowledgeOption_fn","ReaderArgs","args","__privateAdd","__privateSet","definition","key","long","short","__privateGet","i","shortSlice","shortOther","optionResult","arg","__privateMethod","__privateWrapper","valueIndexStart","shortIndexStart","shortIndexEnd","result","TypoError","TypoText","TypoString","typoStyleConstants","direct","constant","rest","value","usageToStyledLines","params","cliName","commandUsage","typoSupport","lines","breadcrumbs","textUsageTitle","textConstants","breadcrumb","textUserInput","infoText","TypoText","textUsageIntro","textDelimiter","textSubtleInfo","detailsString","textBlockTitle","typoGrid","TypoGrid","positionalUsage","typoGridRow","createInformationals","row","subcommandUsage","optionUsage","usage","informationals","textUsefulInfo","value","TypoString","typoStyleConstants","typoStyleUserInput","runAsCliAndExit","cliName","cliArgs","context","command","application","readerArgs","ReaderArgs","usageOnHelp","buildVersion","commandFactory","typoSupport","chooseTypoSupport","onLogStdOut","onLogStdErr","onExit","computeUsageString","commandInstance","error","usageToStyledLines","useColors","TypoSupport"]}
|