zod-args-parser 1.0.2 → 1.0.4

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.
@@ -1 +1 @@
1
- {"version":3,"names":["chalk","concat","getDefaultValueFromSchema","indent","ln","print","println","transformOptionToArg","colors","title","bold","blue","description","white","default","dim","italic","optional","exampleTitle","yellow","example","command","option","cyan","argument","green","placeholder","hex","punctuation","printCliHelp","params","printOptions","arguments","length","undefined","noColors","Proxy","get","_len","str","Array","_key","join","c","customColors","Object","assign","isFirstParamCli","cliOptions","shift","subcommands","printTitle","toUpperCase","cliName","usage","options","allowPositional","longest","optionsToPrint","longestOptionIndent","prepareOptionsToPrint","commandsToPrint","longestSubcommandIndent","prepareCommandsToPrint","argsToPrint","longestArgIndent","prepareArgumentsToPrint","printPreparedOptions","printPreparedCommands","printPreparedArguments","normalizeExample","replace","printSubcommandHelp","subcommand","_len2","_key2","name","normalizeDesc","nameWithAliases","aliases","names","from","Set","map","defaultValue","type","push","JSON","stringify","isOptional","optLength","cmdLength","args","arg","def","spacing","coloredNames","split","help"],"sourceRoot":"../../src","sources":["help.ts"],"sourcesContent":["import chalk from \"chalk\";\nimport { concat, getDefaultValueFromSchema, indent, ln, print, println, transformOptionToArg } from \"./utils.js\";\n\nimport type { Argument, Cli, Option, PrintHelpOpt, Subcommand } from \"./types.js\";\n\n/** Colors */\nconst colors: NonNullable<Required<PrintHelpOpt[\"customColors\"]>> = {\n title: chalk.bold.blue,\n description: chalk.white,\n default: chalk.dim.italic,\n optional: chalk.dim.italic,\n exampleTitle: chalk.yellow,\n example: chalk.dim.italic,\n command: chalk.yellow,\n option: chalk.cyan,\n argument: chalk.green,\n placeholder: chalk.hex(\"#FF9800\"),\n punctuation: chalk.white.dim,\n};\n\ntype PreparedToPrint = {\n names: string;\n description: string;\n placeholder?: string;\n example?: string;\n default?: string;\n optional?: string;\n};\n\nfunction printCliHelp(params: [Cli, ...Subcommand[]], printOptions: PrintHelpOpt = {}) {\n printOptions.colors ??= true;\n\n const noColors = new Proxy(colors, {\n get: () => {\n return (...str: string[]) => str.join(\" \");\n },\n });\n\n const c = printOptions.colors ? colors : noColors;\n\n if (printOptions.customColors) {\n Object.assign(c, printOptions.customColors);\n }\n\n const isFirstParamCli = \"cliName\" in params[0];\n const cliOptions = (isFirstParamCli ? params.shift() : {}) as Cli;\n const subcommands = params as Subcommand[];\n\n /** Print a styled title */\n const printTitle = (title: string) => {\n print(c.title(` ${title.toUpperCase()} `));\n };\n\n // Print CLI usage\n const cliName = cliOptions.cliName ?? \"\";\n const usage =\n cliOptions.usage ??\n concat(\n c.punctuation(\"$\"),\n cliName,\n subcommands.length ? c.command(\"[command]\") : \"\",\n cliOptions.options?.length ? c.option(\"[options]\") : \"\",\n cliOptions.arguments?.length || cliOptions.allowPositional ? c.argument(\"<arguments>\") : \"\",\n );\n printTitle(\"Usage\");\n println();\n println(indent(2), usage, ln(1));\n\n // Print CLI description\n if (cliOptions.description) {\n printTitle(\"Description\");\n println();\n println(indent(2), c.description(cliOptions.description), ln(1));\n }\n\n let longest = 0;\n\n // Prepare CLI options\n const [optionsToPrint, longestOptionIndent] = prepareOptionsToPrint(cliOptions.options);\n if (longestOptionIndent > longest) longest = longestOptionIndent;\n\n // Prepare CLI commands\n const [commandsToPrint, longestSubcommandIndent] = prepareCommandsToPrint(subcommands);\n if (longestSubcommandIndent > longest) longest = longestSubcommandIndent;\n\n // Prepare CLI arguments\n const [argsToPrint, longestArgIndent] = prepareArgumentsToPrint(cliOptions.arguments);\n if (longestArgIndent > longest) longest = longestArgIndent;\n\n // Print CLI options\n printPreparedOptions(optionsToPrint, c, longest);\n\n // Print CLI commands\n printPreparedCommands(commandsToPrint, c, longest);\n\n // Print CLI arguments\n printPreparedArguments(argsToPrint, c, longest);\n\n // Print CLI example\n if (cliOptions.example) {\n printTitle(\"Example\");\n println();\n const normalizeExample = cliOptions.example.replace(/\\n/g, \"\\n\" + indent(3));\n println(indent(2), c.example(normalizeExample), ln(1));\n }\n}\n\nfunction printSubcommandHelp(subcommand: Subcommand, printOptions: PrintHelpOpt = {}, cliName = \"\") {\n printOptions.colors ??= true;\n\n const noColors = new Proxy(colors, {\n get: () => {\n return (...str: string[]) => str.join(\" \");\n },\n });\n\n const c = printOptions.colors ? colors : noColors;\n\n if (printOptions.customColors) {\n Object.assign(c, printOptions.customColors);\n }\n\n /** Print a styled title */\n const printTitle = (title: string) => {\n print(c.title(` ${title.toUpperCase()} `));\n };\n\n // Print command usage\n const usage = concat(\n c.punctuation(\"$\"),\n cliName,\n c.command(subcommand.name),\n subcommand.options?.length ? c.option(\"[options]\") : \"\",\n subcommand.arguments?.length || subcommand.allowPositional ? c.argument(\"<arguments>\") : \"\",\n );\n printTitle(\"Usage\");\n println();\n println(indent(2), usage, ln(1));\n\n // Print command description\n if (subcommand.description) {\n printTitle(\"Description\");\n println();\n const normalizeDesc = subcommand.description.replace(/\\n/g, \"\\n\" + indent(3));\n println(indent(2), c.description(normalizeDesc), ln(1));\n }\n\n let longest = 0;\n\n // Prepare command options\n const [optionsToPrint, longestOptionIndent] = prepareOptionsToPrint(subcommand.options);\n if (longestOptionIndent > longest) longest = longestOptionIndent;\n\n // Prepare command arguments\n const [argsToPrint, longestArgIndent] = prepareArgumentsToPrint(subcommand.arguments);\n if (longestArgIndent > longest) longest = longestArgIndent;\n\n // Print command options\n printPreparedOptions(optionsToPrint, c, longest);\n\n // Print command arguments\n printPreparedArguments(argsToPrint, c, longest);\n\n // Print command example\n if (subcommand.example) {\n printTitle(\"Example\");\n println();\n const normalizeExample = subcommand.example.replace(/\\n/g, \"\\n\" + indent(3));\n println(indent(2), c.example(normalizeExample), ln(1));\n }\n}\n\n// * Prepare\nfunction prepareOptionsToPrint(options: Option[] | undefined): [PreparedToPrint[], number] {\n if (!options || !options.length) return [[], 0];\n\n const optionsToPrint: PreparedToPrint[] = [];\n let longest = 0;\n\n for (const option of options) {\n const nameWithAliases = option.aliases ? [...option.aliases, option.name] : [option.name];\n const names = Array.from(new Set(nameWithAliases.map(name => transformOptionToArg(name)))).join(\", \");\n\n const defaultValue = getDefaultValueFromSchema(option.type);\n\n const placeholder = option.placeholder ?? \" \";\n optionsToPrint.push({\n names,\n placeholder,\n description: option.description ?? option.type.description ?? \"\",\n default: typeof defaultValue !== \"undefined\" ? `(default: ${JSON.stringify(defaultValue)})` : \"\",\n optional: option.type.isOptional() ? \"[optional]\" : \"\",\n example: option.example ?? \"\",\n });\n\n const optLength = names.length + placeholder.length;\n\n if (optLength > longest) longest = optLength;\n }\n\n return [optionsToPrint, longest];\n}\n\nfunction prepareCommandsToPrint(subcommands: Subcommand[] | undefined): [PreparedToPrint[], number] {\n if (!subcommands || !subcommands.length) return [[], 0];\n\n const commandsToPrint: PreparedToPrint[] = [];\n let longest = 0;\n\n for (const subcommand of subcommands) {\n const { name, aliases, description } = subcommand;\n const names = Array.from(new Set([...(aliases ?? []), name])).join(\", \");\n\n const placeholder =\n subcommand.placeholder ?? (subcommand.options ? \"[options]\" : subcommand.allowPositional ? \"<args>\" : \" \");\n\n commandsToPrint.push({ names, placeholder, description: description ?? \"\" });\n\n const cmdLength = names.length + placeholder.length;\n if (cmdLength > longest) longest = cmdLength;\n }\n\n return [commandsToPrint, longest];\n}\n\nfunction prepareArgumentsToPrint(args: Argument[] | undefined): [PreparedToPrint[], number] {\n if (!args || !args.length) return [[], 0];\n\n const argsToPrint: PreparedToPrint[] = [];\n let longest = 0;\n\n for (const arg of args) {\n const defaultValue = getDefaultValueFromSchema(arg.type);\n\n argsToPrint.push({\n names: arg.name,\n description: arg.description ?? \"\",\n default: typeof defaultValue !== \"undefined\" ? `(default: ${JSON.stringify(defaultValue)})` : \"\",\n optional: arg.type.isOptional() ? \"[optional]\" : \"\",\n example: arg.example ?? \"\",\n });\n\n const cmdLength = arg.name.length;\n if (cmdLength > longest) longest = cmdLength;\n }\n\n return [argsToPrint, longest];\n}\n\n// * Print\nfunction printPreparedOptions(optionsToPrint: PreparedToPrint[], c: typeof colors, longest: number) {\n if (!optionsToPrint.length) return;\n\n print(c.title(\" OPTIONS \"));\n\n println();\n\n for (const { names, placeholder, description, example, optional, default: def } of optionsToPrint) {\n const optLength = names.length + (placeholder?.length ?? 0);\n const spacing = longest + 1 - optLength;\n const normalizeDesc = description.replace(/\\n/g, \"\\n\" + indent(longest + 7) + c.punctuation(\"└\"));\n\n const coloredNames = names\n .split(/(,)/)\n .map(name => (name === \",\" ? c.punctuation(name) : c.option(name)))\n .join(\"\");\n\n println(\n indent(2),\n coloredNames,\n c.placeholder(placeholder),\n indent(spacing),\n c.description(normalizeDesc),\n def ? c.default(def) : c.optional(optional),\n );\n\n if (example) {\n const normalizeExample = example.replace(/\\n/g, \"\\n\" + indent(longest + 17));\n println(indent(longest + 6), c.punctuation(\"└\") + c.exampleTitle(\"Example:\"), c.example(normalizeExample));\n }\n }\n\n println();\n}\n\nfunction printPreparedCommands(commandsToPrint: PreparedToPrint[], c: typeof colors, longest: number) {\n if (!commandsToPrint.length) return;\n\n print(c.title(\" COMMANDS \"));\n\n println();\n\n for (const { names, placeholder, description } of commandsToPrint) {\n const optLength = names.length + (placeholder?.length ?? 0);\n const spacing = longest + 1 - optLength;\n const normalizeDesc = description.replace(/\\n/g, \"\\n\" + indent(longest + 7));\n\n const coloredNames = names\n .split(/(,)/)\n .map(name => (name === \",\" ? c.punctuation(name) : c.command(name)))\n .join(\"\");\n\n println(indent(2), coloredNames, c.placeholder(placeholder), indent(spacing), c.description(normalizeDesc));\n }\n\n println();\n}\n\nfunction printPreparedArguments(argsToPrint: PreparedToPrint[], c: typeof colors, longest: number) {\n if (!argsToPrint.length) return;\n\n print(c.title(\" ARGUMENTS \"));\n\n println();\n\n for (const { names, description, example, optional, default: def } of argsToPrint) {\n const spacing = longest + 2 - names.length;\n const normalizeDesc = description.replace(/\\n/g, \"\\n\" + indent(longest + 6) + c.punctuation(\"└\"));\n\n println(\n indent(2),\n c.argument(names),\n indent(spacing),\n c.description(normalizeDesc),\n def ? c.default(def) : c.optional(optional),\n );\n\n if (example) {\n const normalizeExample = example.replace(/\\n/g, \"\\n\" + indent(longest + 16));\n println(indent(longest + 5), c.punctuation(\"└\") + c.exampleTitle(\"Example:\"), c.example(normalizeExample));\n }\n }\n\n println();\n}\n\nexport const help = {\n printCliHelp,\n printSubcommandHelp,\n};\n"],"mappings":"AAAA,MAAO,CAAAA,KAAK,KAAM,OAAO,CACzB,OAASC,MAAM,CAAEC,yBAAyB,CAAEC,MAAM,CAAEC,EAAE,CAAEC,KAAK,CAAEC,OAAO,CAAEC,oBAAoB,KAAQ,YAAY,CAKhH,KAAM,CAAAC,MAA2D,CAAG,CAClEC,KAAK,CAAET,KAAK,CAACU,IAAI,CAACC,IAAI,CACtBC,WAAW,CAAEZ,KAAK,CAACa,KAAK,CACxBC,OAAO,CAAEd,KAAK,CAACe,GAAG,CAACC,MAAM,CACzBC,QAAQ,CAAEjB,KAAK,CAACe,GAAG,CAACC,MAAM,CAC1BE,YAAY,CAAElB,KAAK,CAACmB,MAAM,CAC1BC,OAAO,CAAEpB,KAAK,CAACe,GAAG,CAACC,MAAM,CACzBK,OAAO,CAAErB,KAAK,CAACmB,MAAM,CACrBG,MAAM,CAAEtB,KAAK,CAACuB,IAAI,CAClBC,QAAQ,CAAExB,KAAK,CAACyB,KAAK,CACrBC,WAAW,CAAE1B,KAAK,CAAC2B,GAAG,CAAC,SAAS,CAAC,CACjCC,WAAW,CAAE5B,KAAK,CAACa,KAAK,CAACE,GAC3B,CAAC,CAWD,QAAS,CAAAc,YAAYA,CAACC,MAA8B,CAAmC,IAAjC,CAAAC,YAA0B,CAAAC,SAAA,CAAAC,MAAA,IAAAD,SAAA,MAAAE,SAAA,CAAAF,SAAA,IAAG,CAAC,CAAC,CACnFD,YAAY,CAACvB,MAAM,GAAK,IAAI,CAE5B,KAAM,CAAA2B,QAAQ,CAAG,GAAI,CAAAC,KAAK,CAAC5B,MAAM,CAAE,CACjC6B,GAAG,CAAEA,CAAA,GAAM,CACT,MA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,CAAC,GAAG,CAAC,CAAC,CAEjGtB,OAAO,CACLH,MAAM,CAAC,CAAC,CAAC,CACTwC,CAAC,CAACnB,QAAQ,CAACwD,KAAK,CAAC,CACjB7E,MAAM,CAAC4F,OAAO,CAAC,CACfpD,CAAC,CAAC/B,WAAW,CAACiE,aAAa,CAAC,CAC5BiB,GAAG,CAAGnD,CAAC,CAAC7B,OAAO,CAACgF,GAAG,CAAC,CAAGnD,CAAC,CAAC1B,QAAQ,CAACA,QAAQ,CAC5C,CAAC,CAED,GAAIG,OAAO,CAAE,CACX,KAAM,CAAAkD,gBAAgB,CAAGlD,OAAO,CAACmD,OAAO,CAAC,KAAK,CAAE,IAAI,CAAGpE,MAAM,CAACsD,OAAO,CAAG,EAAE,CAAC,CAAC,CAC5EnD,OAAO,CAACH,MAAM,CAACsD,OAAO,CAAG,CAAC,CAAC,CAAEd,CAAC,CAACf,WAAW,CAAC,GAAG,CAAC,CAAGe,CAAC,CAACzB,YAAY,CAAC,UAAU,CAAC,CAAEyB,CAAC,CAACvB,OAAO,CAACkD,gBAAgB,CAAC,CAAC,CAC5G,CACF,CAEAhE,OAAO,CAAC,CAAC,CACX,CAEA,MAAO,MAAM,CAAA4F,IAAI,CAAG,CAClBrE,YAAY,CACZ2C,mBACF,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["chalk","concat","getDefaultValueFromSchema","indent","ln","print","println","transformOptionToArg","colors","title","bold","blue","description","white","default","dim","italic","optional","exampleTitle","yellow","example","command","option","cyan","argument","green","placeholder","hex","punctuation","printCliHelp","params","printOptions","arguments","length","undefined","noColors","Proxy","get","_len","str","Array","_key","join","c","customColors","Object","assign","isFirstParamCli","cliOptions","shift","subcommands","printTitle","toUpperCase","cliName","usage","options","allowPositional","longest","optionsToPrint","longestOptionIndent","prepareOptionsToPrint","commandsToPrint","longestSubcommandIndent","prepareCommandsToPrint","argsToPrint","longestArgIndent","prepareArgumentsToPrint","printPreparedOptions","printPreparedCommands","printPreparedArguments","normalizeExample","replace","printSubcommandHelp","subcommand","_len2","_key2","name","normalizeDesc","nameWithAliases","aliases","names","from","Set","map","defaultValue","type","push","JSON","stringify","isOptional","optLength","cmdLength","args","arg","def","spacing","coloredNames","split","help"],"sourceRoot":"../../src","sources":["help.ts"],"sourcesContent":["import chalk from \"chalk\";\nimport { concat, getDefaultValueFromSchema, indent, ln, print, println, transformOptionToArg } from \"./utils.js\";\n\nimport type { Argument, Cli, Option, PrintHelpOpt, Subcommand } from \"./types.js\";\n\nconst colors: NonNullable<Required<PrintHelpOpt[\"customColors\"]>> = {\n title: chalk.bold.blue,\n description: chalk.white,\n default: chalk.dim.italic,\n optional: chalk.dim.italic,\n exampleTitle: chalk.yellow,\n example: chalk.dim,\n command: chalk.yellow,\n option: chalk.cyan,\n argument: chalk.green,\n placeholder: chalk.hex(\"#FF9800\"),\n punctuation: chalk.white.dim,\n};\n\ntype PreparedToPrint = {\n names: string;\n description: string;\n placeholder?: string;\n example?: string;\n default?: string;\n optional?: string;\n};\n\nfunction printCliHelp(params: [Cli, ...Subcommand[]], printOptions: PrintHelpOpt = {}) {\n printOptions.colors ??= true;\n\n const noColors = new Proxy(colors, {\n get: () => {\n return (...str: string[]) => str.join(\" \");\n },\n });\n\n const c = printOptions.colors ? colors : noColors;\n\n if (printOptions.customColors) {\n Object.assign(c, printOptions.customColors);\n }\n\n const isFirstParamCli = \"cliName\" in params[0];\n const cliOptions = (isFirstParamCli ? params.shift() : {}) as Cli;\n const subcommands = params as Subcommand[];\n\n /** Print a styled title */\n const printTitle = (title: string) => {\n print(c.title(` ${title.toUpperCase()} `));\n };\n\n // Print CLI usage\n const cliName = cliOptions.cliName ?? \"\";\n const usage =\n cliOptions.usage ??\n concat(\n c.punctuation(\"$\"),\n cliName,\n subcommands.length ? c.command(\"[command]\") : \"\",\n cliOptions.options?.length ? c.option(\"[options]\") : \"\",\n cliOptions.arguments?.length || cliOptions.allowPositional ? c.argument(\"<arguments>\") : \"\",\n );\n printTitle(\"Usage\");\n println();\n println(indent(2), usage, ln(1));\n\n // Print CLI description\n if (cliOptions.description) {\n printTitle(\"Description\");\n println();\n println(indent(2), c.description(cliOptions.description), ln(1));\n }\n\n let longest = 0;\n\n // Prepare CLI options\n const [optionsToPrint, longestOptionIndent] = prepareOptionsToPrint(cliOptions.options);\n if (longestOptionIndent > longest) longest = longestOptionIndent;\n\n // Prepare CLI commands\n const [commandsToPrint, longestSubcommandIndent] = prepareCommandsToPrint(subcommands);\n if (longestSubcommandIndent > longest) longest = longestSubcommandIndent;\n\n // Prepare CLI arguments\n const [argsToPrint, longestArgIndent] = prepareArgumentsToPrint(cliOptions.arguments);\n if (longestArgIndent > longest) longest = longestArgIndent;\n\n // Print CLI options\n printPreparedOptions(optionsToPrint, c, longest);\n\n // Print CLI commands\n printPreparedCommands(commandsToPrint, c, longest);\n\n // Print CLI arguments\n printPreparedArguments(argsToPrint, c, longest);\n\n // Print CLI example\n if (cliOptions.example) {\n printTitle(\"Example\");\n println();\n const normalizeExample = cliOptions.example.replace(/\\n/g, \"\\n\" + indent(3));\n println(indent(2), c.example(normalizeExample), ln(1));\n }\n}\n\nfunction printSubcommandHelp(subcommand: Subcommand, printOptions: PrintHelpOpt = {}, cliName = \"\") {\n printOptions.colors ??= true;\n\n const noColors = new Proxy(colors, {\n get: () => {\n return (...str: string[]) => str.join(\" \");\n },\n });\n\n const c = printOptions.colors ? colors : noColors;\n\n if (printOptions.customColors) {\n Object.assign(c, printOptions.customColors);\n }\n\n /** Print a styled title */\n const printTitle = (title: string) => {\n print(c.title(` ${title.toUpperCase()} `));\n };\n\n // Print command usage\n const usage =\n subcommand.usage ??\n concat(\n c.punctuation(\"$\"),\n cliName,\n c.command(subcommand.name),\n subcommand.options?.length ? c.option(\"[options]\") : \"\",\n subcommand.arguments?.length || subcommand.allowPositional ? c.argument(\"<arguments>\") : \"\",\n );\n printTitle(\"Usage\");\n println();\n println(indent(2), usage, ln(1));\n\n // Print command description\n if (subcommand.description) {\n printTitle(\"Description\");\n println();\n const normalizeDesc = subcommand.description.replace(/\\n/g, \"\\n\" + indent(3));\n println(indent(2), c.description(normalizeDesc), ln(1));\n }\n\n let longest = 0;\n\n // Prepare command options\n const [optionsToPrint, longestOptionIndent] = prepareOptionsToPrint(subcommand.options);\n if (longestOptionIndent > longest) longest = longestOptionIndent;\n\n // Prepare command arguments\n const [argsToPrint, longestArgIndent] = prepareArgumentsToPrint(subcommand.arguments);\n if (longestArgIndent > longest) longest = longestArgIndent;\n\n // Print command options\n printPreparedOptions(optionsToPrint, c, longest);\n\n // Print command arguments\n printPreparedArguments(argsToPrint, c, longest);\n\n // Print command example\n if (subcommand.example) {\n printTitle(\"Example\");\n println();\n const normalizeExample = subcommand.example.replace(/\\n/g, \"\\n\" + indent(3));\n println(indent(2), c.example(normalizeExample), ln(1));\n }\n}\n\n// * Prepare\nfunction prepareOptionsToPrint(options: Option[] | undefined): [PreparedToPrint[], number] {\n if (!options || !options.length) return [[], 0];\n\n const optionsToPrint: PreparedToPrint[] = [];\n let longest = 0;\n\n for (const option of options) {\n const nameWithAliases = option.aliases ? [...option.aliases, option.name] : [option.name];\n const names = Array.from(new Set(nameWithAliases.map(name => transformOptionToArg(name)))).join(\", \");\n\n const defaultValue = getDefaultValueFromSchema(option.type);\n\n const placeholder = option.placeholder ?? \" \";\n optionsToPrint.push({\n names,\n placeholder,\n description: option.description ?? option.type.description ?? \"\",\n default: typeof defaultValue !== \"undefined\" ? `(default: ${JSON.stringify(defaultValue)})` : \"\",\n optional: option.type.isOptional() ? \"[optional]\" : \"\",\n example: option.example ?? \"\",\n });\n\n const optLength = names.length + placeholder.length;\n\n if (optLength > longest) longest = optLength;\n }\n\n return [optionsToPrint, longest];\n}\n\nfunction prepareCommandsToPrint(subcommands: Subcommand[] | undefined): [PreparedToPrint[], number] {\n if (!subcommands || !subcommands.length) return [[], 0];\n\n const commandsToPrint: PreparedToPrint[] = [];\n let longest = 0;\n\n for (const subcommand of subcommands) {\n const { name, aliases, description } = subcommand;\n const names = Array.from(new Set([...(aliases ?? []), name])).join(\", \");\n\n const placeholder =\n subcommand.placeholder ?? (subcommand.options ? \"[options]\" : subcommand.allowPositional ? \"<args>\" : \" \");\n\n commandsToPrint.push({ names, placeholder, description: description ?? \"\" });\n\n const cmdLength = names.length + placeholder.length;\n if (cmdLength > longest) longest = cmdLength;\n }\n\n return [commandsToPrint, longest];\n}\n\nfunction prepareArgumentsToPrint(args: Argument[] | undefined): [PreparedToPrint[], number] {\n if (!args || !args.length) return [[], 0];\n\n const argsToPrint: PreparedToPrint[] = [];\n let longest = 0;\n\n for (const arg of args) {\n const defaultValue = getDefaultValueFromSchema(arg.type);\n\n argsToPrint.push({\n names: arg.name,\n description: arg.description ?? \"\",\n default: typeof defaultValue !== \"undefined\" ? `(default: ${JSON.stringify(defaultValue)})` : \"\",\n optional: arg.type.isOptional() ? \"[optional]\" : \"\",\n example: arg.example ?? \"\",\n });\n\n const cmdLength = arg.name.length;\n if (cmdLength > longest) longest = cmdLength;\n }\n\n return [argsToPrint, longest];\n}\n\n// * Print\nfunction printPreparedOptions(optionsToPrint: PreparedToPrint[], c: typeof colors, longest: number) {\n if (!optionsToPrint.length) return;\n\n print(c.title(\" OPTIONS \"));\n\n println();\n\n for (const { names, placeholder, description, example, optional, default: def } of optionsToPrint) {\n const optLength = names.length + (placeholder?.length ?? 0);\n const spacing = longest + 1 - optLength;\n const normalizeDesc = description.replace(/\\n/g, \"\\n\" + indent(longest + 7) + c.punctuation(\"└\"));\n\n const coloredNames = names\n .split(/(,)/)\n .map(name => (name === \",\" ? c.punctuation(name) : c.option(name)))\n .join(\"\");\n\n println(\n indent(2),\n coloredNames,\n c.placeholder(placeholder),\n indent(spacing),\n c.description(normalizeDesc),\n def ? c.default(def) : c.optional(optional),\n );\n\n if (example) {\n const normalizeExample = example.replace(/\\n/g, \"\\n\" + indent(longest + 17));\n println(indent(longest + 6), c.punctuation(\"└\") + c.exampleTitle(\"Example:\"), c.example(normalizeExample));\n }\n }\n\n println();\n}\n\nfunction printPreparedCommands(commandsToPrint: PreparedToPrint[], c: typeof colors, longest: number) {\n if (!commandsToPrint.length) return;\n\n print(c.title(\" COMMANDS \"));\n\n println();\n\n for (const { names, placeholder, description } of commandsToPrint) {\n const optLength = names.length + (placeholder?.length ?? 0);\n const spacing = longest + 1 - optLength;\n const normalizeDesc = description.replace(/\\n/g, \"\\n\" + indent(longest + 7) + c.punctuation(\"└\"));\n\n const coloredNames = names\n .split(/(,)/)\n .map(name => (name === \",\" ? c.punctuation(name) : c.command(name)))\n .join(\"\");\n\n println(indent(2), coloredNames, c.placeholder(placeholder), indent(spacing), c.description(normalizeDesc));\n }\n\n println();\n}\n\nfunction printPreparedArguments(argsToPrint: PreparedToPrint[], c: typeof colors, longest: number) {\n if (!argsToPrint.length) return;\n\n print(c.title(\" ARGUMENTS \"));\n\n println();\n\n for (const { names, description, example, optional, default: def } of argsToPrint) {\n const spacing = longest + 2 - names.length;\n const normalizeDesc = description.replace(/\\n/g, \"\\n\" + indent(longest + 6) + c.punctuation(\"└\"));\n\n println(\n indent(2),\n c.argument(names),\n indent(spacing),\n c.description(normalizeDesc),\n def ? c.default(def) : c.optional(optional),\n );\n\n if (example) {\n const normalizeExample = example.replace(/\\n/g, \"\\n\" + indent(longest + 16));\n println(indent(longest + 5), c.punctuation(\"└\") + c.exampleTitle(\"Example:\"), c.example(normalizeExample));\n }\n }\n\n println();\n}\n\nexport const help = {\n printCliHelp,\n printSubcommandHelp,\n};\n"],"mappings":"AAAA,MAAO,CAAAA,KAAK,KAAM,OAAO,CACzB,OAASC,MAAM,CAAEC,yBAAyB,CAAEC,MAAM,CAAEC,EAAE,CAAEC,KAAK,CAAEC,OAAO,CAAEC,oBAAoB,KAAQ,YAAY,CAIhH,KAAM,CAAAC,MAA2D,CAAG,CAClEC,KAAK,CAAET,KAAK,CAACU,IAAI,CAACC,IAAI,CACtBC,WAAW,CAAEZ,KAAK,CAACa,KAAK,CACxBC,OAAO,CAAEd,KAAK,CAACe,GAAG,CAAC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AC,CAC5EnD,OAAO,CAACH,MAAM,CAACsD,OAAO,CAAG,CAAC,CAAC,CAAEd,CAAC,CAACf,WAAW,CAAC,GAAG,CAAC,CAAGe,CAAC,CAACzB,YAAY,CAAC,UAAU,CAAC,CAAEyB,CAAC,CAACvB,OAAO,CAACkD,gBAAgB,CAAC,CAAC,CAC5G,CACF,CAEAhE,OAAO,CAAC,CAAC,CACX,CAEA,MAAO,MAAM,CAAA4F,IAAI,CAAG,CAClBrE,YAAY,CACZ2C,mBACF,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- import{help}from"./help.js";import{parse,safeParse}from"./parser.js";function createSubcommand(input){return Object.assign(input,{setAction:action=>input.action=action});}function createCli(input){return Object.assign(input,{setAction:action=>input.action=action});}const{printCliHelp,printSubcommandHelp}=help;export{createCli,createSubcommand,parse,printCliHelp,printSubcommandHelp,safeParse};
1
+ import{help}from"./help.js";import{parse,safeParse}from"./parser.js";function createSubcommand(input){return Object.assign(input,{setAction:action=>input.action=action});}function createCli(input){return Object.assign(input,{setAction:action=>input.action=action});}function createOptions(options){return options;}const{printCliHelp,printSubcommandHelp}=help;export{createCli,createSubcommand,createOptions,parse,printCliHelp,printSubcommandHelp,safeParse};
@@ -1 +1 @@
1
- {"version":3,"names":["help","parse","safeParse","createSubcommand","input","Object","assign","setAction","action","createCli","printCliHelp","printSubcommandHelp"],"sourceRoot":"../../src","sources":["index.ts"],"sourcesContent":["import { help } from \"./help.js\";\nimport { parse, safeParse } from \"./parser.js\";\n\nimport type { ActionFn, Cli, Prettify, Subcommand, UnSafeParseResult } from \"./types.js\";\n\nfunction createSubcommand<const T extends Subcommand>(input: T & Subcommand): Prettify<T & ActionFn<T>> {\n return Object.assign(input, {\n setAction: (action: (res: UnSafeParseResult<[T]>) => void) => (input.action = action),\n });\n}\n\nfunction createCli<const T extends Cli>(input: T & Cli): Prettify<T & ActionFn<T>> {\n return Object.assign(input, {\n setAction: (action: (res: UnSafeParseResult<[T]>) => void) => (input.action = action),\n });\n}\n\nconst { printCliHelp, printSubcommandHelp } = help;\n\nexport { createCli, createSubcommand, parse, printCliHelp, printSubcommandHelp, safeParse };\n\nexport type * from \"./types.js\";\n"],"mappings":"AAAA,OAASA,IAAI,KAAQ,WAAW,CAChC,OAASC,KAAK,CAAEC,SAAS,KAAQ,aAAa,CAI9C,QAAS,CAAAC,gBAAgBA,CAA6BC,KAAqB,CAA6B,CACtG,MAAO,CAAAC,MAAM,CAACC,MAAM,CAACF,KAAK,CAAE,CAC1BG,SAAS,CAAGC,MAA6C,EAAMJ,KAAK,CAACI,MAAM,CAAGA,MAChF,CAAC,CAAC,CACJ,CAEA,QAAS,CAAAC,SAASA,CAAsBL,KAAc,CAA6B,CACjF,MAAO,CAAAC,MAAM,CAACC,MAAM,CAACF,KAAK,CAAE,CAC1BG,SAAS,CAAGC,MAA6C,EAAMJ,KAAK,CAACI,MAAM,CAAGA,MAChF,CAAC,CAAC,CACJ,CAEA,KAAM,CAAEE,YAAY,CAAEC,mBAAoB,CAAC,CAAGX,IAAI,CAElD,OAASS,SAAS,CAAEN,gBAAgB,CAAEF,KAAK,CAAES,YAAY,CAAEC,mBAAmB,CAAET,SAAS","ignoreList":[]}
1
+ {"version":3,"names":["help","parse","safeParse","createSubcommand","input","Object","assign","setAction","action","createCli","createOptions","options","printCliHelp","printSubcommandHelp"],"sourceRoot":"../../src","sources":["index.ts"],"sourcesContent":["import { help } from \"./help.js\";\nimport { parse, safeParse } from \"./parser.js\";\n\nimport type {\n ActionFn,\n CheckDuplicatedOptions,\n Cli,\n Option,\n Prettify,\n Subcommand,\n UnSafeParseResult,\n} from \"./types.js\";\n\nfunction createSubcommand<const T extends Subcommand>(input: CheckDuplicatedOptions<T>): Prettify<T & ActionFn<T>> {\n return Object.assign(input, {\n setAction: (action: (res: UnSafeParseResult<[T]>) => void) => (input.action = action),\n });\n}\n\nfunction createCli<const T extends Cli>(input: CheckDuplicatedOptions<T>): Prettify<T & ActionFn<T>> {\n return Object.assign(input, {\n setAction: (action: (res: UnSafeParseResult<[T]>) => void) => (input.action = action),\n });\n}\n\nfunction createOptions<const T extends [Option, ...Option[]]>(options: T): T {\n return options;\n}\n\nconst { printCliHelp, printSubcommandHelp } = help;\n\nexport { createCli, createSubcommand, createOptions, parse, printCliHelp, printSubcommandHelp, safeParse };\n\nexport type * from \"./types.js\";\n"],"mappings":"AAAA,OAASA,IAAI,KAAQ,WAAW,CAChC,OAASC,KAAK,CAAEC,SAAS,KAAQ,aAAa,CAY9C,QAAS,CAAAC,gBAAgBA,CAA6BC,KAAgC,CAA6B,CACjH,MAAO,CAAAC,MAAM,CAACC,MAAM,CAACF,KAAK,CAAE,CAC1BG,SAAS,CAAGC,MAA6C,EAAMJ,KAAK,CAACI,MAAM,CAAGA,MAChF,CAAC,CAAC,CACJ,CAEA,QAAS,CAAAC,SAASA,CAAsBL,KAAgC,CAA6B,CACnG,MAAO,CAAAC,MAAM,CAACC,MAAM,CAACF,KAAK,CAAE,CAC1BG,SAAS,CAAGC,MAA6C,EAAMJ,KAAK,CAACI,MAAM,CAAGA,MAChF,CAAC,CAAC,CACJ,CAEA,QAAS,CAAAE,aAAaA,CAAwCC,OAAU,CAAK,CAC3E,MAAO,CAAAA,OAAO,CAChB,CAEA,KAAM,CAAEC,YAAY,CAAEC,mBAAoB,CAAC,CAAGb,IAAI,CAElD,OAASS,SAAS,CAAEN,gBAAgB,CAAEO,aAAa,CAAET,KAAK,CAAEW,YAAY,CAAEC,mBAAmB,CAAEX,SAAS","ignoreList":[]}
@@ -1 +1 @@
1
- import{help}from"./help.js";import{decoupleFlags,getOrdinalPlacement,isBooleanSchema,isFlagArg,isOptionArg,noName,stringToBoolean,transformArg,transformOptionToArg}from"./utils.js";export function parse(argsv){for(var _len=arguments.length,params=new Array(_len>1?_len-1:0),_key=1;_key<_len;_key++){params[_key-1]=arguments[_key];}const cliOptions="cliName"in params[0]?params[0]:{};const subcommandArr=params;const allSubcommands=new Set(subcommandArr.flatMap(c=>[c.name,...(c.aliases||[])]));argsv=decoupleFlags(argsv);const results={subcommand:undefined,printCliHelp(opt){help.printCliHelp(params,opt);},printSubcommandHelp(subcommandStr,opt){const subcommand=subcommandArr.find(c=>c.name===subcommandStr);if(!subcommand)return console.error(`Cannot print help for subcommand "${subcommandStr}" as it does not exist`);help.printSubcommandHelp(subcommand,opt,cliOptions.cliName);}};const addRawArg=(optionName,rawArg)=>{if(!results._info)results._info={};if(!results._info[optionName])results._info[optionName]=Object.create({});results._info[optionName].rawArg=rawArg;};const addRawValue=(optionName,rawValue)=>{if(!results._info)results._info={};if(!results._info[optionName])results._info[optionName]=Object.create({});results._info[optionName].rawValue=rawValue;};const addSource=(optionName,source)=>{if(!results._info)results._info={};if(!results._info[optionName])results._info[optionName]=Object.create({});results._info[optionName].source=source;};const fillOption=(optionName,value)=>{if(!results._info)results._info={};if(!results._info[optionName])results._info[optionName]=Object.create({});Object.assign(results._info[optionName],value);};for(let i=0;i<argsv.length;i++){const arg=argsv[i];if(i===0){results.subcommand=allSubcommands.has(arg)?arg:undefined;const subcommandProps=subcommandArr.find(c=>c.name===results.subcommand);if(subcommandProps?.allowPositional)results.positional=[];if(subcommandProps?.arguments?.length)results.arguments=[];if(results.subcommand)continue;}const argAndValue=arg.split("=").filter(Boolean);const argWithEquals=arg.includes("=");const argument=argAndValue[0];const argValue=argAndValue[1];if(isOptionArg(argument)){if(isFlagArg(argument)&&argWithEquals){throw new Error(`Flag arguments cannot be assigned using "=": "${arg}"`);}const subcommandProps=subcommandArr.find(c=>c.name===results.subcommand);if(!subcommandProps)throw new Error(`Unknown subcommand: "${results.subcommand}"`);if(!subcommandProps.options){const msg=!results.subcommand?"options are not allowed here":`subcommand "${results.subcommand}" does not allow options`;throw new Error(`Error: ${msg}: "${argument}"`);}const optionName=transformArg(argument);if(optionName in results)throw new Error(`Duplicate option: "${argument}"`);const isNegative=argument.startsWith("--no-");const option=subcommandProps.options.find(o=>{if(o.name===optionName)return true;if(isNegative&&noName(o.name)===optionName)return true;if(!o.aliases)return false;if(o.aliases.includes(optionName))return true;if(isNegative&&o.aliases.map(noName).includes(optionName))return true;return false;});if(!option){throw new Error(`Unknown option: "${argument}"`);}const isTypeBoolean=isBooleanSchema(option.type);const nextArg=argsv[i+1];let optionValue=argWithEquals?argValue:nextArg;if(isTypeBoolean){if(argWithEquals){const parsedBoolean=stringToBoolean(argValue);optionValue=isNegative?!parsedBoolean:parsedBoolean;}else{optionValue=!isNegative;}}if(typeof optionValue==="undefined"){throw new Error(`Expected a value for "${argument}" but got nothing`);}if(!argWithEquals&&isOptionArg(optionValue)){throw new Error(`Expected a value for "${argument}" but got an argument "${nextArg}"`);}const res=option.type.safeParse(optionValue);if(!res.success){throw new Error(`Invalid value "${optionValue}" for "${argument}": ${res.error.errors[0].message}`);}results[option.name]=res.data;addRawArg(option.name,argument);const rawVal=argWithEquals?argValue:isTypeBoolean?"":nextArg;addRawValue(option.name,rawVal);fillOption(option.name,option);if(!argWithEquals&&!isTypeBoolean)i++;continue;}const subcommandProps=subcommandArr.find(c=>c.name===results.subcommand);if(subcommandProps?.arguments?.length){if(!results.arguments)results.arguments=[];const currentArgCount=results.arguments.length;if(currentArgCount<subcommandProps.arguments.length){const argType=subcommandProps.arguments[currentArgCount].type;let argValue=arg;const isTypeBoolean=isBooleanSchema(argType);if(isTypeBoolean)argValue=stringToBoolean(argValue);const res=argType.safeParse(argValue);if(!res.success){throw new Error(`The ${getOrdinalPlacement(currentArgCount)} argument "${arg}" is invalid: ${res.error.errors[0].message}`);}results.arguments.push(res.data);continue;}}if(subcommandProps?.allowPositional){if(!results.positional)results.positional=[];results.positional.push(arg);continue;}const msg=!results.subcommand?"here":`for subcommand "${results.subcommand}"`;throw new Error(`Unexpected argument "${arg}": positional arguments are not allowed ${msg}`);}const subcommandProps=subcommandArr.find(c=>c.name===results.subcommand);if(subcommandProps?.options?.length){for(const option of subcommandProps.options){if(option.name in results){addSource(option.name,"cli");fillOption(option.name,option);continue;}if(option.type.isOptional()){const hasDefault=typeof option.type._def.defaultValue==="function";if(!hasDefault)continue;results[option.name]=option.type._def.defaultValue();addSource(option.name,"default");fillOption(option.name,option);continue;}throw new Error(`Missing required option: ${transformOptionToArg(option.name)}`);}}if(subcommandProps?.arguments?.length){const currentArgCount=results.arguments?.length??0;const subcommandArgCount=subcommandProps.arguments.length;if(currentArgCount<subcommandArgCount){for(let i=currentArgCount;i<subcommandArgCount;i++){const argumentType=subcommandProps.arguments[i].type;const hasDefault=typeof argumentType._def.defaultValue==="function";if(hasDefault&&results.arguments){results.arguments.push(argumentType._def.defaultValue());continue;}if(argumentType.isOptional())continue;throw new Error(`the ${getOrdinalPlacement(i)} argument is required: "${subcommandProps.arguments[i].name}"`);}}}if(subcommandProps?.action){subcommandProps.action(results);}return results;}export function safeParse(argsv){for(var _len2=arguments.length,params=new Array(_len2>1?_len2-1:0),_key2=1;_key2<_len2;_key2++){params[_key2-1]=arguments[_key2];}const cliOptions="cliName"in params[0]?params[0]:{};const subcommandArr=params;const printCliHelp=opt=>help.printCliHelp(params,opt);const printSubcommandHelp=(subcommandStr,opt)=>{const subcommand=subcommandArr.find(c=>c.name===subcommandStr);if(!subcommand)return console.error(`Cannot print help for subcommand "${subcommandStr}" as it does not exist`);help.printSubcommandHelp(subcommand,opt,cliOptions.cliName);};try{const data=parse(argsv,...params);delete data.printCliHelp;delete data.printSubcommandHelp;return{success:true,data:data,printCliHelp,printSubcommandHelp};}catch(e){return{success:false,error:e,printCliHelp,printSubcommandHelp};}}
1
+ import{help}from"./help.js";import{decoupleFlags,getOrdinalPlacement,isBooleanSchema,isFlagArg,isOptionArg,noName,stringToBoolean,transformArg,transformOptionToArg}from"./utils.js";export function parse(argsv){for(var _len=arguments.length,params=new Array(_len>1?_len-1:0),_key=1;_key<_len;_key++){params[_key-1]=arguments[_key];}const cliOptions="cliName"in params[0]?params[0]:{};const subcommandArr=params;const allSubcommands=new Set(subcommandArr.flatMap(c=>[c.name,...(c.aliases||[])]));argsv=decoupleFlags(argsv);const results={subcommand:undefined,printCliHelp(opt){help.printCliHelp(params,opt);},printSubcommandHelp(subcommandStr,opt){const subcommand=subcommandArr.find(c=>{if(c.name===subcommandStr)return true;if(!subcommandStr)return false;if(!c.aliases?.length)return false;return c.aliases.includes(subcommandStr);});if(!subcommand)return console.error(`Cannot print help for subcommand "${subcommandStr}" as it does not exist`);help.printSubcommandHelp(subcommand,opt,cliOptions.cliName);}};const GetSubcommandProps=function(){let cmd=arguments.length>0&&arguments[0]!==undefined?arguments[0]:results.subcommand;return subcommandArr.find(c=>{if(c.name===cmd)return true;if(!cmd)return false;if(!c.aliases?.length)return false;return c.aliases.includes(cmd);});};const addRawArg=(optionName,rawArg)=>{if(!results._info)results._info={};if(!results._info[optionName])results._info[optionName]=Object.create({});results._info[optionName].rawArg=rawArg;};const addRawValue=(optionName,rawValue)=>{if(!results._info)results._info={};if(!results._info[optionName])results._info[optionName]=Object.create({});results._info[optionName].rawValue=rawValue;};const addSource=(optionName,source)=>{if(!results._info)results._info={};if(!results._info[optionName])results._info[optionName]=Object.create({});results._info[optionName].source=source;};const fillOption=(optionName,value)=>{if(!results._info)results._info={};if(!results._info[optionName])results._info[optionName]=Object.create({});Object.assign(results._info[optionName],value);};for(let i=0;i<argsv.length;i++){const arg=argsv[i];if(i===0){results.subcommand=allSubcommands.has(arg)?arg:undefined;const subcommandProps=GetSubcommandProps();if(subcommandProps?.allowPositional)results.positional=[];if(subcommandProps?.arguments?.length)results.arguments=[];if(results.subcommand)continue;}const argAndValue=arg.split("=").filter(Boolean);const argWithEquals=arg.includes("=");const argument=argAndValue[0];const argValue=argAndValue[1];if(isOptionArg(argument)){if(isFlagArg(argument)&&argWithEquals){throw new Error(`Flag arguments cannot be assigned using "=": "${arg}"`);}const subcommandProps=GetSubcommandProps();if(!subcommandProps)throw new Error(`Unknown subcommand: "${results.subcommand}"`);if(!subcommandProps.options){const msg=!results.subcommand?"options are not allowed here":`subcommand "${results.subcommand}" does not allow options`;throw new Error(`Error: ${msg}: "${argument}"`);}const optionName=transformArg(argument);const isNegative=argument.startsWith("--no-");const option=subcommandProps.options.find(o=>{if(o.name===optionName)return true;if(isNegative&&noName(o.name)===optionName)return true;if(!o.aliases)return false;if(o.aliases.includes(optionName))return true;if(isNegative&&o.aliases.map(noName).includes(optionName))return true;return false;});if(!option){throw new Error(`Unknown option: "${argument}"`);}if(option.name in results){throw new Error(`Duplicated option: "${argument}"`);}const isTypeBoolean=isBooleanSchema(option.type);const nextArg=argsv[i+1];let optionValue=argWithEquals?argValue:nextArg;if(isTypeBoolean){if(argWithEquals){const parsedBoolean=stringToBoolean(argValue);optionValue=isNegative?!parsedBoolean:parsedBoolean;}else{optionValue=!isNegative;}}if(typeof optionValue==="undefined"){throw new Error(`Expected a value for "${argument}" but got nothing`);}if(!argWithEquals&&isOptionArg(optionValue)){throw new Error(`Expected a value for "${argument}" but got an argument "${nextArg}"`);}const res=option.type.safeParse(optionValue);if(!res.success){throw new Error(`Invalid value "${optionValue}" for "${argument}": ${res.error.errors[0].message}`);}results[option.name]=res.data;addRawArg(option.name,argument);const rawVal=argWithEquals?argValue:isTypeBoolean?"":nextArg;addRawValue(option.name,rawVal);fillOption(option.name,option);if(!argWithEquals&&!isTypeBoolean)i++;continue;}const subcommandProps=GetSubcommandProps();if(subcommandProps?.arguments?.length){if(!results.arguments)results.arguments=[];const currentArgCount=results.arguments.length;if(currentArgCount<subcommandProps.arguments.length){const argType=subcommandProps.arguments[currentArgCount].type;let argValue=arg;const isTypeBoolean=isBooleanSchema(argType);if(isTypeBoolean)argValue=stringToBoolean(argValue);const res=argType.safeParse(argValue);if(!res.success){throw new Error(`The ${getOrdinalPlacement(currentArgCount)} argument "${arg}" is invalid: ${res.error.errors[0].message}`);}results.arguments.push(res.data);continue;}}if(subcommandProps?.allowPositional){if(!results.positional)results.positional=[];results.positional.push(arg);continue;}const msg=!results.subcommand?"here":`for subcommand "${results.subcommand}"`;throw new Error(`Unexpected argument "${arg}": positional arguments are not allowed ${msg}`);}const subcommandProps=GetSubcommandProps();if(subcommandProps?.options?.length){for(const option of subcommandProps.options){if(option.name in results){addSource(option.name,"cli");fillOption(option.name,option);continue;}if(option.type.isOptional()){const hasDefault=typeof option.type._def.defaultValue==="function";if(!hasDefault)continue;results[option.name]=option.type._def.defaultValue();addSource(option.name,"default");fillOption(option.name,option);continue;}throw new Error(`Missing required option: ${transformOptionToArg(option.name)}`);}}if(subcommandProps?.arguments?.length){const currentArgCount=results.arguments?.length??0;const subcommandArgCount=subcommandProps.arguments.length;if(currentArgCount<subcommandArgCount){for(let i=currentArgCount;i<subcommandArgCount;i++){const argumentType=subcommandProps.arguments[i].type;const hasDefault=typeof argumentType._def.defaultValue==="function";if(hasDefault&&results.arguments){results.arguments.push(argumentType._def.defaultValue());continue;}if(argumentType.isOptional())continue;throw new Error(`the ${getOrdinalPlacement(i)} argument is required: "${subcommandProps.arguments[i].name}"`);}}}if(subcommandProps?.action){subcommandProps.action(results);}return results;}export function safeParse(argsv){for(var _len2=arguments.length,params=new Array(_len2>1?_len2-1:0),_key2=1;_key2<_len2;_key2++){params[_key2-1]=arguments[_key2];}const cliOptions="cliName"in params[0]?params[0]:{};const subcommandArr=params;const printCliHelp=opt=>help.printCliHelp(params,opt);const printSubcommandHelp=(subcommandStr,opt)=>{const subcommand=subcommandArr.find(c=>c.name===subcommandStr);if(!subcommand)return console.error(`Cannot print help for subcommand "${subcommandStr}" as it does not exist`);help.printSubcommandHelp(subcommand,opt,cliOptions.cliName);};try{const data=parse(argsv,...params);delete data.printCliHelp;delete data.printSubcommandHelp;return{success:true,data:data,printCliHelp,printSubcommandHelp};}catch(e){return{success:false,error:e,printCliHelp,printSubcommandHelp};}}
@@ -1 +1 @@
1
- {"version":3,"names":["help","decoupleFlags","getOrdinalPlacement","isBooleanSchema","isFlagArg","isOptionArg","noName","stringToBoolean","transformArg","transformOptionToArg","parse","argsv","_len","arguments","length","params","Array","_key","cliOptions","subcommandArr","allSubcommands","Set","flatMap","c","name","aliases","results","subcommand","undefined","printCliHelp","opt","printSubcommandHelp","subcommandStr","find","console","error","cliName","addRawArg","optionName","rawArg","_info","Object","create","addRawValue","rawValue","addSource","source","fillOption","value","assign","i","arg","has","subcommandProps","allowPositional","positional","argAndValue","split","filter","Boolean","argWithEquals","includes","argument","argValue","Error","options","msg","isNegative","startsWith","option","o","map","isTypeBoolean","type","nextArg","optionValue","parsedBoolean","res","safeParse","success","errors","message","data","rawVal","currentArgCount","argType","push","isOptional","hasDefault","_def","defaultValue","subcommandArgCount","argumentType","action","_len2","_key2","e"],"sourceRoot":"../../src","sources":["parser.ts"],"sourcesContent":["import { help } from \"./help.js\";\nimport {\n decoupleFlags,\n getOrdinalPlacement,\n isBooleanSchema,\n isFlagArg,\n isOptionArg,\n noName,\n stringToBoolean,\n transformArg,\n transformOptionToArg,\n} from \"./utils.js\";\n\nimport type {\n Cli,\n NoSubcommand,\n Option,\n PrintHelpOpt,\n SafeParseResult,\n Subcommand,\n UnSafeParseResult,\n} from \"./types.js\";\n\nexport function parse<T extends Subcommand[]>(argsv: string[], ...params: T): UnSafeParseResult<T>;\nexport function parse<T extends Subcommand[], U extends Cli>(\n argsv: string[],\n ...params: [U, ...T]\n): UnSafeParseResult<[...T, NoSubcommand & U]>;\n\nexport function parse<T extends Subcommand[], U extends Cli>(argsv: string[], ...params: [U, ...T]) {\n const cliOptions = (\"cliName\" in params[0] ? params[0] : {}) as U;\n const subcommandArr = params as unknown as T;\n const allSubcommands = new Set<string>(subcommandArr.flatMap(c => [c.name, ...(c.aliases || [])]));\n\n // decouple flags E.g. `-rf` -> `-r, -f`\n argsv = decoupleFlags(argsv);\n\n type ResultObj = Record<string, unknown> & {\n subcommand: string | undefined;\n positional?: string[];\n arguments?: unknown[];\n _info?: Record<string, { rawArg?: string; rawValue?: string; source: \"cli\" | \"default\" }>;\n printCliHelp: (options?: PrintHelpOpt) => void;\n printSubcommandHelp: (subcommand: any, options?: PrintHelpOpt) => void;\n };\n\n const results: ResultObj = {\n subcommand: undefined,\n printCliHelp(opt) {\n help.printCliHelp(params, opt);\n },\n printSubcommandHelp(subcommandStr, opt) {\n const subcommand = subcommandArr.find(c => c.name === subcommandStr);\n if (!subcommand) return console.error(`Cannot print help for subcommand \"${subcommandStr}\" as it does not exist`);\n help.printSubcommandHelp(subcommand, opt, cliOptions.cliName);\n },\n };\n\n const addRawArg = (optionName: string, rawArg: string) => {\n if (!results._info) results._info = {};\n if (!results._info[optionName]) results._info[optionName] = Object.create({});\n results._info[optionName].rawArg = rawArg;\n };\n\n const addRawValue = (optionName: string, rawValue: string) => {\n if (!results._info) results._info = {};\n if (!results._info[optionName]) results._info[optionName] = Object.create({});\n results._info[optionName].rawValue = rawValue;\n };\n\n const addSource = (optionName: string, source: \"cli\" | \"default\") => {\n if (!results._info) results._info = {};\n if (!results._info[optionName]) results._info[optionName] = Object.create({});\n results._info[optionName].source = source;\n };\n\n const fillOption = (optionName: string, value: Option) => {\n if (!results._info) results._info = {};\n if (!results._info[optionName]) results._info[optionName] = Object.create({});\n Object.assign(results._info[optionName], value);\n };\n\n for (let i = 0; i < argsv.length; i++) {\n const arg = argsv[i];\n\n // * subcommand\n if (i === 0) {\n results.subcommand = allSubcommands.has(arg) ? arg : undefined;\n\n // add positional and arguments array\n const subcommandProps = subcommandArr.find(c => c.name === results.subcommand);\n if (subcommandProps?.allowPositional) results.positional = [];\n if (subcommandProps?.arguments?.length) results.arguments = [];\n\n if (results.subcommand) continue;\n }\n\n // * option\n const argAndValue = arg.split(\"=\").filter(Boolean);\n const argWithEquals = arg.includes(\"=\");\n const argument = argAndValue[0];\n const argValue: string | undefined = argAndValue[1];\n\n if (isOptionArg(argument)) {\n if (isFlagArg(argument) && argWithEquals) {\n throw new Error(`Flag arguments cannot be assigned using \"=\": \"${arg}\"`);\n }\n\n const subcommandProps = subcommandArr.find(c => c.name === results.subcommand);\n if (!subcommandProps) throw new Error(`Unknown subcommand: \"${results.subcommand}\"`);\n\n if (!subcommandProps.options) {\n const msg = !results.subcommand\n ? \"options are not allowed here\"\n : `subcommand \"${results.subcommand}\" does not allow options`;\n throw new Error(`Error: ${msg}: \"${argument}\"`);\n }\n\n const optionName = transformArg(argument);\n if (optionName in results) throw new Error(`Duplicate option: \"${argument}\"`);\n\n const isNegative = argument.startsWith(\"--no-\");\n\n const option = subcommandProps.options.find(o => {\n if (o.name === optionName) return true;\n if (isNegative && noName(o.name) === optionName) return true;\n\n if (!o.aliases) return false;\n if (o.aliases.includes(optionName)) return true;\n if (isNegative && o.aliases.map(noName).includes(optionName)) return true;\n\n return false;\n });\n\n if (!option) {\n throw new Error(`Unknown option: \"${argument}\"`);\n }\n\n const isTypeBoolean = isBooleanSchema(option.type);\n const nextArg = argsv[i + 1];\n\n let optionValue: string | boolean = argWithEquals ? argValue : nextArg;\n\n if (isTypeBoolean) {\n if (argWithEquals) {\n const parsedBoolean = stringToBoolean(argValue);\n optionValue = isNegative ? !parsedBoolean : parsedBoolean;\n } else {\n optionValue = !isNegative;\n }\n }\n\n if (typeof optionValue === \"undefined\") {\n throw new Error(`Expected a value for \"${argument}\" but got nothing`);\n }\n\n if (!argWithEquals && isOptionArg(optionValue)) {\n throw new Error(`Expected a value for \"${argument}\" but got an argument \"${nextArg}\"`);\n }\n\n const res = option.type.safeParse(optionValue);\n if (!res.success) {\n throw new Error(`Invalid value \"${optionValue}\" for \"${argument}\": ${res.error.errors[0].message}`);\n }\n\n results[option.name] = res.data;\n addRawArg(option.name, argument);\n const rawVal = argWithEquals ? argValue : isTypeBoolean ? \"\" : nextArg;\n addRawValue(option.name, rawVal);\n fillOption(option.name, option);\n\n if (!argWithEquals && !isTypeBoolean) i++;\n continue;\n }\n\n const subcommandProps = subcommandArr.find(c => c.name === results.subcommand);\n\n // * arguments\n if (subcommandProps?.arguments?.length) {\n if (!results.arguments) results.arguments = [];\n\n const currentArgCount = results.arguments.length;\n\n if (currentArgCount < subcommandProps.arguments.length) {\n const argType = subcommandProps.arguments[currentArgCount].type;\n\n let argValue: string | boolean = arg;\n const isTypeBoolean = isBooleanSchema(argType);\n if (isTypeBoolean) argValue = stringToBoolean(argValue);\n\n const res = argType.safeParse(argValue);\n if (!res.success) {\n throw new Error(\n `The ${getOrdinalPlacement(currentArgCount)} argument \"${arg}\" is invalid: ${res.error.errors[0].message}`,\n );\n }\n\n results.arguments.push(res.data);\n continue;\n }\n }\n\n // * positional\n if (subcommandProps?.allowPositional) {\n if (!results.positional) results.positional = [];\n results.positional.push(arg);\n continue;\n }\n\n const msg = !results.subcommand ? \"here\" : `for subcommand \"${results.subcommand}\"`;\n throw new Error(`Unexpected argument \"${arg}\": positional arguments are not allowed ${msg}`);\n }\n\n // check for missing options - set defaults - add _source\n const subcommandProps = subcommandArr.find(c => c.name === results.subcommand);\n if (subcommandProps?.options?.length) {\n for (const option of subcommandProps.options) {\n if (option.name in results) {\n addSource(option.name, \"cli\");\n fillOption(option.name, option);\n continue;\n }\n\n if (option.type.isOptional()) {\n const hasDefault = typeof option.type._def.defaultValue === \"function\";\n if (!hasDefault) continue;\n results[option.name] = option.type._def.defaultValue();\n addSource(option.name, \"default\");\n fillOption(option.name, option);\n continue;\n }\n\n throw new Error(`Missing required option: ${transformOptionToArg(option.name)}`);\n }\n }\n\n // check for arguments - set defaults\n if (subcommandProps?.arguments?.length) {\n const currentArgCount = results.arguments?.length ?? 0;\n const subcommandArgCount = subcommandProps.arguments.length;\n\n // missing arguments\n if (currentArgCount < subcommandArgCount) {\n for (let i = currentArgCount; i < subcommandArgCount; i++) {\n const argumentType = subcommandProps.arguments[i].type;\n const hasDefault = typeof argumentType._def.defaultValue === \"function\";\n if (hasDefault && results.arguments) {\n results.arguments.push(argumentType._def.defaultValue());\n continue;\n }\n\n if (argumentType.isOptional()) continue;\n\n throw new Error(`the ${getOrdinalPlacement(i)} argument is required: \"${subcommandProps.arguments[i].name}\"`);\n }\n }\n }\n\n if (subcommandProps?.action) {\n subcommandProps.action(results);\n }\n\n return results as UnSafeParseResult<[...T, NoSubcommand & U]>;\n}\n\nexport function safeParse<T extends Subcommand[]>(argsv: string[], ...params: T): SafeParseResult<T>;\nexport function safeParse<T extends Subcommand[], U extends Cli>(\n argsv: string[],\n ...params: [U, ...T]\n): SafeParseResult<[...T, NoSubcommand & U]>;\n\nexport function safeParse<T extends Subcommand[], U extends Cli>(argsv: string[], ...params: [U, ...T]) {\n const cliOptions = (\"cliName\" in params[0] ? params[0] : {}) as U;\n const subcommandArr = params as Subcommand[];\n\n const printCliHelp = (opt?: PrintHelpOpt) => help.printCliHelp(params, opt);\n const printSubcommandHelp = (subcommandStr: NonNullable<T[number][\"name\"]>, opt?: PrintHelpOpt) => {\n const subcommand = subcommandArr.find(c => c.name === subcommandStr);\n if (!subcommand) return console.error(`Cannot print help for subcommand \"${subcommandStr}\" as it does not exist`);\n help.printSubcommandHelp(subcommand, opt, cliOptions.cliName);\n };\n\n try {\n const data = parse(argsv, ...params);\n // @ts-expect-error error\n delete data.printCliHelp;\n // @ts-expect-error error\n delete data.printSubcommandHelp;\n\n return {\n success: true,\n data: data as Omit<typeof data, \"printCliHelp\" | \"printSubcommandHelp\">,\n printCliHelp,\n printSubcommandHelp,\n };\n } catch (e) {\n return { success: false, error: e as Error, printCliHelp, printSubcommandHelp };\n }\n}\n"],"mappings":"AAAA,OAASA,IAAI,KAAQ,WAAW,CAChC,OACEC,aAAa,CACbC,mBAAmB,CACnBC,eAAe,CACfC,SAAS,CACTC,WAAW,CACXC,MAAM,CACNC,eAAe,CACfC,YAAY,CACZC,oBAAoB,KACf,YAAY,CAkBnB,MAAO,SAAS,CAAAC,KAAKA,CAAwCC,KAAe,CAAwB,SAAAC,IAAA,CAAAC,SAAA,CAAAC,MAAA,CAAnBC,MAAM,KAAAC,KAAA,CAAAJ,IAAA,GAAAA,IAAA,MAAAK,IAAA,GAAAA,IAAA,CAAAL,IAAA,CAAAK,IAAA,IAANF,MAAM,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA,GACrF,KAAM,CAAAC,UAAU,CAAI,SAAS,EAAI,CAAAH,MAAM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+ {"version":3,"names":["help","decoupleFlags","getOrdinalPlacement","isBooleanSchema","isFlagArg","isOptionArg","noName","stringToBoolean","transformArg","transformOptionToArg","parse","argsv","_len","arguments","length","params","Array","_key","cliOptions","subcommandArr","allSubcommands","Set","flatMap","c","name","aliases","results","subcommand","undefined","printCliHelp","opt","printSubcommandHelp","subcommandStr","find","includes","console","error","cliName","GetSubcommandProps","cmd","addRawArg","optionName","rawArg","_info","Object","create","addRawValue","rawValue","addSource","source","fillOption","value","assign","i","arg","has","subcommandProps","allowPositional","positional","argAndValue","split","filter","Boolean","argWithEquals","argument","argValue","Error","options","msg","isNegative","startsWith","option","o","map","isTypeBoolean","type","nextArg","optionValue","parsedBoolean","res","safeParse","success","errors","message","data","rawVal","currentArgCount","argType","push","isOptional","hasDefault","_def","defaultValue","subcommandArgCount","argumentType","action","_len2","_key2","e"],"sourceRoot":"../../src","sources":["parser.ts"],"sourcesContent":["import { help } from \"./help.js\";\nimport {\n decoupleFlags,\n getOrdinalPlacement,\n isBooleanSchema,\n isFlagArg,\n isOptionArg,\n noName,\n stringToBoolean,\n transformArg,\n transformOptionToArg,\n} from \"./utils.js\";\n\nimport type {\n Cli,\n NoSubcommand,\n Option,\n PrintHelpOpt,\n SafeParseResult,\n Subcommand,\n UnSafeParseResult,\n} from \"./types.js\";\n\nexport function parse<T extends Subcommand[]>(argsv: string[], ...params: T): UnSafeParseResult<T>;\nexport function parse<T extends Subcommand[], U extends Cli>(\n argsv: string[],\n ...params: [U, ...T]\n): UnSafeParseResult<[...T, NoSubcommand & U]>;\n\nexport function parse<T extends Subcommand[], U extends Cli>(argsv: string[], ...params: [U, ...T]) {\n const cliOptions = (\"cliName\" in params[0] ? params[0] : {}) as U;\n const subcommandArr = params as unknown as T;\n const allSubcommands = new Set<string>(subcommandArr.flatMap(c => [c.name, ...(c.aliases || [])]));\n\n // decouple flags E.g. `-rf` -> `-r, -f`\n argsv = decoupleFlags(argsv);\n\n type ResultObj = Record<string, unknown> & {\n subcommand: string | undefined;\n positional?: string[];\n arguments?: unknown[];\n _info?: Record<string, { rawArg?: string; rawValue?: string; source: \"cli\" | \"default\" }>;\n printCliHelp: (options?: PrintHelpOpt) => void;\n printSubcommandHelp: (subcommand: any, options?: PrintHelpOpt) => void;\n };\n\n const results: ResultObj = {\n subcommand: undefined,\n printCliHelp(opt) {\n help.printCliHelp(params, opt);\n },\n printSubcommandHelp(subcommandStr, opt) {\n const subcommand = subcommandArr.find(c => {\n if (c.name === subcommandStr) return true;\n if (!subcommandStr) return false;\n if (!c.aliases?.length) return false;\n return c.aliases.includes(subcommandStr);\n });\n if (!subcommand) return console.error(`Cannot print help for subcommand \"${subcommandStr}\" as it does not exist`);\n help.printSubcommandHelp(subcommand, opt, cliOptions.cliName);\n },\n };\n\n /** - Get current subcommand props */\n const GetSubcommandProps = (cmd = results.subcommand) => {\n return subcommandArr.find(c => {\n if (c.name === cmd) return true;\n if (!cmd) return false;\n if (!c.aliases?.length) return false;\n return c.aliases.includes(cmd);\n });\n };\n\n const addRawArg = (optionName: string, rawArg: string) => {\n if (!results._info) results._info = {};\n if (!results._info[optionName]) results._info[optionName] = Object.create({});\n results._info[optionName].rawArg = rawArg;\n };\n\n const addRawValue = (optionName: string, rawValue: string) => {\n if (!results._info) results._info = {};\n if (!results._info[optionName]) results._info[optionName] = Object.create({});\n results._info[optionName].rawValue = rawValue;\n };\n\n const addSource = (optionName: string, source: \"cli\" | \"default\") => {\n if (!results._info) results._info = {};\n if (!results._info[optionName]) results._info[optionName] = Object.create({});\n results._info[optionName].source = source;\n };\n\n const fillOption = (optionName: string, value: Option) => {\n if (!results._info) results._info = {};\n if (!results._info[optionName]) results._info[optionName] = Object.create({});\n Object.assign(results._info[optionName], value);\n };\n\n for (let i = 0; i < argsv.length; i++) {\n const arg = argsv[i];\n\n // * subcommand\n if (i === 0) {\n results.subcommand = allSubcommands.has(arg) ? arg : undefined;\n\n // add positional and arguments array\n const subcommandProps = GetSubcommandProps();\n if (subcommandProps?.allowPositional) results.positional = [];\n if (subcommandProps?.arguments?.length) results.arguments = [];\n\n if (results.subcommand) continue;\n }\n\n // * option\n const argAndValue = arg.split(\"=\").filter(Boolean);\n const argWithEquals = arg.includes(\"=\");\n const argument = argAndValue[0];\n const argValue: string | undefined = argAndValue[1];\n\n if (isOptionArg(argument)) {\n if (isFlagArg(argument) && argWithEquals) {\n throw new Error(`Flag arguments cannot be assigned using \"=\": \"${arg}\"`);\n }\n\n const subcommandProps = GetSubcommandProps();\n if (!subcommandProps) throw new Error(`Unknown subcommand: \"${results.subcommand}\"`);\n\n if (!subcommandProps.options) {\n const msg = !results.subcommand\n ? \"options are not allowed here\"\n : `subcommand \"${results.subcommand}\" does not allow options`;\n throw new Error(`Error: ${msg}: \"${argument}\"`);\n }\n\n const optionName = transformArg(argument);\n const isNegative = argument.startsWith(\"--no-\");\n\n const option = subcommandProps.options.find(o => {\n if (o.name === optionName) return true;\n if (isNegative && noName(o.name) === optionName) return true;\n\n if (!o.aliases) return false;\n if (o.aliases.includes(optionName)) return true;\n if (isNegative && o.aliases.map(noName).includes(optionName)) return true;\n\n return false;\n });\n\n if (!option) {\n throw new Error(`Unknown option: \"${argument}\"`);\n }\n\n if (option.name in results) {\n throw new Error(`Duplicated option: \"${argument}\"`);\n }\n\n const isTypeBoolean = isBooleanSchema(option.type);\n const nextArg = argsv[i + 1];\n\n let optionValue: string | boolean = argWithEquals ? argValue : nextArg;\n\n if (isTypeBoolean) {\n if (argWithEquals) {\n const parsedBoolean = stringToBoolean(argValue);\n optionValue = isNegative ? !parsedBoolean : parsedBoolean;\n } else {\n optionValue = !isNegative;\n }\n }\n\n if (typeof optionValue === \"undefined\") {\n throw new Error(`Expected a value for \"${argument}\" but got nothing`);\n }\n\n if (!argWithEquals && isOptionArg(optionValue)) {\n throw new Error(`Expected a value for \"${argument}\" but got an argument \"${nextArg}\"`);\n }\n\n const res = option.type.safeParse(optionValue);\n if (!res.success) {\n throw new Error(`Invalid value \"${optionValue}\" for \"${argument}\": ${res.error.errors[0].message}`);\n }\n\n results[option.name] = res.data;\n addRawArg(option.name, argument);\n const rawVal = argWithEquals ? argValue : isTypeBoolean ? \"\" : nextArg;\n addRawValue(option.name, rawVal);\n fillOption(option.name, option);\n\n if (!argWithEquals && !isTypeBoolean) i++;\n continue;\n }\n\n const subcommandProps = GetSubcommandProps();\n\n // * arguments\n if (subcommandProps?.arguments?.length) {\n if (!results.arguments) results.arguments = [];\n\n const currentArgCount = results.arguments.length;\n\n if (currentArgCount < subcommandProps.arguments.length) {\n const argType = subcommandProps.arguments[currentArgCount].type;\n\n let argValue: string | boolean = arg;\n const isTypeBoolean = isBooleanSchema(argType);\n if (isTypeBoolean) argValue = stringToBoolean(argValue);\n\n const res = argType.safeParse(argValue);\n if (!res.success) {\n throw new Error(\n `The ${getOrdinalPlacement(currentArgCount)} argument \"${arg}\" is invalid: ${res.error.errors[0].message}`,\n );\n }\n\n results.arguments.push(res.data);\n continue;\n }\n }\n\n // * positional\n if (subcommandProps?.allowPositional) {\n if (!results.positional) results.positional = [];\n results.positional.push(arg);\n continue;\n }\n\n const msg = !results.subcommand ? \"here\" : `for subcommand \"${results.subcommand}\"`;\n throw new Error(`Unexpected argument \"${arg}\": positional arguments are not allowed ${msg}`);\n }\n\n // check for missing options - set defaults - add _source\n const subcommandProps = GetSubcommandProps();\n if (subcommandProps?.options?.length) {\n for (const option of subcommandProps.options) {\n if (option.name in results) {\n addSource(option.name, \"cli\");\n fillOption(option.name, option);\n continue;\n }\n\n if (option.type.isOptional()) {\n const hasDefault = typeof option.type._def.defaultValue === \"function\";\n if (!hasDefault) continue;\n results[option.name] = option.type._def.defaultValue();\n addSource(option.name, \"default\");\n fillOption(option.name, option);\n continue;\n }\n\n throw new Error(`Missing required option: ${transformOptionToArg(option.name)}`);\n }\n }\n\n // check for arguments - set defaults\n if (subcommandProps?.arguments?.length) {\n const currentArgCount = results.arguments?.length ?? 0;\n const subcommandArgCount = subcommandProps.arguments.length;\n\n // missing arguments\n if (currentArgCount < subcommandArgCount) {\n for (let i = currentArgCount; i < subcommandArgCount; i++) {\n const argumentType = subcommandProps.arguments[i].type;\n const hasDefault = typeof argumentType._def.defaultValue === \"function\";\n if (hasDefault && results.arguments) {\n results.arguments.push(argumentType._def.defaultValue());\n continue;\n }\n\n if (argumentType.isOptional()) continue;\n\n throw new Error(`the ${getOrdinalPlacement(i)} argument is required: \"${subcommandProps.arguments[i].name}\"`);\n }\n }\n }\n\n if (subcommandProps?.action) {\n subcommandProps.action(results);\n }\n\n return results as UnSafeParseResult<[...T, NoSubcommand & U]>;\n}\n\nexport function safeParse<T extends Subcommand[]>(argsv: string[], ...params: T): SafeParseResult<T>;\nexport function safeParse<T extends Subcommand[], U extends Cli>(\n argsv: string[],\n ...params: [U, ...T]\n): SafeParseResult<[...T, NoSubcommand & U]>;\n\nexport function safeParse<T extends Subcommand[], U extends Cli>(argsv: string[], ...params: [U, ...T]) {\n const cliOptions = (\"cliName\" in params[0] ? params[0] : {}) as U;\n const subcommandArr = params as Subcommand[];\n\n const printCliHelp = (opt?: PrintHelpOpt) => help.printCliHelp(params, opt);\n const printSubcommandHelp = (subcommandStr: NonNullable<T[number][\"name\"]>, opt?: PrintHelpOpt) => {\n const subcommand = subcommandArr.find(c => c.name === subcommandStr);\n if (!subcommand) return console.error(`Cannot print help for subcommand \"${subcommandStr}\" as it does not exist`);\n help.printSubcommandHelp(subcommand, opt, cliOptions.cliName);\n };\n\n try {\n const data = parse(argsv, ...params);\n // @ts-expect-error error\n delete data.printCliHelp;\n // @ts-expect-error error\n delete data.printSubcommandHelp;\n\n return {\n success: true,\n data: data as Omit<typeof data, \"printCliHelp\" | \"printSubcommandHelp\">,\n printCliHelp,\n printSubcommandHelp,\n };\n } catch (e) {\n return { success: false, error: e as Error, printCliHelp, printSubcommandHelp };\n }\n}\n"],"mappings":"AAAA,OAASA,IAAI,KAAQ,WAAW,CAChC,OACEC,aAAa,CACbC,mBAAmB,CACnBC,eAAe,CACfC,SAAS,CACTC,WAA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B,EAAE,OAAO,SAAK,QA+DjG;AAsKD,eAAO,MAAM,IAAI;;;CAGhB,CAAC"}
1
+ {"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../../src/help.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAY,GAAG,EAAU,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAyBlF,iBAAS,YAAY,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,UAAU,EAAE,CAAC,EAAE,YAAY,GAAE,YAAiB,QA4EpF;AAED,iBAAS,mBAAmB,CAAC,UAAU,EAAE,UAAU,EAAE,YAAY,GAAE,YAAiB,EAAE,OAAO,SAAK,QAiEjG;AAsKD,eAAO,MAAM,IAAI;;;CAGhB,CAAC"}
@@ -1,8 +1,9 @@
1
1
  import { parse, safeParse } from "./parser.js";
2
- import type { ActionFn, Cli, Prettify, Subcommand } from "./types.js";
3
- declare function createSubcommand<const T extends Subcommand>(input: T & Subcommand): Prettify<T & ActionFn<T>>;
4
- declare function createCli<const T extends Cli>(input: T & Cli): Prettify<T & ActionFn<T>>;
2
+ import type { ActionFn, CheckDuplicatedOptions, Cli, Option, Prettify, Subcommand } from "./types.js";
3
+ declare function createSubcommand<const T extends Subcommand>(input: CheckDuplicatedOptions<T>): Prettify<T & ActionFn<T>>;
4
+ declare function createCli<const T extends Cli>(input: CheckDuplicatedOptions<T>): Prettify<T & ActionFn<T>>;
5
+ declare function createOptions<const T extends [Option, ...Option[]]>(options: T): T;
5
6
  declare const printCliHelp: (params: [Cli, ...Subcommand[]], printOptions?: import("./types.js").PrintHelpOpt) => void, printSubcommandHelp: (subcommand: Subcommand, printOptions?: import("./types.js").PrintHelpOpt, cliName?: string) => void;
6
- export { createCli, createSubcommand, parse, printCliHelp, printSubcommandHelp, safeParse };
7
+ export { createCli, createSubcommand, createOptions, parse, printCliHelp, printSubcommandHelp, safeParse };
7
8
  export type * from "./types.js";
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,UAAU,EAAqB,MAAM,YAAY,CAAC;AAEzF,iBAAS,gBAAgB,CAAC,KAAK,CAAC,CAAC,SAAS,UAAU,EAAE,KAAK,EAAE,CAAC,GAAG,UAAU,GAAG,QAAQ,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAItG;AAED,iBAAS,SAAS,CAAC,KAAK,CAAC,CAAC,SAAS,GAAG,EAAE,KAAK,EAAE,CAAC,GAAG,GAAG,GAAG,QAAQ,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAIjF;AAED,QAAA,MAAQ,YAAY,8FAAE,mBAAmB,sGAAS,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,SAAS,EAAE,CAAC;AAE5F,mBAAmB,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EACV,QAAQ,EACR,sBAAsB,EACtB,GAAG,EACH,MAAM,EACN,QAAQ,EACR,UAAU,EAEX,MAAM,YAAY,CAAC;AAEpB,iBAAS,gBAAgB,CAAC,KAAK,CAAC,CAAC,SAAS,UAAU,EAAE,KAAK,EAAE,sBAAsB,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAIjH;AAED,iBAAS,SAAS,CAAC,KAAK,CAAC,CAAC,SAAS,GAAG,EAAE,KAAK,EAAE,sBAAsB,CAAC,C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AAM,EAAE,EACf,GAAG,MAAM,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,GACnB,eAAe,CAAC,CAAC,GAAG,CAAC,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACV,GAAG,EACH,YAAY,EAGZ,eAAe,EACf,UAAU,EACV,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAEpB,wBAAgB,KAAK,CAAC,CAAC,SAAS,UAAU,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;AACnG,wBAAgB,KAAK,CAAC,CAAC,SAAS,UAAU,EAAE,EAAE,CAAC,SAAS,GAAG,EACzD,KAAK,EAAE,MAAM,EAAE,EACf,GAAG,MAAM,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,GACnB,iBAAiB,CAAC,CAAC,GAAG,CAAC,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC;AA+P/C,wBAAgB,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;AACrG,wBAAgB,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,EAAE,CAAC,SAAS,GAAG,EAC7D,KAAK,EAAE,MAAM,EAAE,EACf,GAAG,MAAM,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,GACnB,eAAe,CAAC,CAAC,GAAG,CAAC,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC"}
@@ -9,20 +9,13 @@ export type Subcommand = {
9
9
  * name: "run-app";
10
10
  */
11
11
  name: string;
12
- /**
13
- * - The action is executed with the result of the parsed arguments.
14
- * - To get typescript types use `setAction` instead of this.
15
- *
16
- * @example
17
- * const helpCommand = createSubcommand({ name: "help", options: [...] });
18
- * helpCommand.setAction(res => console.log(res));
19
- */
20
- action?: (results?: any) => void;
21
12
  /**
22
13
  * - The description of the subcommand.
23
14
  * - Used for generating the help message.
24
15
  */
25
16
  description?: string;
17
+ /** - The usage message in the help message. */
18
+ usage?: string;
26
19
  /** - Used for generating the help message. */
27
20
  placeholder?: string;
28
21
  /**
@@ -55,15 +48,19 @@ export type Subcommand = {
55
48
  * which arguments are optional.
56
49
  */
57
50
  arguments?: [Argument, ...Argument[]];
51
+ /**
52
+ * - The action is executed with the result of the parsed arguments.
53
+ * - To get typescript types use `setAction` instead of this.
54
+ *
55
+ * @example
56
+ * const helpCommand = createSubcommand({ name: "help", options: [...] });
57
+ * helpCommand.setAction(res => console.log(res));
58
+ */
59
+ action?: (results?: any) => void;
58
60
  };
59
61
  export type Cli = Prettify<Omit<Subcommand, "name"> & {
60
62
  /** - The name of the CLI program. */
61
63
  cliName: string;
62
- /**
63
- * - The usage of the CLI program.
64
- * - Used for generating the help message.
65
- */
66
- usage?: string;
67
64
  }>;
68
65
  export type Option = {
69
66
  /**
@@ -241,8 +238,8 @@ export type PrintMethods<N extends Subcommand["name"] | undefined> = {
241
238
  printCliHelp: (options?: PrintHelpOpt) => void;
242
239
  printSubcommandHelp: (subcommand: LiteralUnion<NonNullable<N>>, options?: PrintHelpOpt) => void;
243
240
  };
244
- export type UnSafeParseResult<S extends Partial<Subcommand>[]> = Prettify<ParseResult<S> & PrintMethods<S[number]["name"]>>;
245
- export type SafeParseResult<S extends Partial<Subcommand>[]> = Prettify<({
241
+ export type UnSafeParseResult<S extends Partial<Subcommand>[]> = CheckDuplicatedSubcommands<S> extends infer E extends string ? E : Prettify<ParseResult<S> & PrintMethods<S[number]["name"]>>;
242
+ export type SafeParseResult<S extends Partial<Subcommand>[]> = CheckDuplicatedSubcommands<S> extends infer E extends string ? E : Prettify<({
246
243
  success: false;
247
244
  error: Error;
248
245
  } | {
@@ -252,5 +249,33 @@ export type SafeParseResult<S extends Partial<Subcommand>[]> = Prettify<({
252
249
  export type ActionFn<T extends Subcommand | Cli> = {
253
250
  setAction: (actions: (res: UnSafeParseResult<[T]>) => void) => void;
254
251
  };
252
+ /** - Combine `name` and `aliases` to a `string[]` */
253
+ type MapNameAndAliases2StrArr<T extends {
254
+ name?: string;
255
+ aliases?: string[];
256
+ }[]> = T extends [
257
+ infer First extends Subcommand,
258
+ ...infer Rest
259
+ ] ? Rest extends {
260
+ name?: string;
261
+ aliases?: string[];
262
+ }[] ? [First["name"], ...(First["aliases"] extends string[] ? First["aliases"] : []), ...MapNameAndAliases2StrArr<Rest>] : [First["name"], ...(First["aliases"] extends string[] ? First["aliases"] : [])] : [];
263
+ /**
264
+ * - Find duplicated items in an array and return it
265
+ * - Return `false` if not found
266
+ */
267
+ type IsDuplicatesInArr<Input extends any[]> = Input extends [infer Item, ...infer Rest] ? Rest extends any[] ? Item extends Rest[number] ? Item : IsDuplicatesInArr<Rest> : false : false;
268
+ /**
269
+ * - Check if there are duplicated options including aliases in `subcommand`
270
+ * - Return an error message if duplicated is found
271
+ * - Return `subcommand` if not found
272
+ */
273
+ export type CheckDuplicatedOptions<T extends Subcommand | Cli> = T["options"] extends infer O extends Option[] ? IsDuplicatesInArr<MapNameAndAliases2StrArr<O>> extends infer D extends string ? `>>> Error: Duplicated Options \`${D}\` <<<` : T : T;
274
+ /**
275
+ * - Check for duplicated subcommands including aliases
276
+ * - Return an error message if duplicated is found
277
+ * - Return the `subcommand[]` if no error
278
+ */
279
+ export type CheckDuplicatedSubcommands<T extends Partial<Subcommand>[]> = IsDuplicatesInArr<MapNameAndAliases2StrArr<T>> extends infer D extends string ? `>>> Error: Duplicated Subcommand \`${D}\` <<<` : T;
255
280
  export {};
256
281
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,K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I,CAAC,MAAM,CAAC,GACvB,IAAI,GACJ,iBAAiB,CAAC,IAAI,CAAC,GACzB,KAAK,GACP,KAAK,CAAC;AAEV;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,UAAU,GAAG,GAAG,IAAI,CAAC,CAAC,SAAS,CAAC,SAAS,MAAM,CAAC,SAAS,MAAM,EAAE,GAC1G,iBAAiB,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,SAAS,MAAM,GAC3E,mCAAmC,CAAC,QAAQ,GAC5C,CAAC,GACH,CAAC,CAAC;AAEN;;;;GAIG;AACH,MAAM,MAAM,0BAA0B,CAAC,CAAC,SAAS,OAAO,CAAC,UAAU,CAAC,EAAE,IACpE,iBAAiB,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,SAAS,MAAM,GACzE,sCAAsC,CAAC,QAAQ,GAC/C,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,10 +1,16 @@
1
1
  {
2
2
  "name": "zod-args-parser",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "A strictly typed command-line arguments parser powered by Zod.",
5
+ "author": "Ahmed ALABSI <alabsi91@gmail>",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/alabsi91/zod-args-parser.git"
10
+ },
5
11
  "type": "module",
6
12
  "scripts": {
7
- "dev": "tsx watch src/test.ts",
13
+ "dev": "tsx watch example/cli.ts",
8
14
  "build": "node scripts/build.mjs",
9
15
  "test": "eslint src/** --fix && tsc --noEmit && tsx test/test.ts",
10
16
  "prepare": "npm run test && npm run build"
@@ -24,6 +30,14 @@
24
30
  "lib",
25
31
  "src"
26
32
  ],
33
+ "keywords": [
34
+ "command-line",
35
+ "cli",
36
+ "arguments",
37
+ "parser",
38
+ "zod",
39
+ "typescript"
40
+ ],
27
41
  "dependencies": {
28
42
  "chalk": "^5.3.0",
29
43
  "zod": "^3.23.8"
@@ -32,6 +46,7 @@
32
46
  "@babel/core": "^7.26.0",
33
47
  "@babel/preset-env": "^7.26.0",
34
48
  "@babel/preset-typescript": "^7.26.0",
49
+ "@eslint/compat": "^1.2.3",
35
50
  "@eslint/js": "^9.14.0",
36
51
  "@types/babel__core": "^7.20.5",
37
52
  "@types/node": "^22.9.0",
package/src/help.ts CHANGED
@@ -3,14 +3,13 @@ import { concat, getDefaultValueFromSchema, indent, ln, print, println, transfor
3
3
 
4
4
  import type { Argument, Cli, Option, PrintHelpOpt, Subcommand } from "./types.js";
5
5
 
6
- /** Colors */
7
6
  const colors: NonNullable<Required<PrintHelpOpt["customColors"]>> = {
8
7
  title: chalk.bold.blue,
9
8
  description: chalk.white,
10
9
  default: chalk.dim.italic,
11
10
  optional: chalk.dim.italic,
12
11
  exampleTitle: chalk.yellow,
13
- example: chalk.dim.italic,
12
+ example: chalk.dim,
14
13
  command: chalk.yellow,
15
14
  option: chalk.cyan,
16
15
  argument: chalk.green,
@@ -126,13 +125,15 @@ function printSubcommandHelp(subcommand: Subcommand, printOptions: PrintHelpOpt
126
125
  };
127
126
 
128
127
  // Print command usage
129
- const usage = concat(
130
- c.punctuation("$"),
131
- cliName,
132
- c.command(subcommand.name),
133
- subcommand.options?.length ? c.option("[options]") : "",
134
- subcommand.arguments?.length || subcommand.allowPositional ? c.argument("<arguments>") : "",
135
- );
128
+ const usage =
129
+ subcommand.usage ??
130
+ concat(
131
+ c.punctuation("$"),
132
+ cliName,
133
+ c.command(subcommand.name),
134
+ subcommand.options?.length ? c.option("[options]") : "",
135
+ subcommand.arguments?.length || subcommand.allowPositional ? c.argument("<arguments>") : "",
136
+ );
136
137
  printTitle("Usage");
137
138
  println();
138
139
  println(indent(2), usage, ln(1));
@@ -293,7 +294,7 @@ function printPreparedCommands(commandsToPrint: PreparedToPrint[], c: typeof col
293
294
  for (const { names, placeholder, description } of commandsToPrint) {
294
295
  const optLength = names.length + (placeholder?.length ?? 0);
295
296
  const spacing = longest + 1 - optLength;
296
- const normalizeDesc = description.replace(/\n/g, "\n" + indent(longest + 7));
297
+ const normalizeDesc = description.replace(/\n/g, "\n" + indent(longest + 7) + c.punctuation("└"));
297
298
 
298
299
  const coloredNames = names
299
300
  .split(/(,)/)
package/src/index.ts CHANGED
@@ -1,22 +1,34 @@
1
1
  import { help } from "./help.js";
2
2
  import { parse, safeParse } from "./parser.js";
3
3
 
4
- import type { ActionFn, Cli, Prettify, Subcommand, UnSafeParseResult } from "./types.js";
4
+ import type {
5
+ ActionFn,
6
+ CheckDuplicatedOptions,
7
+ Cli,
8
+ Option,
9
+ Prettify,
10
+ Subcommand,
11
+ UnSafeParseResult,
12
+ } from "./types.js";
5
13
 
6
- function createSubcommand<const T extends Subcommand>(input: T & Subcommand): Prettify<T & ActionFn<T>> {
14
+ function createSubcommand<const T extends Subcommand>(input: CheckDuplicatedOptions<T>): Prettify<T & ActionFn<T>> {
7
15
  return Object.assign(input, {
8
16
  setAction: (action: (res: UnSafeParseResult<[T]>) => void) => (input.action = action),
9
17
  });
10
18
  }
11
19
 
12
- function createCli<const T extends Cli>(input: T & Cli): Prettify<T & ActionFn<T>> {
20
+ function createCli<const T extends Cli>(input: CheckDuplicatedOptions<T>): Prettify<T & ActionFn<T>> {
13
21
  return Object.assign(input, {
14
22
  setAction: (action: (res: UnSafeParseResult<[T]>) => void) => (input.action = action),
15
23
  });
16
24
  }
17
25
 
26
+ function createOptions<const T extends [Option, ...Option[]]>(options: T): T {
27
+ return options;
28
+ }
29
+
18
30
  const { printCliHelp, printSubcommandHelp } = help;
19
31
 
20
- export { createCli, createSubcommand, parse, printCliHelp, printSubcommandHelp, safeParse };
32
+ export { createCli, createSubcommand, createOptions, parse, printCliHelp, printSubcommandHelp, safeParse };
21
33
 
22
34
  export type * from "./types.js";