convoker 0.3.4 → 0.4.1
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/LICENSE +1 -1
- package/dist/color/index.d.mts +2 -0
- package/dist/color/index.mjs +3 -0
- package/dist/{color-OlJQTTxb.mjs → color-s-N9yh90.mjs} +7 -41
- package/dist/color-s-N9yh90.mjs.map +1 -0
- package/dist/command/index.d.mts +5 -0
- package/dist/command/index.mjs +9 -0
- package/dist/{command-D2UiQBNA.mjs → command-C9QIG--8.mjs} +187 -148
- package/dist/command-C9QIG--8.mjs.map +1 -0
- package/dist/{index-Dikc5KAP.d.mts → index-C0cH9MIP.d.mts} +4 -3
- package/dist/{input-B12iaqb8.d.mts → index-C6iJZTo3.d.mts} +20 -5
- package/dist/index-CCQ6jz54.d.mts +58 -0
- package/dist/{command-BXmfoT-l.d.mts → index-OUlP1L9o.d.mts} +10 -25
- package/dist/index.d.mts +62 -43
- package/dist/index.mjs +8 -9
- package/dist/input/index.d.mts +3 -0
- package/dist/input/index.mjs +4 -0
- package/dist/{input-DRy_sVxZ.mjs → input-li13L1uf.mjs} +5 -3
- package/dist/input-li13L1uf.mjs.map +1 -0
- package/dist/prompt/index.d.mts +3 -3
- package/dist/prompt/index.mjs +5 -6
- package/dist/prompt/raw.mjs +1 -2
- package/dist/{prompt-Cvufljin.mjs → prompt-OXGrAkDf.mjs} +30 -58
- package/dist/prompt-OXGrAkDf.mjs.map +1 -0
- package/dist/raw-BqvlveTU.d.mts +2 -1
- package/dist/{raw--889icsd.mjs → raw-DVT5lw11.mjs} +4 -21
- package/dist/raw-DVT5lw11.mjs.map +1 -0
- package/dist/{standard-schema-DLeKaehR.d.mts → standard-schema-D1sStgzy.d.mts} +3 -2
- package/dist/standard-schema-WhGEzW0C.mjs +32 -0
- package/dist/standard-schema-WhGEzW0C.mjs.map +1 -0
- package/dist/{utils-ChmY93uA.mjs → theme-Chg3mOhZ.mjs} +36 -13
- package/dist/theme-Chg3mOhZ.mjs.map +1 -0
- package/dist/theme-EERPMtQU.d.mts +115 -0
- package/dist/theme.d.mts +2 -0
- package/dist/theme.mjs +4 -0
- package/package.json +18 -17
- package/dist/color-BuHvMolk.d.mts +0 -158
- package/dist/color.d.mts +0 -2
- package/dist/color.mjs +0 -4
- package/dist/command.d.mts +0 -5
- package/dist/command.mjs +0 -10
- package/dist/error-C1S1gs8L.mjs +0 -115
- package/dist/error.d.mts +0 -5
- package/dist/error.mjs +0 -3
- package/dist/input.d.mts +0 -3
- package/dist/input.mjs +0 -5
- package/dist/standard-schema-DBXbMy6L.mjs +0 -17
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-C9QIG--8.mjs","names":["th: Theme","setTheme","DEFAULT_CONFIG: Config","config: Config","command","command: Command<any>","input: Record<string, unknown>","args: string[]","opts: Record<string, string>","errors: ConvokerError[]","usedValue: string | undefined","rawValue: string | string[] | undefined","names: string[]","cmd: Command<any> | undefined","nonCliErrors: Error[]","error","middlewares: MiddlewareFn<any>[]","current: Command<any> | undefined"],"sources":["../src/log/error.ts","../src/log/index.ts","../src/command/error.ts","../src/command/index.ts"],"sourcesContent":["/**\n * Error for when logs fail to write to stdout/stderr.\n */\nexport class WriteError extends Error {\n /**\n * Creates a new error for stream writes.\n * @param streamName The name of the stream.\n */\n constructor(streamName: string) {\n super(`Could not write to \\`${streamName}\\`.`);\n }\n}\n","import Stream from \"node:stream\";\nimport process from \"node:process\";\nimport { DEFAULT_THEME, type Theme } from \"@/theme\";\nimport { DeepPartial, merge } from \"@/utils\";\nimport { WriteError } from \"./error\";\n\nlet th: Theme = DEFAULT_THEME;\n\n/**\n * Sets the theme for logs.\n * @param theme The theme to set.\n */\nexport function setTheme(theme: Theme) {\n th = theme;\n}\n\n/**\n * Log configuration.\n */\nexport interface Config {\n /**\n * The configuration format.\n */\n format: \"text\" | \"json\";\n /**\n * Standard output.\n */\n stdout: Stream.Writable;\n /**\n * Standard error output.\n */\n stderr: Stream.Writable;\n /**\n * How much space in the JSON output of objects.\n * This does not change spacing in JSON logs, only for objects passed into log functions.\n */\n jsonSpace: number;\n}\n\n/**\n * Default log configuration.\n */\nexport const DEFAULT_CONFIG: Config = {\n format: \"text\",\n stderr: process.stderr,\n stdout: process.stdout,\n jsonSpace: 2,\n};\n\nlet config: Config = DEFAULT_CONFIG;\n\n/**\n * Sets log configuration.\n * @param cfg The configuration, optionally including a theme.\n */\nexport function setConfig({\n theme,\n ...cfg\n}: DeepPartial<Config> & { theme?: Theme }) {\n config = merge(DEFAULT_CONFIG, cfg);\n th = theme ?? th;\n}\n\n/**\n * Prints messages.\n * @param msgs The messages to print.\n */\nexport function trace(...msgs: any[]) {\n const str = format(msgs, \"TRACE\");\n if (!config.stdout.write(str)) {\n throw new WriteError(\"stdout\");\n }\n}\n\n/**\n * Prints messages.\n * @param msgs The messages to print.\n */\nexport function info(...msgs: any[]) {\n const str = format(msgs, \"INFO\");\n if (!config.stdout.write(str)) {\n throw new WriteError(\"stdout\");\n }\n}\n\n/**\n * Prints warning messages.\n * @param msgs The messages to print.\n */\nexport function warn(...msgs: any[]) {\n const str = format(msgs, \"WARN\");\n if (!config.stderr.write(th.warning(str))) {\n throw new WriteError(\"stderr\");\n }\n}\n\n/**\n * Prints error messages.\n * @param msgs The messages to print.\n */\nexport function error(...msgs: any[]) {\n const str = format(msgs, \"ERROR\");\n if (!config.stderr.write(str)) {\n throw new WriteError(\"stderr\");\n }\n}\n\n/**\n * Prints messages and exits with code -1.\n * @param msgs The messages to print.\n */\nexport function fatal(...msgs: any[]) {\n const str = format(msgs, \"FATAL\");\n if (!config.stderr.write(str)) {\n throw new WriteError(\"stderr\");\n }\n\n process.exit(-1);\n}\n\nexport * from \"./error\";\n\n/**\n * Formats a list of messages into a single string.\n * @param msgs The messages to format.\n * @param level The log level.\n * @returns A formatted message.\n */\nfunction format(msgs: any[], level: string): string {\n const timestamp = new Date().toISOString();\n const msg = msgs\n .map((m) =>\n typeof m === \"string\" ? m : JSON.stringify(m, null, config.jsonSpace),\n )\n .join(\" \");\n switch (config.format) {\n case \"json\":\n return colorize(\n JSON.stringify({ timestamp, level, message: msg }) + \"\\n\",\n level,\n );\n case \"text\":\n default:\n return colorize(\n `[${timestamp}] [${(th.symbols as any)[level] ?? level}] ${msg}\\n`,\n level,\n );\n }\n}\n\n/**\n * Wraps a string in ANSI codes, based on a log level.\n * @param str The string to color.\n * @param level The log level.\n * @returns An ANSI-wrapped string.\n */\nfunction colorize(str: string, level: string) {\n switch (level) {\n case \"TRACE\":\n return th.secondary(str);\n case \"WARN\":\n return th.warning(str);\n case \"ERROR\":\n return th.error(str);\n case \"FATAL\":\n return th.styles?.bold ? th.styles.bold(th.error(str)) : th.error(str);\n case \"INFO\":\n default:\n return th.info?.(str) ?? str;\n }\n}\n","import { Positional, Option } from \"@/input\";\nimport { Command } from \".\";\n\n/**\n * A Convoker-related error. These are usually handled by default.\n */\nexport class ConvokerError extends Error {\n /**\n * The command this error happened on.\n */\n command: Command<any>;\n\n /**\n * Creates a new Convoker error.\n * @param message The message.\n * @param command The command.\n */\n constructor(message: string, command: Command<any>) {\n super(message);\n this.command = command;\n }\n\n /**\n * Prints the error's message.\n */\n print() {\n console.error(this.message);\n }\n}\n\n/**\n * When the user asks for help.\n */\nexport class HelpAskedError extends ConvokerError {\n /**\n * Creates a new help asked error.\n * @param command The command.\n */\n constructor(command: Command<any>) {\n super(\"user asked for help!\", command);\n }\n}\n\n/**\n * When you pass too many arguments.\n */\nexport class TooManyArgumentsError extends ConvokerError {\n /**\n * Creates a new too many arguments error.\n * @param command The command.\n */\n constructor(command: Command<any>) {\n super(\"too many arguments!\", command);\n }\n}\n\n/**\n * When you pass an unknown option, when unknown options aren't allowed.\n */\nexport class UnknownOptionError extends ConvokerError {\n /**\n * The option key.\n */\n key: string;\n\n /**\n * Creates a new unknown option error.\n * @param command The command.\n * @param key The key.\n */\n constructor(command: Command<any>, key: string) {\n super(`unknown option: ${key}!`, command);\n this.key = key;\n }\n}\n\n/**\n * When a required option is missing.\n */\nexport class MissingRequiredOptionError extends ConvokerError {\n /**\n * The option key.\n */\n key: string;\n /**\n * The option entry.\n */\n entry: Option<any, any, any>;\n\n /**\n * Creates a new missing required option error.\n * @param command The command.\n * @param key The key.\n * @param entry The entry.\n */\n constructor(\n command: Command<any>,\n key: string,\n entry: Option<any, any, any>,\n ) {\n super(`missing required option: ${key}!`, command);\n this.key = key;\n this.entry = entry;\n }\n}\n\nexport class MissingRequiredArgumentError extends ConvokerError {\n /**\n * The argument key.\n */\n key: string;\n /**\n * The argument entry.\n */\n entry: Positional<any, any, any>;\n\n /**\n * Creates a new missing required argument error.\n * @param command The command.\n * @param key The key.\n * @param entry The entry.\n */\n constructor(\n command: Command<any>,\n key: string,\n entry: Positional<any, any, any>,\n ) {\n super(`missing required positional argument: ${key}!`, command);\n this.key = key;\n this.entry = entry;\n }\n}\n","import process from \"node:process\";\n\nimport { gray, cyan, bold } from \"@/color\";\nimport type { Theme } from \"@/theme\";\nimport { setTheme as setPromptTheme } from \"@/prompt\";\nimport { setTheme as setLogTheme } from \"@/log\";\nimport {\n ConvokerError,\n HelpAskedError,\n MissingRequiredArgumentError,\n MissingRequiredOptionError,\n TooManyArgumentsError,\n UnknownOptionError,\n} from \"./error\";\nimport {\n convert,\n Option,\n Positional,\n type InferInput,\n type Input,\n} from \"@/input\";\n\n/**\n * What the command is an alias for.\n */\nexport interface CommandAlias<T extends Input = Input> {\n /**\n * A pointer to the command.\n */\n command: Command<T>;\n /**\n * The name of the command this is an alias for.\n */\n alias?: string;\n}\n\n/**\n * The result of the `Command.parse` function.\n */\nexport interface ParseResult<T extends Input> {\n /**\n * A pointer to the command to run.\n */\n command: Command<T>;\n /**\n * The input to pass into the command.\n */\n input: InferInput<T>;\n /**\n * Errors collected during parsing.\n */\n errors: ConvokerError[];\n /**\n * If this should result in displaying the version of the command.\n */\n isVersion: boolean;\n /**\n * If this should result in displaying a help screen.\n */\n isHelp: boolean;\n}\n\n/**\n * Command action function.\n */\nexport type ActionFn<T extends Input> = (\n input: InferInput<T>,\n) => any | Promise<any>;\n\n/**\n * Command middleware function.\n */\nexport type MiddlewareFn<T extends Input = Input> = (\n input: InferInput<T>,\n next: () => Promise<any>,\n) => any | Promise<any>;\n\n/**\n * Command error handler.\n */\nexport type ErrorFn<T extends Input> = (\n command: Command<T>,\n errors: Error[],\n input: Partial<InferInput<T>>,\n) => void | Promise<void>;\n\n/**\n * Builder for commands.\n */\nexport type Builder = (c: Command<any>) => Command<any> | void;\n\n/**\n * An input map entry.\n */\ninterface MapEntry {\n /**\n * The key of the map entry.\n */\n key: string;\n /**\n * The value of the map entry.\n */\n value: Option<any, any, any> | Positional<any, any, any>;\n}\n\n/**\n * A command.\n */\nexport class Command<T extends Input = Input> {\n /**\n * The names (aliases) of this command.\n */\n $names: string[];\n /**\n * The description of this command.\n */\n $description: string | undefined;\n /**\n * The theme of this command\n */\n $theme: Theme | undefined;\n /**\n * The version of this command.\n */\n $version: string | undefined;\n /**\n * The children of this command.\n */\n $children: Map<string, CommandAlias> = new Map();\n /**\n * The parent of this command.\n */\n $parent: Command<any> | undefined;\n /**\n * If this command allows unknown options.\n */\n $allowUnknownOptions: boolean = false;\n /**\n * If you should be able to surpass the amount of positional arguments defined in the input.\n */\n $allowSurpassArgLimit: boolean = false;\n /**\n * The input this command takes.\n */\n $input: T = {} as T;\n /**\n * The action function of this command.\n */\n $fn: ActionFn<T> | undefined = undefined;\n /**\n * The middlewares associated with this command.\n */\n $middlewares: MiddlewareFn<T>[] = [];\n /**\n * The error handler of this command.\n */\n $errorFn: ErrorFn<T> | undefined = undefined;\n\n /**\n * Creates a new command.\n * @param names The names (aliases).\n * @param desc The description.\n * @param version The version.\n */\n constructor(names: string | string[], desc?: string, version?: string) {\n this.$names = Array.isArray(names) ? names : [names];\n this.$description = desc;\n this.$version = version;\n }\n\n /**\n * Adds a set of aliases to this command.\n * @param aliases The aliases to add.\n * @returns this\n */\n alias(...aliases: string[]): this {\n this.$names.push(...aliases);\n this.$parent?.add(this);\n return this;\n }\n\n /**\n * Adds a description to this command.\n * @param desc The description.\n * @returns this\n */\n description(desc: string): this {\n this.$description = desc;\n return this;\n }\n\n /**\n * Adds a version to this command.\n * @param version The version.\n * @returns this\n */\n version(version: string): this {\n this.$version = version;\n return this;\n }\n\n /**\n * Sets the input for this command.\n * @param version The input.\n * @returns this\n */\n input<TInput extends Input>(input: TInput): Command<TInput> {\n this.$input = input as any;\n return this as any;\n }\n\n /**\n * Adds a chain of middlewares.\n * @param fns The middlewares to use.\n * @returns this\n */\n use(...fns: MiddlewareFn<T>[]): this {\n this.$middlewares.push(...fns);\n return this;\n }\n\n /**\n * Sets the action function for this command.\n * @param fn The action.\n * @returns this\n */\n action(fn: ActionFn<T>): this {\n this.$fn = fn;\n return this;\n }\n\n /**\n * Sets the error function for this command.\n * @param fn The error handler.\n * @returns this\n */\n error(fn: ErrorFn<T>): this {\n this.$errorFn = fn;\n return this;\n }\n\n /**\n * Adds existing commands to this.\n * @param commands The commands.\n * @returns this\n */\n add(...commands: Command<any>[]): this {\n for (const command of commands) {\n command.$parent = this;\n const alias = { command, alias: command.$names[0] };\n for (let i = 0; i < command.$names.length; i++) {\n if (i === 0) this.$children.set(command.$names[i], { command });\n this.$children.set(command.$names[i], alias);\n }\n }\n return this;\n }\n\n /**\n * Creates a new subcommand and adds it.\n * @param names The aliases of the subcommand.\n * @param builder A builder to create the command.\n */\n subCommand(names: string | string[], builder: Builder): this;\n /**\n * Creates a new subcommand and adds it.\n * @param names The aliases of the subcommand.\n * @param desc The description of the subcommand.\n * @param version The version of the subcommand.\n */\n subCommand(\n names: string | string[],\n desc?: string,\n version?: string,\n ): Command<any>;\n\n subCommand(\n names: string | string[],\n descOrBuilder?: Builder | string,\n version?: string,\n ): Command<any> {\n if (typeof descOrBuilder === \"function\") {\n const command = new Command(names);\n descOrBuilder(command);\n this.add(command);\n return this;\n }\n\n const command = new Command(names, descOrBuilder, version);\n this.add(command);\n return command;\n }\n\n /**\n * Allows unknown options.\n * @returns this\n */\n allowUnknownOptions(): this {\n this.$allowUnknownOptions = true;\n return this;\n }\n\n /**\n * Parses a set of command-line arguments.\n * @param argv The arguments to parse.\n * @returns A parse result.\n */\n async parse(argv: string[]): Promise<ParseResult<T>> {\n // eslint-disable-next-line -- alias to this is necessary to go through the tree\n let command: Command<any> = this;\n let found = false;\n const input: Record<string, unknown> = {};\n\n const args: string[] = [];\n const opts: Record<string, string> = {};\n\n const errors: ConvokerError[] = [];\n const map = command.buildInputMap();\n\n function getOption(key: string, isSpecial?: boolean) {\n const entry = map.get(key);\n if (!entry) {\n if (!command.$allowUnknownOptions && !isSpecial)\n errors.push(new UnknownOptionError(command, key));\n return null;\n }\n return entry.value as Option<any, any, any>;\n }\n\n function setOption(\n key: string,\n option: Option<any, any, any>,\n value?: string,\n ) {\n if (option.$kind === \"boolean\") {\n opts[key] = \"true\";\n } else if (value !== undefined) {\n opts[key] = value;\n }\n }\n\n let isVersion = false;\n let isHelp = false;\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i];\n if (arg.startsWith(\"--\")) {\n // --long[=value] or --long [value]\n const [key, value] = arg.slice(2).split(\"=\");\n\n let isSpecial = false;\n if (key === \"help\") {\n isHelp = true;\n isSpecial = true;\n } else if (key === \"version\") {\n isVersion = true;\n isSpecial = true;\n }\n\n const option = getOption(key, isSpecial);\n if (option) {\n if (value === undefined)\n setOption(\n key,\n option,\n option.$kind === \"boolean\" ? undefined : argv[++i],\n );\n else setOption(key, option, value);\n }\n } else if (arg.startsWith(\"-\")) {\n // -abc or -k[=value] or -k [value]\n const [shortKeys, value] = arg.slice(1).split(\"=\");\n const chars = shortKeys.split(\"\");\n let usedValue: string | undefined = value;\n\n for (const char of chars) {\n let isSpecial = false;\n if (char === \"h\") {\n isHelp = true;\n isSpecial = true;\n } else if (char === \"V\") {\n isVersion = true;\n isSpecial = true;\n }\n\n const option = getOption(char, isSpecial);\n if (!option) continue;\n\n if (option.$kind !== \"boolean\" && usedValue === undefined) {\n usedValue = argv[++i];\n }\n setOption(char, option, usedValue);\n usedValue = undefined; // only first consumes\n }\n } else {\n // positional\n if (command.$children.has(arg) && !found) {\n command = command.$children.get(arg)!.command;\n if (command.$theme) {\n setPromptTheme(command.$theme);\n setLogTheme(command.$theme);\n }\n } else {\n found = true;\n args.push(arg);\n }\n }\n }\n\n // Apply user values, defaults, or enforce required\n let index = 0;\n for (const key in command.$input) {\n const entry = command.$input[key];\n let rawValue: string | string[] | undefined;\n\n if (entry instanceof Positional) {\n if (entry.$list) {\n rawValue = args.slice(index);\n index = args.length;\n if (\n !command.$allowSurpassArgLimit &&\n rawValue.length === 0 &&\n entry.$required\n ) {\n errors.push(new MissingRequiredArgumentError(command, key, entry));\n }\n } else {\n rawValue = args[index++];\n if (rawValue === undefined && entry.$required) {\n errors.push(new MissingRequiredArgumentError(command, key, entry));\n }\n }\n } else {\n for (const name of entry.$names) {\n if (opts[name] !== undefined) {\n rawValue = entry.$list\n ? opts[name].split(entry.$separator ?? \",\")\n : opts[name];\n break;\n }\n }\n }\n\n if (rawValue !== undefined) {\n input[key] = await convert(entry.$kind, rawValue);\n } else if (entry.$default !== undefined) {\n input[key] = entry.$default;\n } else if (entry.$required) {\n if (entry instanceof Option) {\n errors.push(new MissingRequiredOptionError(command, key, entry));\n } else {\n errors.push(new MissingRequiredArgumentError(command, key, entry));\n }\n }\n }\n\n // Check for too many arguments\n const remainingArgs = args.slice(index);\n if (!command.$allowSurpassArgLimit && remainingArgs.length > 0) {\n errors.push(new TooManyArgumentsError(command));\n }\n\n return {\n input: input as InferInput<T>,\n command,\n errors,\n isVersion,\n isHelp,\n };\n }\n\n private buildInputMap(\n ignoreParentMap?: boolean,\n ): Map<string | number, MapEntry> {\n const map = new Map<string | number, MapEntry>();\n\n let i = 0;\n for (const key in this.$input) {\n const value = this.$input[key];\n if (value instanceof Positional) {\n map.set(i++, { value, key });\n } else {\n for (const name of value.$names) {\n map.set(name, { value, key });\n }\n }\n }\n\n if (!ignoreParentMap) {\n for (const [key, entry] of this.$parent?.buildInputMap() ?? []) {\n map.set(key, entry);\n }\n }\n\n for (const [, { command }] of this.$children) {\n for (const [key, entry] of command.buildInputMap(true)) {\n map.set(key, entry);\n }\n }\n\n return map;\n }\n\n /**\n * Allows surpassing the amount of arguments specified.\n * @returns this\n */\n allowSurpassArgLimit(): this {\n this.$allowSurpassArgLimit = true;\n return this;\n }\n\n /**\n * Gets the full command path (name including parents).\n * @returns The full command path.\n */\n fullCommandPath(): string {\n const names: string[] = [];\n // eslint-disable-next-line -- necessary for traversing up the tree\n let cmd: Command<any> | undefined = this;\n while (cmd) {\n names.unshift(cmd.$names[0]);\n cmd = cmd.$parent;\n }\n return names.join(\" \");\n }\n\n /**\n * The default error screen.\n * @param errors The errors.\n */\n defaultErrorScreen(errors: Error[]) {\n let printHelpScreen = false;\n const nonCliErrors: Error[] = [];\n\n for (const error of errors) {\n if (error instanceof ConvokerError) {\n if (!(error instanceof HelpAskedError)) error.print();\n printHelpScreen = true;\n } else {\n nonCliErrors.push(error);\n }\n }\n\n if (nonCliErrors.length) throw nonCliErrors[0];\n\n if (!printHelpScreen) return;\n const pad = (s: string, len: number) => s.padEnd(len, \" \");\n\n console.log(\n `${bold(\"usage:\")} ${cyan(this.fullCommandPath())} ${gray(\"[options] [arguments]\")}`,\n );\n if (this.$description) {\n console.log(`${this.$description}`);\n }\n\n if (this.$version) {\n console.log(`${bold(\"version\")} ${this.$version}`);\n }\n\n // OPTIONS\n const opts = Object.entries(this.$input)\n .filter(([, entry]) => entry instanceof Option)\n .map(([key, entry]) => ({ key, entry: entry as Option<any, any, any> }));\n\n if (opts.length > 0) {\n console.log(bold(\"options:\"));\n const longest = Math.max(\n ...opts.map(({ entry }) => entry.$names.join(\", \").length),\n );\n for (const { entry } of opts) {\n const names = entry.$names\n .map((n) => (n.length === 1 ? `-${n}` : `--${n}`))\n .join(\", \");\n const line = ` ${cyan(pad(names, longest + 4))}${gray(entry.$description ?? \"\")}`;\n console.log(line);\n }\n }\n\n // POSITIONALS\n const positionals = Object.entries(this.$input)\n .filter(([, entry]) => entry instanceof Positional)\n .map(([key, entry]) => ({\n key,\n entry: entry as Positional<any, any, any>,\n }));\n\n if (positionals.length > 0) {\n console.log(bold(\"arguments:\"));\n const longest = Math.max(...positionals.map(({ key }) => key.length));\n for (const { key, entry } of positionals) {\n const name = entry.$required ? `<${key}>` : `[${key}]`;\n const line = ` ${cyan(pad(name, longest + 4))}${gray(entry.$description ?? \"\")}`;\n console.log(line);\n }\n }\n\n // SUBCOMMANDS\n if (this.$children.size > 0) {\n console.log(bold(\"sub commands:\"));\n const deduped = Array.from(\n new Map(\n [...this.$children.values()].map((a) => [\n a.command.$names[0],\n a.command,\n ]),\n ).values(),\n );\n\n const longest = Math.max(...deduped.map((c) => c.$names[0].length));\n for (const cmd of deduped) {\n const line = ` ${cyan(pad(cmd.$names[0], longest + 4))}${gray(cmd.$description) ?? \"\"}`;\n console.log(line);\n }\n console.log();\n console.log(\n `run '${cyan(`${this.fullCommandPath()} <command> --help`)}' for more info on a command.`,\n );\n }\n }\n\n /**\n * Handles a set of errors.\n * @param errors The errors to handle.\n * @param input The parsed input, if possible.\n * @returns this\n */\n async handleErrors(\n errors: Error[],\n input?: Partial<InferInput<T>>,\n ): Promise<this> {\n // eslint-disable-next-line -- necessary for traversing up the tree\n let command: Command<any> = this;\n while (!command.$errorFn && command.$parent) {\n command = command.$parent;\n }\n\n if (command.$errorFn) {\n await command.$errorFn(command, errors, input ?? {});\n } else {\n this.defaultErrorScreen(errors);\n }\n return this;\n }\n\n /**\n * Runs a command.\n * @param argv The arguments to run the command with. Defaults to your runtime's `argv` equivalent.\n * @returns this\n */\n async run(argv?: string[]): Promise<this> {\n const result = await this.parse(argv ?? process.argv.slice(2));\n if (result.isHelp) {\n result.command.handleErrors([new HelpAskedError(result.command)]);\n return this;\n } else if (result.isVersion) {\n console.log(\n `${result.command.fullCommandPath()} version ${result.command.$version}`,\n );\n return this;\n }\n\n try {\n if (result.errors.length > 0) {\n await result.command.handleErrors(result.errors, result.input);\n } else if (!result.command.$fn) {\n await result.command.handleErrors(\n [new HelpAskedError(result.command), ...result.errors],\n result.input,\n );\n } else {\n const middlewares = collectMiddlewares(result.command);\n if (middlewares.length > 0) {\n const runner = compose(middlewares);\n // finalNext calls the command action with the same input\n await runner(result.input, async () => {\n await result.command.$fn?.(result.input);\n });\n } else {\n await result.command.$fn(result.input);\n }\n }\n } catch (e) {\n if (!(e instanceof Error)) {\n console.warn(\n \"[convoker] an error that is not instance of `Error` was thrown. this may cause undefined behavior.\",\n );\n }\n await result.command.handleErrors([e as Error]);\n }\n return this;\n }\n}\n\nfunction collectMiddlewares(cmd: Command<any>) {\n const middlewares: MiddlewareFn<any>[] = [];\n let current: Command<any> | undefined = cmd;\n while (current) {\n if (current.$middlewares.length) {\n middlewares.unshift(...current.$middlewares);\n }\n current = current.$parent;\n }\n return middlewares;\n}\n\nfunction compose(mws: MiddlewareFn<any>[]) {\n return (input: InferInput<any>, finalNext?: () => Promise<any>) => {\n let index = -1;\n const dispatch = (i: number): Promise<any> => {\n if (i <= index)\n return Promise.reject(new Error(\"next() called multiple times\"));\n index = i;\n const fn = mws[i];\n if (!fn) {\n // when middlewares exhausted call finalNext if provided\n return finalNext ? finalNext() : Promise.resolve();\n }\n try {\n return Promise.resolve(fn(input, () => dispatch(i + 1)));\n } catch (err) {\n return Promise.reject(err);\n }\n };\n return dispatch(0);\n };\n}\n\nexport * from \"./error\";\n"],"mappings":";;;;;;;;;;;AAGA,IAAa,aAAb,cAAgC,MAAM;;;;;CAKpC,YAAY,YAAoB;AAC9B,QAAM,wBAAwB,WAAW,KAAK;;;;;;;;;;;;;;;;;ACHlD,IAAIA,KAAY;;;;;AAMhB,SAAgBC,WAAS,OAAc;AACrC,MAAK;;;;;AA6BP,MAAaC,iBAAyB;CACpC,QAAQ;CACR,QAAQ,QAAQ;CAChB,QAAQ,QAAQ;CAChB,WAAW;CACZ;AAED,IAAIC,S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W,GAAG,QAAQ,SAAS;AAEpD,OAAI;AACF,WAAO,QAAQ,QAAQ,GAAG,aAAa,SAAS,IAAI,EAAE,CAAC,CAAC;YACjD,KAAK;AACZ,WAAO,QAAQ,OAAO,IAAI;;;AAG9B,SAAO,SAAS,EAAE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as Theme } from "./
|
|
2
|
-
import { t as StandardSchemaV1 } from "./standard-schema-
|
|
1
|
+
import { n as Theme } from "./theme-EERPMtQU.mjs";
|
|
2
|
+
import { t as StandardSchemaV1 } from "./standard-schema-D1sStgzy.mjs";
|
|
3
3
|
import { i as raw_d_exports } from "./raw-BqvlveTU.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/prompt/index.d.ts
|
|
@@ -196,4 +196,5 @@ interface EditorOpts extends BaseOpts<string> {
|
|
|
196
196
|
*/
|
|
197
197
|
declare function editor(opts: EditorOpts): Promise<string>;
|
|
198
198
|
//#endregion
|
|
199
|
-
export { text as _, SearchOpts as a, TextOpts as c, index_d_exports as d, multiselect as f, setTheme as g, select as h, PasswordOpts as i, confirm as l, search as m, ConfirmOpts as n, SelectOption as o, password as p, EditorOpts as r, SelectOpts as s, BaseOpts as t, editor as u };
|
|
199
|
+
export { text as _, SearchOpts as a, TextOpts as c, index_d_exports as d, multiselect as f, setTheme as g, select as h, PasswordOpts as i, confirm as l, search as m, ConfirmOpts as n, SelectOption as o, password as p, EditorOpts as r, SelectOpts as s, BaseOpts as t, editor as u };
|
|
200
|
+
//# sourceMappingURL=index-C0cH9MIP.d.mts.map
|
|
@@ -1,8 +1,22 @@
|
|
|
1
|
-
import { t as StandardSchemaV1 } from "./standard-schema-
|
|
1
|
+
import { t as StandardSchemaV1 } from "./standard-schema-D1sStgzy.mjs";
|
|
2
2
|
|
|
3
|
-
//#region src/input.d.ts
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
//#region src/input/error.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Thrown when the command fails to validate an input.
|
|
6
|
+
*/
|
|
7
|
+
declare class InputValidationError extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* A list of messages.
|
|
10
|
+
*/
|
|
11
|
+
messages: string[];
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new input validation error.
|
|
14
|
+
* @param messages The messages.
|
|
15
|
+
*/
|
|
16
|
+
constructor(messages: string[]);
|
|
17
|
+
}
|
|
18
|
+
declare namespace index_d_exports {
|
|
19
|
+
export { BasicKind, InferEntry, InferInput, Input, InputValidationError, Kind, Option, Positional, TypeOf, argument, convert, option, positional };
|
|
6
20
|
}
|
|
7
21
|
/**
|
|
8
22
|
* An input object.
|
|
@@ -184,4 +198,5 @@ declare function positional<T extends Kind>(kind: T): Positional<T>;
|
|
|
184
198
|
*/
|
|
185
199
|
declare function argument<T extends Kind>(kind: T): Positional<T>;
|
|
186
200
|
//#endregion
|
|
187
|
-
export { Kind as a, TypeOf as c,
|
|
201
|
+
export { Kind as a, TypeOf as c, index_d_exports as d, option as f, Input as i, argument as l, InputValidationError as m, InferEntry as n, Option as o, positional as p, InferInput as r, Positional as s, BasicKind as t, convert as u };
|
|
202
|
+
//# sourceMappingURL=index-C6iJZTo3.d.mts.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
declare namespace index_d_exports {
|
|
2
|
+
export { bgBlack, bgBlue, bgBlueBright, bgCyan, bgCyanBright, bgGray, bgGreen, bgGreenBright, bgMagenta, bgMagentaBright, bgRed, bgRedBright, bgWhite, bgWhiteBright, bgYellow, bgYellowBright, black, blue, blueBright, bold, createAnsiColor, cyan, cyanBright, dim, gray, green, greenBright, hidden, inverse, italic, magenta, magentaBright, overline, red, redBright, reset, strikethrough, supportsColor, underline, white, whiteBright, yellow, yellowBright };
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* If the runtime supports color.
|
|
6
|
+
*/
|
|
7
|
+
declare const supportsColor: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a function that wraps a string in ANSI codes.
|
|
10
|
+
* @param open The opening ANSI code.
|
|
11
|
+
* @param close The closing ANSI code.
|
|
12
|
+
* @returns A function that wraps the string in ANSI codes.
|
|
13
|
+
*/
|
|
14
|
+
declare function createAnsiColor(open: number, close: number): (input: any) => string;
|
|
15
|
+
declare const reset: (input: any) => string;
|
|
16
|
+
declare const bold: (input: any) => string;
|
|
17
|
+
declare const dim: (input: any) => string;
|
|
18
|
+
declare const italic: (input: any) => string;
|
|
19
|
+
declare const underline: (input: any) => string;
|
|
20
|
+
declare const overline: (input: any) => string;
|
|
21
|
+
declare const inverse: (input: any) => string;
|
|
22
|
+
declare const hidden: (input: any) => string;
|
|
23
|
+
declare const strikethrough: (input: any) => string;
|
|
24
|
+
declare const black: (input: any) => string;
|
|
25
|
+
declare const red: (input: any) => string;
|
|
26
|
+
declare const green: (input: any) => string;
|
|
27
|
+
declare const yellow: (input: any) => string;
|
|
28
|
+
declare const blue: (input: any) => string;
|
|
29
|
+
declare const magenta: (input: any) => string;
|
|
30
|
+
declare const cyan: (input: any) => string;
|
|
31
|
+
declare const white: (input: any) => string;
|
|
32
|
+
declare const gray: (input: any) => string;
|
|
33
|
+
declare const bgBlack: (input: any) => string;
|
|
34
|
+
declare const bgRed: (input: any) => string;
|
|
35
|
+
declare const bgGreen: (input: any) => string;
|
|
36
|
+
declare const bgYellow: (input: any) => string;
|
|
37
|
+
declare const bgBlue: (input: any) => string;
|
|
38
|
+
declare const bgMagenta: (input: any) => string;
|
|
39
|
+
declare const bgCyan: (input: any) => string;
|
|
40
|
+
declare const bgWhite: (input: any) => string;
|
|
41
|
+
declare const bgGray: (input: any) => string;
|
|
42
|
+
declare const redBright: (input: any) => string;
|
|
43
|
+
declare const greenBright: (input: any) => string;
|
|
44
|
+
declare const yellowBright: (input: any) => string;
|
|
45
|
+
declare const blueBright: (input: any) => string;
|
|
46
|
+
declare const magentaBright: (input: any) => string;
|
|
47
|
+
declare const cyanBright: (input: any) => string;
|
|
48
|
+
declare const whiteBright: (input: any) => string;
|
|
49
|
+
declare const bgRedBright: (input: any) => string;
|
|
50
|
+
declare const bgGreenBright: (input: any) => string;
|
|
51
|
+
declare const bgYellowBright: (input: any) => string;
|
|
52
|
+
declare const bgBlueBright: (input: any) => string;
|
|
53
|
+
declare const bgMagentaBright: (input: any) => string;
|
|
54
|
+
declare const bgCyanBright: (input: any) => string;
|
|
55
|
+
declare const bgWhiteBright: (input: any) => string;
|
|
56
|
+
//#endregion
|
|
57
|
+
export { inverse as A, underline as B, cyanBright as C, greenBright as D, green as E, red as F, whiteBright as H, redBright as I, reset as L, magenta as M, magentaBright as N, hidden as O, overline as P, strikethrough as R, cyan as S, gray as T, yellow as U, white as V, yellowBright as W, black as _, bgCyanBright as a, bold as b, bgGreenBright as c, bgRed as d, bgRedBright as f, bgYellowBright as g, bgYellow as h, bgCyan as i, italic as j, index_d_exports as k, bgMagenta as l, bgWhiteBright as m, bgBlue as n, bgGray as o, bgWhite as p, bgBlueBright as r, bgGreen as s, bgBlack as t, bgMagentaBright as u, blue as v, dim as w, createAnsiColor as x, blueBright as y, supportsColor as z };
|
|
58
|
+
//# sourceMappingURL=index-CCQ6jz54.d.mts.map
|
|
@@ -1,24 +1,8 @@
|
|
|
1
|
-
import { n as Theme } from "./
|
|
2
|
-
import { i as Input, o as Option, r as InferInput, s as Positional } from "./
|
|
1
|
+
import { n as Theme } from "./theme-EERPMtQU.mjs";
|
|
2
|
+
import { i as Input, o as Option, r as InferInput, s as Positional } from "./index-C6iJZTo3.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/command/error.d.ts
|
|
3
5
|
|
|
4
|
-
//#region src/error.d.ts
|
|
5
|
-
declare namespace error_d_exports {
|
|
6
|
-
export { ConvokerError, HelpAskedError, InputValidationError, MissingRequiredArgumentError, MissingRequiredOptionError, TooManyArgumentsError, UnknownOptionError };
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Thrown when the command fails to validate an input.
|
|
10
|
-
*/
|
|
11
|
-
declare class InputValidationError extends Error {
|
|
12
|
-
/**
|
|
13
|
-
* A list of messages.
|
|
14
|
-
*/
|
|
15
|
-
messages: string[];
|
|
16
|
-
/**
|
|
17
|
-
* Creates a new input validation error.
|
|
18
|
-
* @param messages The messages.
|
|
19
|
-
*/
|
|
20
|
-
constructor(messages: string[]);
|
|
21
|
-
}
|
|
22
6
|
/**
|
|
23
7
|
* A Convoker-related error. These are usually handled by default.
|
|
24
8
|
*/
|
|
@@ -111,7 +95,7 @@ declare class MissingRequiredArgumentError extends ConvokerError {
|
|
|
111
95
|
constructor(command: Command<any>, key: string, entry: Positional<any, any, any>);
|
|
112
96
|
}
|
|
113
97
|
//#endregion
|
|
114
|
-
//#region src/command.d.ts
|
|
98
|
+
//#region src/command/index.d.ts
|
|
115
99
|
/**
|
|
116
100
|
* What the command is an alias for.
|
|
117
101
|
*/
|
|
@@ -268,11 +252,11 @@ declare class Command<T extends Input = Input> {
|
|
|
268
252
|
*/
|
|
269
253
|
error(fn: ErrorFn<T>): this;
|
|
270
254
|
/**
|
|
271
|
-
* Adds
|
|
272
|
-
* @param
|
|
255
|
+
* Adds existing commands to this.
|
|
256
|
+
* @param commands The commands.
|
|
273
257
|
* @returns this
|
|
274
258
|
*/
|
|
275
|
-
add(
|
|
259
|
+
add(...commands: Command<any>[]): this;
|
|
276
260
|
/**
|
|
277
261
|
* Creates a new subcommand and adds it.
|
|
278
262
|
* @param names The aliases of the subcommand.
|
|
@@ -328,4 +312,5 @@ declare class Command<T extends Input = Input> {
|
|
|
328
312
|
run(argv?: string[]): Promise<this>;
|
|
329
313
|
}
|
|
330
314
|
//#endregion
|
|
331
|
-
export { ErrorFn as a, ConvokerError as c,
|
|
315
|
+
export { ErrorFn as a, ConvokerError as c, MissingRequiredOptionError as d, TooManyArgumentsError as f, CommandAlias as i, HelpAskedError as l, Builder as n, MiddlewareFn as o, UnknownOptionError as p, Command as r, ParseResult as s, ActionFn as t, MissingRequiredArgumentError as u };
|
|
316
|
+
//# sourceMappingURL=index-OUlP1L9o.d.mts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -1,73 +1,92 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
1
|
+
import { k as index_d_exports } from "./index-CCQ6jz54.mjs";
|
|
2
|
+
import { i as DeepPartial, n as Theme, r as defineTheme, t as DEFAULT_THEME } from "./theme-EERPMtQU.mjs";
|
|
3
|
+
import "./standard-schema-D1sStgzy.mjs";
|
|
4
|
+
import { d as index_d_exports$1 } from "./index-C6iJZTo3.mjs";
|
|
5
|
+
import { a as ErrorFn, c as ConvokerError, d as MissingRequiredOptionError, f as TooManyArgumentsError, i as CommandAlias, l as HelpAskedError, n as Builder, o as MiddlewareFn, p as UnknownOptionError, r as Command, s as ParseResult, t as ActionFn, u as MissingRequiredArgumentError } from "./index-OUlP1L9o.mjs";
|
|
5
6
|
import "./raw-BqvlveTU.mjs";
|
|
6
|
-
import { d as index_d_exports } from "./index-
|
|
7
|
+
import { d as index_d_exports$3 } from "./index-C0cH9MIP.mjs";
|
|
8
|
+
import Stream from "node:stream";
|
|
7
9
|
|
|
8
|
-
//#region src/log.d.ts
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
//#region src/log/error.d.ts
|
|
11
|
+
/**
|
|
12
|
+
* Error for when logs fail to write to stdout/stderr.
|
|
13
|
+
*/
|
|
14
|
+
declare class WriteError extends Error {
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new error for stream writes.
|
|
17
|
+
* @param streamName The name of the stream.
|
|
18
|
+
*/
|
|
19
|
+
constructor(streamName: string);
|
|
20
|
+
}
|
|
21
|
+
declare namespace index_d_exports$2 {
|
|
22
|
+
export { Config, DEFAULT_CONFIG, WriteError, error, fatal, info, setConfig, setTheme, trace, warn };
|
|
11
23
|
}
|
|
12
24
|
/**
|
|
13
|
-
*
|
|
25
|
+
* Sets the theme for logs.
|
|
26
|
+
* @param theme The theme to set.
|
|
14
27
|
*/
|
|
15
|
-
|
|
28
|
+
declare function setTheme(theme: Theme): void;
|
|
29
|
+
/**
|
|
30
|
+
* Log configuration.
|
|
31
|
+
*/
|
|
32
|
+
interface Config {
|
|
16
33
|
/**
|
|
17
|
-
* The format
|
|
34
|
+
* The configuration format.
|
|
18
35
|
*/
|
|
19
|
-
format: "text" | "json"
|
|
36
|
+
format: "text" | "json";
|
|
20
37
|
/**
|
|
21
38
|
* Standard output.
|
|
22
39
|
*/
|
|
23
|
-
stdout:
|
|
40
|
+
stdout: Stream.Writable;
|
|
24
41
|
/**
|
|
25
|
-
* Standard error.
|
|
42
|
+
* Standard error output.
|
|
26
43
|
*/
|
|
27
|
-
stderr:
|
|
44
|
+
stderr: Stream.Writable;
|
|
28
45
|
/**
|
|
29
|
-
*
|
|
46
|
+
* How much space in the JSON output of objects.
|
|
47
|
+
* This does not change spacing in JSON logs, only for objects passed into log functions.
|
|
30
48
|
*/
|
|
31
|
-
|
|
49
|
+
jsonSpace: number;
|
|
32
50
|
}
|
|
33
51
|
/**
|
|
34
|
-
*
|
|
35
|
-
* @param t The theme.
|
|
36
|
-
*/
|
|
37
|
-
declare function setTheme(t: Theme): void;
|
|
38
|
-
/**
|
|
39
|
-
* Sets new configuration.
|
|
40
|
-
* @param c The config.
|
|
52
|
+
* Default log configuration.
|
|
41
53
|
*/
|
|
42
|
-
declare
|
|
54
|
+
declare const DEFAULT_CONFIG: Config;
|
|
43
55
|
/**
|
|
44
|
-
* Sets
|
|
56
|
+
* Sets log configuration.
|
|
57
|
+
* @param cfg The configuration, optionally including a theme.
|
|
45
58
|
*/
|
|
46
|
-
declare function
|
|
59
|
+
declare function setConfig({
|
|
60
|
+
theme,
|
|
61
|
+
...cfg
|
|
62
|
+
}: DeepPartial<Config> & {
|
|
63
|
+
theme?: Theme;
|
|
64
|
+
}): void;
|
|
47
65
|
/**
|
|
48
|
-
* Prints
|
|
49
|
-
* @param msgs The messages to
|
|
66
|
+
* Prints messages.
|
|
67
|
+
* @param msgs The messages to print.
|
|
50
68
|
*/
|
|
51
|
-
declare function trace(...msgs: any[]):
|
|
69
|
+
declare function trace(...msgs: any[]): void;
|
|
52
70
|
/**
|
|
53
|
-
* Prints
|
|
54
|
-
* @param msgs The messages to
|
|
71
|
+
* Prints messages.
|
|
72
|
+
* @param msgs The messages to print.
|
|
55
73
|
*/
|
|
56
|
-
declare function info(...msgs: any[]):
|
|
74
|
+
declare function info(...msgs: any[]): void;
|
|
57
75
|
/**
|
|
58
|
-
* Prints
|
|
59
|
-
* @param msgs The messages to
|
|
76
|
+
* Prints warning messages.
|
|
77
|
+
* @param msgs The messages to print.
|
|
60
78
|
*/
|
|
61
|
-
declare function warn(...msgs: any[]):
|
|
79
|
+
declare function warn(...msgs: any[]): void;
|
|
62
80
|
/**
|
|
63
|
-
* Prints
|
|
64
|
-
* @param msgs The messages to
|
|
81
|
+
* Prints error messages.
|
|
82
|
+
* @param msgs The messages to print.
|
|
65
83
|
*/
|
|
66
|
-
declare function error(...msgs: any[]):
|
|
84
|
+
declare function error(...msgs: any[]): void;
|
|
67
85
|
/**
|
|
68
|
-
* Prints
|
|
69
|
-
* @param msgs The messages to
|
|
86
|
+
* Prints messages and exits with code -1.
|
|
87
|
+
* @param msgs The messages to print.
|
|
70
88
|
*/
|
|
71
|
-
declare function fatal(...msgs: any[]):
|
|
89
|
+
declare function fatal(...msgs: any[]): void;
|
|
72
90
|
//#endregion
|
|
73
|
-
export { ActionFn, Builder, Command, CommandAlias, ErrorFn, MiddlewareFn, ParseResult,
|
|
91
|
+
export { ActionFn, Builder, Command, CommandAlias, ConvokerError, DEFAULT_THEME, ErrorFn, HelpAskedError, MiddlewareFn, MissingRequiredArgumentError, MissingRequiredOptionError, ParseResult, Theme, TooManyArgumentsError, UnknownOptionError, index_d_exports as color, defineTheme, index_d_exports$1 as i, index_d_exports$2 as log, index_d_exports$3 as prompt };
|
|
92
|
+
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import "./
|
|
5
|
-
import "./
|
|
6
|
-
import { a as
|
|
7
|
-
import {
|
|
8
|
-
import { a as input_exports } from "./input-DRy_sVxZ.mjs";
|
|
1
|
+
import { x as color_exports } from "./color-s-N9yh90.mjs";
|
|
2
|
+
import { n as defineTheme, t as DEFAULT_THEME } from "./theme-Chg3mOhZ.mjs";
|
|
3
|
+
import "./standard-schema-WhGEzW0C.mjs";
|
|
4
|
+
import "./raw-DVT5lw11.mjs";
|
|
5
|
+
import { a as prompt_exports } from "./prompt-OXGrAkDf.mjs";
|
|
6
|
+
import { a as MissingRequiredOptionError, c as log_exports, i as MissingRequiredArgumentError, n as ConvokerError, o as TooManyArgumentsError, r as HelpAskedError, s as UnknownOptionError, t as Command } from "./command-C9QIG--8.mjs";
|
|
7
|
+
import { a as input_exports } from "./input-li13L1uf.mjs";
|
|
9
8
|
|
|
10
|
-
export { Command,
|
|
9
|
+
export { Command, ConvokerError, DEFAULT_THEME, HelpAskedError, MissingRequiredArgumentError, MissingRequiredOptionError, TooManyArgumentsError, UnknownOptionError, color_exports as color, defineTheme, input_exports as i, log_exports as log, prompt_exports as prompt };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import "../standard-schema-D1sStgzy.mjs";
|
|
2
|
+
import { a as Kind, c as TypeOf, f as option, i as Input, l as argument, m as InputValidationError, n as InferEntry, o as Option, p as positional, r as InferInput, s as Positional, t as BasicKind, u as convert } from "../index-C6iJZTo3.mjs";
|
|
3
|
+
export { BasicKind, InferEntry, InferInput, Input, InputValidationError, Kind, Option, Positional, TypeOf, argument, convert, option, positional };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { n as InputValidationError } from "../standard-schema-WhGEzW0C.mjs";
|
|
2
|
+
import { i as convert, n as Positional, o as option, r as argument, s as positional, t as Option } from "../input-li13L1uf.mjs";
|
|
3
|
+
|
|
4
|
+
export { InputValidationError, Option, Positional, argument, convert, option, positional };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { t as __export } from "./chunk-z5eko27R.mjs";
|
|
2
|
-
import { t as validate } from "./standard-schema-
|
|
2
|
+
import { n as InputValidationError, t as validate } from "./standard-schema-WhGEzW0C.mjs";
|
|
3
3
|
|
|
4
|
-
//#region src/input.ts
|
|
4
|
+
//#region src/input/index.ts
|
|
5
5
|
var input_exports = /* @__PURE__ */ __export({
|
|
6
|
+
InputValidationError: () => InputValidationError,
|
|
6
7
|
Option: () => Option,
|
|
7
8
|
Positional: () => Positional,
|
|
8
9
|
argument: () => argument,
|
|
@@ -171,4 +172,5 @@ function argument(kind) {
|
|
|
171
172
|
}
|
|
172
173
|
|
|
173
174
|
//#endregion
|
|
174
|
-
export { input_exports as a, convert as i, Positional as n, option as o, argument as r, positional as s, Option as t };
|
|
175
|
+
export { input_exports as a, convert as i, Positional as n, option as o, argument as r, positional as s, Option as t };
|
|
176
|
+
//# sourceMappingURL=input-li13L1uf.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-li13L1uf.mjs","names":[],"sources":["../src/input/index.ts"],"sourcesContent":["import { validate, type StandardSchemaV1 } from \"./standard-schema\";\n\n/**\n * An input object.\n */\nexport interface Input {\n [x: string]: Option<any, any, any> | Positional<any, any, any>;\n}\n\n/**\n * A basic input type.\n */\nexport type BasicKind = \"boolean\" | \"string\" | \"number\" | \"bigint\";\n/**\n * An input type.\n */\nexport type Kind = BasicKind | StandardSchemaV1<any, any>;\n\n/**\n * Converts a Kind to a TypeScript type.\n */\nexport type TypeOf<T extends Kind> =\n T extends StandardSchemaV1<any, infer Out>\n ? Out\n : T extends \"boolean\"\n ? boolean\n : T extends \"string\"\n ? string\n : T extends \"number\"\n ? number\n : T extends \"bigint\"\n ? bigint\n : never;\n\n/**\n * Infers TypeScript types from an input object.\n */\nexport type InferInput<T extends Input> = {\n [K in keyof T]: InferEntry<T[K]>;\n};\n\n/**\n * Infers a TypeScript type from an option or positional.\n */\nexport type InferEntry<T> = T extends {\n $kind: infer TKind extends Kind;\n $required: infer Required;\n $list: infer List;\n}\n ? List extends true\n ? Required extends true\n ? TypeOf<TKind>[]\n : TypeOf<TKind>[] | undefined\n : Required extends true\n ? TypeOf<TKind>\n : TypeOf<TKind> | undefined\n : never;\n\n/**\n * Converts a value from a Kind to a TypeScript type.\n * @param kind The kind to convert to.\n * @param value The value to convert.\n * @returns The converted value.\n */\nexport async function convert<TKind extends Kind>(\n kind: TKind,\n value: string | string[],\n): Promise<TypeOf<TKind> | TypeOf<TKind>[]> {\n // Helper for single value conversion\n async function convertOne(val: string): Promise<TypeOf<TKind>> {\n if (typeof kind === \"string\") {\n switch (kind) {\n case \"boolean\":\n return (val === \"true\") as any;\n case \"bigint\":\n return BigInt(val) as any;\n case \"number\":\n return parseFloat(val) as any;\n case \"string\":\n return val as any;\n }\n }\n // Otherwise, Standard Schema\n return validate(kind, val);\n }\n\n // If list → map each item\n if (Array.isArray(value)) {\n const results = await Promise.all(value.map((v) => convertOne(v)));\n return results as any;\n }\n\n // Single value case\n return convertOne(value);\n}\n\n/**\n * An option.\n */\nexport class Option<\n TKind extends Kind,\n TRequired extends boolean = true,\n TList extends boolean = false,\n> {\n /**\n * The kind of this option.\n */\n $kind: TKind;\n /**\n * The aliases of this option.\n */\n $names: string[];\n /**\n * The description of this option.\n */\n $description: string | undefined;\n /**\n * The default value of this option.\n */\n $default: TypeOf<TKind> | undefined;\n /**\n * If this option is required.\n */\n $required: TRequired = true as TRequired;\n /**\n * If this option is a list.\n */\n $list: TList = false as TList;\n /**\n * A separator if this option is a list.\n */\n $separator: string | undefined;\n\n /**\n * Creates a new option.\n * @param kind The type of this option.\n * @param names The names of this option.\n */\n constructor(kind: TKind, names: string[]) {\n this.$kind = kind;\n this.$names = names.map((name) => name.replace(/^-+/, \"\"));\n }\n\n /**\n * Makes this option a list.\n * @returns this\n */\n list(separator?: string): Option<TKind, TRequired, true> {\n this.$list = true as TList;\n this.$separator = separator ?? this.$separator;\n return this as any;\n }\n\n /**\n * Makes this option required.\n * @returns this\n */\n required(): Option<TKind, true, TList> {\n this.$required = true as TRequired;\n return this as any;\n }\n\n /**\n * Makes this option optional.\n * @returns this\n */\n optional(): Option<TKind, false, TList> {\n this.$required = false as TRequired;\n return this as any;\n }\n\n /**\n * Sets a default value.\n * @param value The default value.\n * @returns this\n */\n default(value: TypeOf<TKind>): this {\n this.$default = value;\n return this;\n }\n\n /**\n * Sets a description.\n * @param desc The description.\n * @returns this\n */\n description(desc: string): this {\n this.$description = desc;\n return this;\n }\n}\n\n/**\n * A positional argument.\n */\nexport class Positional<\n TKind extends Kind,\n TRequired extends boolean = true,\n TList extends boolean = false,\n> {\n /**\n * The type of this argument.\n */\n $kind: TKind;\n /**\n * The default value of this argument.\n */\n $default: TypeOf<TKind> | undefined;\n /**\n * The description of this argument.\n */\n $description: string | undefined;\n /**\n * If this argument is required.\n */\n $required: TRequired = true as TRequired;\n /**\n * If this argument is a list.\n */\n $list: TList = false as TList;\n\n /**\n * Creates a new positional argument.\n * @param kind The positional argument.\n */\n constructor(kind: TKind) {\n this.$kind = kind;\n }\n\n /**\n * Makes this argument a list.\n * @returns this\n */\n list(): Positional<TKind, TRequired, true> {\n this.$list = true as TList;\n return this as any;\n }\n\n /**\n * Makes this argument required.\n * @returns this\n */\n required(): Positional<TKind, true, TList> {\n this.$required = true as TRequired;\n return this as any;\n }\n\n /**\n * Makes this argument optional.\n * @returns this\n */\n optional(): Positional<TKind, false, TList> {\n this.$required = false as TRequired;\n return this as any;\n }\n\n /**\n * Sets a default value.\n * @param value The default value.\n * @returns this\n */\n default(value: TypeOf<TKind>): this {\n this.$default = value;\n return this;\n }\n\n /**\n * Sets a description.\n * @param desc The description.\n * @returns this\n */\n description(desc: string): this {\n this.$description = desc;\n return this;\n }\n}\n\n/**\n * Creates a new option.\n * @param kind The kind of option.\n * @param names The names of the option.\n * @returns A new option.\n */\nexport function option<T extends Kind>(kind: T, ...names: string[]): Option<T> {\n return new Option(kind, names);\n}\n\n/**\n * Creates a new positional argument.\n * @param kind The kind of positional argument.\n * @returns A new positional argument.\n */\nexport function positional<T extends Kind>(kind: T): Positional<T> {\n return new Positional(kind);\n}\n\n/**\n * Creates a new positional argument.\n * @param kind The kind of positional argument.\n * @returns A new positional argument.\n */\nexport function argument<T extends Kind>(kind: T): Positional<T> {\n return new Positional(kind);\n}\n\nexport * from \"./error\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgEA,eAAsB,QACpB,MACA,OAC0C;CAE1C,eAAe,WAAW,KAAqC;AAC7D,MAAI,OAAO,SAAS,SAClB,SAAQ,MAAR;GACE,KAAK,UACH,QAAQ,QAAQ;GAClB,KAAK,SACH,QAAO,OAAO,IAAI;GACpB,KAAK,SACH,QAAO,WAAW,IAAI;GACxB,KAAK,SACH,QAAO;;AAIb,SAAO,SAAS,MAAM,IAAI;;AAI5B,KAAI,MAAM,QAAQ,MAAM,CAEtB,QADgB,MAAM,QAAQ,IAAI,MAAM,KAAK,MAAM,WAAW,EAAE,CAAC,CAAC;AAKpE,QAAO,WAAW,MAAM;;;;;AAM1B,IAAa,SAAb,MAIE;;;;;;CAmCA,YAAY,MAAa,OAAiB;mBAfnB;eAIR;AAYb,OAAK,QAAQ;AACb,OAAK,SAAS,MAAM,KAAK,SAAS,KAAK,QAAQ,OAAO,GAAG,CAAC;;;;;;CAO5D,KAAK,WAAoD;AACvD,OAAK,QAAQ;AACb,OAAK,aAAa,aAAa,KAAK;AACpC,SAAO;;;;;;CAOT,WAAuC;AACrC,OAAK,YAAY;AACjB,SAAO;;;;;;CAOT,WAAwC;AACtC,OAAK,YAAY;AACjB,SAAO;;;;;;;CAQT,QAAQ,OAA4B;AAClC,OAAK,WAAW;AAChB,SAAO;;;;;;;CAQT,YAAY,MAAoB;AAC9B,OAAK,eAAe;AACpB,SAAO;;;;;;AAOX,IAAa,aAAb,MAIE;;;;;CA0BA,YAAY,MAAa;mBAVF;eAIR;AAOb,OAAK,QAAQ;;;;;;CAOf,OAA2C;AACzC,OAAK,QAAQ;AACb,SAAO;;;;;;CAOT,WAA2C;AACzC,OAAK,YAAY;AACjB,SAAO;;;;;;CAOT,WAA4C;AAC1C,OAAK,YAAY;AACjB,SAAO;;;;;;;CAQT,QAAQ,OAA4B;AAClC,OAAK,WAAW;AAChB,SAAO;;;;;;;CAQT,YAAY,MAAoB;AAC9B,OAAK,eAAe;AACpB,SAAO;;;;;;;;;AAUX,SAAgB,OAAuB,MAAS,GAAG,OAA4B;AAC7E,QAAO,IAAI,OAAO,MAAM,MAAM;;;;;;;AAQhC,SAAgB,WAA2B,MAAwB;AACjE,QAAO,IAAI,WAAW,KAAK;;;;;;;AAQ7B,SAAgB,SAAyB,MAAwB;AAC/D,QAAO,IAAI,WAAW,KAAK"}
|
package/dist/prompt/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import "../standard-schema-
|
|
1
|
+
import "../theme-EERPMtQU.mjs";
|
|
2
|
+
import "../standard-schema-D1sStgzy.mjs";
|
|
3
3
|
import { i as raw_d_exports } from "../raw-BqvlveTU.mjs";
|
|
4
|
-
import { _ as text, a as SearchOpts, c as TextOpts, f as multiselect, g as setTheme, h as select, i as PasswordOpts, l as confirm, m as search, n as ConfirmOpts, o as SelectOption, p as password, r as EditorOpts, s as SelectOpts, t as BaseOpts, u as editor } from "../index-
|
|
4
|
+
import { _ as text, a as SearchOpts, c as TextOpts, f as multiselect, g as setTheme, h as select, i as PasswordOpts, l as confirm, m as search, n as ConfirmOpts, o as SelectOption, p as password, r as EditorOpts, s as SelectOpts, t as BaseOpts, u as editor } from "../index-C0cH9MIP.mjs";
|
|
5
5
|
export { BaseOpts, ConfirmOpts, EditorOpts, PasswordOpts, SearchOpts, SelectOption, SelectOpts, TextOpts, confirm, editor, multiselect, password, raw_d_exports as raw, search, select, setTheme, text };
|
package/dist/prompt/index.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import "../
|
|
3
|
-
import "../
|
|
4
|
-
import "../
|
|
5
|
-
import { i as
|
|
6
|
-
import { c as setTheme, i as password, l as text, n as editor, o as search, r as multiselect, s as select, t as confirm } from "../prompt-Cvufljin.mjs";
|
|
1
|
+
import "../color-s-N9yh90.mjs";
|
|
2
|
+
import "../theme-Chg3mOhZ.mjs";
|
|
3
|
+
import "../standard-schema-WhGEzW0C.mjs";
|
|
4
|
+
import { i as raw_exports } from "../raw-DVT5lw11.mjs";
|
|
5
|
+
import { c as setTheme, i as password, l as text, n as editor, o as search, r as multiselect, s as select, t as confirm } from "../prompt-OXGrAkDf.mjs";
|
|
7
6
|
|
|
8
7
|
export { confirm, editor, multiselect, password, raw_exports as raw, search, select, setTheme, text };
|
package/dist/prompt/raw.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import { a as readKey, n as cursorDown, o as readLine, r as cursorUp, t as clearLines } from "../raw--889icsd.mjs";
|
|
1
|
+
import { a as readKey, n as cursorDown, o as readLine, r as cursorUp, t as clearLines } from "../raw-DVT5lw11.mjs";
|
|
3
2
|
|
|
4
3
|
export { clearLines, cursorDown, cursorUp, readKey, readLine };
|