zod-args-parser 1.0.3 → 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.
package/README.md CHANGED
@@ -19,13 +19,13 @@ npm install zod-args-parser
19
19
  ## Usage
20
20
 
21
21
  ```ts
22
+ import { z } from "zod";
22
23
  import { createCli, createSubcommand, createOptions, safeParse } from "zod-args-parser";
23
24
 
24
25
  // Share same options between subcommands
25
26
  const sharedOptions = createOptions([
26
27
  {
27
28
  name: "verbose",
28
- aliases: ["v"],
29
29
  description: "Verbose mode",
30
30
  type: z.boolean().optional(),
31
31
  },
@@ -33,25 +33,43 @@ const sharedOptions = createOptions([
33
33
 
34
34
  // Create a CLI schema
35
35
  // This will be used when no subcommands are provided
36
- const cliProgram = createCli({
36
+ const cliSchema = createCli({
37
37
  cliName: "my-cli",
38
38
  description: "A description for my CLI",
39
39
  example: "example of how to use my cli\nmy-cli --help",
40
40
  options: [
41
41
  {
42
42
  name: "help",
43
- description: "Show this help message",
44
43
  aliases: ["h"],
45
- type: z.boolean(),
44
+ type: z.boolean().optional().describe("Show this help message"),
45
+ },
46
+ {
47
+ name: "version",
48
+ aliases: ["v"],
49
+ description: "Show version",
50
+ type: z.boolean().optional(),
46
51
  },
47
52
  ...sharedOptions,
48
53
  ],
49
54
  });
50
55
 
51
- // Execute this function when the CLI is run
52
- cliProgram.setAction(results => {
53
- const { help } = results;
54
- if (help) results.printCliHelp();
56
+ // Execute this function when the CLI is run (no subcommands)
57
+ cliSchema.setAction(results => {
58
+ const { help, version, verbose } = results;
59
+
60
+ if (help) {
61
+ results.printCliHelp();
62
+ return;
63
+ }
64
+
65
+ if (version) {
66
+ console.log("v1.0.0");
67
+ return;
68
+ }
69
+
70
+ if (verbose) {
71
+ console.log("Verbose mode enabled");
72
+ }
55
73
  });
56
74
 
57
75
  // Create a subcommand schema
@@ -77,7 +95,7 @@ helpCommandSchema.setAction(results => {
77
95
 
78
96
  const results = safeParse(
79
97
  process.argv.slice(2),
80
- cliProgram,
98
+ cliSchema,
81
99
  helpCommandSchema,
82
100
  // Add more subcommands
83
101
  );
@@ -131,6 +149,9 @@ type Arguments = InferArgumentsType<typeof subcommand>;
131
149
  - `description?: string`
132
150
  A description of the subcommand for the help message.
133
151
 
152
+ - `usage?: string`
153
+ The usage of the subcommand for the help message.
154
+
134
155
  - `placeholder?: string`
135
156
  A placeholder displayed in the help message alongside the subcommand name.
136
157
 
@@ -145,7 +166,7 @@ type Arguments = InferArgumentsType<typeof subcommand>;
145
166
  An array of options for the subcommand.
146
167
 
147
168
  - `name: string`
148
- The name of the option. Should be a valid variable name in JavaScript.
169
+ The name of the option. camelCase is recommended. E.g. `inputDir` -> `--input-dir`
149
170
 
150
171
  - `aliases?: string[]`
151
172
  An array of aliases for the option.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.help=void 0;var _chalk=_interopRequireDefault(require("chalk"));var _utils=require("./utils.js");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e};}const colors={title:_chalk.default.bold.blue,description:_chalk.default.white,default:_chalk.default.dim.italic,optional:_chalk.default.dim.italic,exampleTitle:_chalk.default.yellow,example:_chalk.default.dim.italic,command:_chalk.default.yellow,option:_chalk.default.cyan,argument:_chalk.default.green,placeholder:_chalk.default.hex("#FF9800"),punctuation:_chalk.default.white.dim};function printCliHelp(params){let printOptions=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};printOptions.colors??=true;const noColors=new Proxy(colors,{get:()=>{return function(){for(var _len=arguments.length,str=new Array(_len),_key=0;_key<_len;_key++){str[_key]=arguments[_key];}return str.join(" ");};}});const c=printOptions.colors?colors:noColors;if(printOptions.customColors){Object.assign(c,printOptions.customColors);}const isFirstParamCli="cliName"in params[0];const cliOptions=isFirstParamCli?params.shift():{};const subcommands=params;const printTitle=title=>{(0,_utils.print)(c.title(` ${title.toUpperCase()} `));};const cliName=cliOptions.cliName??"";const usage=cliOptions.usage??(0,_utils.concat)(c.punctuation("$"),cliName,subcommands.length?c.command("[command]"):"",cliOptions.options?.length?c.option("[options]"):"",cliOptions.arguments?.length||cliOptions.allowPositional?c.argument("<arguments>"):"");printTitle("Usage");(0,_utils.println)();(0,_utils.println)((0,_utils.indent)(2),usage,(0,_utils.ln)(1));if(cliOptions.description){printTitle("Description");(0,_utils.println)();(0,_utils.println)((0,_utils.indent)(2),c.description(cliOptions.description),(0,_utils.ln)(1));}let longest=0;const[optionsToPrint,longestOptionIndent]=prepareOptionsToPrint(cliOptions.options);if(longestOptionIndent>longest)longest=longestOptionIndent;const[commandsToPrint,longestSubcommandIndent]=prepareCommandsToPrint(subcommands);if(longestSubcommandIndent>longest)longest=longestSubcommandIndent;const[argsToPrint,longestArgIndent]=prepareArgumentsToPrint(cliOptions.arguments);if(longestArgIndent>longest)longest=longestArgIndent;printPreparedOptions(optionsToPrint,c,longest);printPreparedCommands(commandsToPrint,c,longest);printPreparedArguments(argsToPrint,c,longest);if(cliOptions.example){printTitle("Example");(0,_utils.println)();const normalizeExample=cliOptions.example.replace(/\n/g,"\n"+(0,_utils.indent)(3));(0,_utils.println)((0,_utils.indent)(2),c.example(normalizeExample),(0,_utils.ln)(1));}}function printSubcommandHelp(subcommand){let printOptions=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};let cliName=arguments.length>2&&arguments[2]!==undefined?arguments[2]:"";printOptions.colors??=true;const noColors=new Proxy(colors,{get:()=>{return function(){for(var _len2=arguments.length,str=new Array(_len2),_key2=0;_key2<_len2;_key2++){str[_key2]=arguments[_key2];}return str.join(" ");};}});const c=printOptions.colors?colors:noColors;if(printOptions.customColors){Object.assign(c,printOptions.customColors);}const printTitle=title=>{(0,_utils.print)(c.title(` ${title.toUpperCase()} `));};const usage=(0,_utils.concat)(c.punctuation("$"),cliName,c.command(subcommand.name),subcommand.options?.length?c.option("[options]"):"",subcommand.arguments?.length||subcommand.allowPositional?c.argument("<arguments>"):"");printTitle("Usage");(0,_utils.println)();(0,_utils.println)((0,_utils.indent)(2),usage,(0,_utils.ln)(1));if(subcommand.description){printTitle("Description");(0,_utils.println)();const normalizeDesc=subcommand.description.replace(/\n/g,"\n"+(0,_utils.indent)(3));(0,_utils.println)((0,_utils.indent)(2),c.description(normalizeDesc),(0,_utils.ln)(1));}let longest=0;const[optionsToPrint,longestOptionIndent]=prepareOptionsToPrint(subcommand.options);if(longestOptionIndent>longest)longest=longestOptionIndent;const[argsToPrint,longestArgIndent]=prepareArgumentsToPrint(subcommand.arguments);if(longestArgIndent>longest)longest=longestArgIndent;printPreparedOptions(optionsToPrint,c,longest);printPreparedArguments(argsToPrint,c,longest);if(subcommand.example){printTitle("Example");(0,_utils.println)();const normalizeExample=subcommand.example.replace(/\n/g,"\n"+(0,_utils.indent)(3));(0,_utils.println)((0,_utils.indent)(2),c.example(normalizeExample),(0,_utils.ln)(1));}}function prepareOptionsToPrint(options){if(!options||!options.length)return[[],0];const optionsToPrint=[];let longest=0;for(const option of options){const nameWithAliases=option.aliases?[...option.aliases,option.name]:[option.name];const names=Array.from(new Set(nameWithAliases.map(name=>(0,_utils.transformOptionToArg)(name)))).join(", ");const defaultValue=(0,_utils.getDefaultValueFromSchema)(option.type);const placeholder=option.placeholder??" ";optionsToPrint.push({names,placeholder,description:option.description??option.type.description??"",default:typeof defaultValue!=="undefined"?`(default: ${JSON.stringify(defaultValue)})`:"",optional:option.type.isOptional()?"[optional]":"",example:option.example??""});const optLength=names.length+placeholder.length;if(optLength>longest)longest=optLength;}return[optionsToPrint,longest];}function prepareCommandsToPrint(subcommands){if(!subcommands||!subcommands.length)return[[],0];const commandsToPrint=[];let longest=0;for(const subcommand of subcommands){const{name,aliases,description}=subcommand;const names=Array.from(new Set([...(aliases??[]),name])).join(", ");const placeholder=subcommand.placeholder??(subcommand.options?"[options]":subcommand.allowPositional?"<args>":" ");commandsToPrint.push({names,placeholder,description:description??""});const cmdLength=names.length+placeholder.length;if(cmdLength>longest)longest=cmdLength;}return[commandsToPrint,longest];}function prepareArgumentsToPrint(args){if(!args||!args.length)return[[],0];const argsToPrint=[];let longest=0;for(const arg of args){const defaultValue=(0,_utils.getDefaultValueFromSchema)(arg.type);argsToPrint.push({names:arg.name,description:arg.description??"",default:typeof defaultValue!=="undefined"?`(default: ${JSON.stringify(defaultValue)})`:"",optional:arg.type.isOptional()?"[optional]":"",example:arg.example??""});const cmdLength=arg.name.length;if(cmdLength>longest)longest=cmdLength;}return[argsToPrint,longest];}function printPreparedOptions(optionsToPrint,c,longest){if(!optionsToPrint.length)return;(0,_utils.print)(c.title(" OPTIONS "));(0,_utils.println)();for(const{names,placeholder,description,example,optional,default:def}of optionsToPrint){const optLength=names.length+(placeholder?.length??0);const spacing=longest+1-optLength;const normalizeDesc=description.replace(/\n/g,"\n"+(0,_utils.indent)(longest+7)+c.punctuation("└"));const coloredNames=names.split(/(,)/).map(name=>name===","?c.punctuation(name):c.option(name)).join("");(0,_utils.println)((0,_utils.indent)(2),coloredNames,c.placeholder(placeholder),(0,_utils.indent)(spacing),c.description(normalizeDesc),def?c.default(def):c.optional(optional));if(example){const normalizeExample=example.replace(/\n/g,"\n"+(0,_utils.indent)(longest+17));(0,_utils.println)((0,_utils.indent)(longest+6),c.punctuation("└")+c.exampleTitle("Example:"),c.example(normalizeExample));}}(0,_utils.println)();}function printPreparedCommands(commandsToPrint,c,longest){if(!commandsToPrint.length)return;(0,_utils.print)(c.title(" COMMANDS "));(0,_utils.println)();for(const{names,placeholder,description}of commandsToPrint){const optLength=names.length+(placeholder?.length??0);const spacing=longest+1-optLength;const normalizeDesc=description.replace(/\n/g,"\n"+(0,_utils.indent)(longest+7));const coloredNames=names.split(/(,)/).map(name=>name===","?c.punctuation(name):c.command(name)).join("");(0,_utils.println)((0,_utils.indent)(2),coloredNames,c.placeholder(placeholder),(0,_utils.indent)(spacing),c.description(normalizeDesc));}(0,_utils.println)();}function printPreparedArguments(argsToPrint,c,longest){if(!argsToPrint.length)return;(0,_utils.print)(c.title(" ARGUMENTS "));(0,_utils.println)();for(const{names,description,example,optional,default:def}of argsToPrint){const spacing=longest+2-names.length;const normalizeDesc=description.replace(/\n/g,"\n"+(0,_utils.indent)(longest+6)+c.punctuation("└"));(0,_utils.println)((0,_utils.indent)(2),c.argument(names),(0,_utils.indent)(spacing),c.description(normalizeDesc),def?c.default(def):c.optional(optional));if(example){const normalizeExample=example.replace(/\n/g,"\n"+(0,_utils.indent)(longest+16));(0,_utils.println)((0,_utils.indent)(longest+5),c.punctuation("└")+c.exampleTitle("Example:"),c.example(normalizeExample));}}(0,_utils.println)();}const help=exports.help={printCliHelp,printSubcommandHelp};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.help=void 0;var _chalk=_interopRequireDefault(require("chalk"));var _utils=require("./utils.js");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e};}const colors={title:_chalk.default.bold.blue,description:_chalk.default.white,default:_chalk.default.dim.italic,optional:_chalk.default.dim.italic,exampleTitle:_chalk.default.yellow,example:_chalk.default.dim,command:_chalk.default.yellow,option:_chalk.default.cyan,argument:_chalk.default.green,placeholder:_chalk.default.hex("#FF9800"),punctuation:_chalk.default.white.dim};function printCliHelp(params){let printOptions=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};printOptions.colors??=true;const noColors=new Proxy(colors,{get:()=>{return function(){for(var _len=arguments.length,str=new Array(_len),_key=0;_key<_len;_key++){str[_key]=arguments[_key];}return str.join(" ");};}});const c=printOptions.colors?colors:noColors;if(printOptions.customColors){Object.assign(c,printOptions.customColors);}const isFirstParamCli="cliName"in params[0];const cliOptions=isFirstParamCli?params.shift():{};const subcommands=params;const printTitle=title=>{(0,_utils.print)(c.title(` ${title.toUpperCase()} `));};const cliName=cliOptions.cliName??"";const usage=cliOptions.usage??(0,_utils.concat)(c.punctuation("$"),cliName,subcommands.length?c.command("[command]"):"",cliOptions.options?.length?c.option("[options]"):"",cliOptions.arguments?.length||cliOptions.allowPositional?c.argument("<arguments>"):"");printTitle("Usage");(0,_utils.println)();(0,_utils.println)((0,_utils.indent)(2),usage,(0,_utils.ln)(1));if(cliOptions.description){printTitle("Description");(0,_utils.println)();(0,_utils.println)((0,_utils.indent)(2),c.description(cliOptions.description),(0,_utils.ln)(1));}let longest=0;const[optionsToPrint,longestOptionIndent]=prepareOptionsToPrint(cliOptions.options);if(longestOptionIndent>longest)longest=longestOptionIndent;const[commandsToPrint,longestSubcommandIndent]=prepareCommandsToPrint(subcommands);if(longestSubcommandIndent>longest)longest=longestSubcommandIndent;const[argsToPrint,longestArgIndent]=prepareArgumentsToPrint(cliOptions.arguments);if(longestArgIndent>longest)longest=longestArgIndent;printPreparedOptions(optionsToPrint,c,longest);printPreparedCommands(commandsToPrint,c,longest);printPreparedArguments(argsToPrint,c,longest);if(cliOptions.example){printTitle("Example");(0,_utils.println)();const normalizeExample=cliOptions.example.replace(/\n/g,"\n"+(0,_utils.indent)(3));(0,_utils.println)((0,_utils.indent)(2),c.example(normalizeExample),(0,_utils.ln)(1));}}function printSubcommandHelp(subcommand){let printOptions=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};let cliName=arguments.length>2&&arguments[2]!==undefined?arguments[2]:"";printOptions.colors??=true;const noColors=new Proxy(colors,{get:()=>{return function(){for(var _len2=arguments.length,str=new Array(_len2),_key2=0;_key2<_len2;_key2++){str[_key2]=arguments[_key2];}return str.join(" ");};}});const c=printOptions.colors?colors:noColors;if(printOptions.customColors){Object.assign(c,printOptions.customColors);}const printTitle=title=>{(0,_utils.print)(c.title(` ${title.toUpperCase()} `));};const usage=subcommand.usage??(0,_utils.concat)(c.punctuation("$"),cliName,c.command(subcommand.name),subcommand.options?.length?c.option("[options]"):"",subcommand.arguments?.length||subcommand.allowPositional?c.argument("<arguments>"):"");printTitle("Usage");(0,_utils.println)();(0,_utils.println)((0,_utils.indent)(2),usage,(0,_utils.ln)(1));if(subcommand.description){printTitle("Description");(0,_utils.println)();const normalizeDesc=subcommand.description.replace(/\n/g,"\n"+(0,_utils.indent)(3));(0,_utils.println)((0,_utils.indent)(2),c.description(normalizeDesc),(0,_utils.ln)(1));}let longest=0;const[optionsToPrint,longestOptionIndent]=prepareOptionsToPrint(subcommand.options);if(longestOptionIndent>longest)longest=longestOptionIndent;const[argsToPrint,longestArgIndent]=prepareArgumentsToPrint(subcommand.arguments);if(longestArgIndent>longest)longest=longestArgIndent;printPreparedOptions(optionsToPrint,c,longest);printPreparedArguments(argsToPrint,c,longest);if(subcommand.example){printTitle("Example");(0,_utils.println)();const normalizeExample=subcommand.example.replace(/\n/g,"\n"+(0,_utils.indent)(3));(0,_utils.println)((0,_utils.indent)(2),c.example(normalizeExample),(0,_utils.ln)(1));}}function prepareOptionsToPrint(options){if(!options||!options.length)return[[],0];const optionsToPrint=[];let longest=0;for(const option of options){const nameWithAliases=option.aliases?[...option.aliases,option.name]:[option.name];const names=Array.from(new Set(nameWithAliases.map(name=>(0,_utils.transformOptionToArg)(name)))).join(", ");const defaultValue=(0,_utils.getDefaultValueFromSchema)(option.type);const placeholder=option.placeholder??" ";optionsToPrint.push({names,placeholder,description:option.description??option.type.description??"",default:typeof defaultValue!=="undefined"?`(default: ${JSON.stringify(defaultValue)})`:"",optional:option.type.isOptional()?"[optional]":"",example:option.example??""});const optLength=names.length+placeholder.length;if(optLength>longest)longest=optLength;}return[optionsToPrint,longest];}function prepareCommandsToPrint(subcommands){if(!subcommands||!subcommands.length)return[[],0];const commandsToPrint=[];let longest=0;for(const subcommand of subcommands){const{name,aliases,description}=subcommand;const names=Array.from(new Set([...(aliases??[]),name])).join(", ");const placeholder=subcommand.placeholder??(subcommand.options?"[options]":subcommand.allowPositional?"<args>":" ");commandsToPrint.push({names,placeholder,description:description??""});const cmdLength=names.length+placeholder.length;if(cmdLength>longest)longest=cmdLength;}return[commandsToPrint,longest];}function prepareArgumentsToPrint(args){if(!args||!args.length)return[[],0];const argsToPrint=[];let longest=0;for(const arg of args){const defaultValue=(0,_utils.getDefaultValueFromSchema)(arg.type);argsToPrint.push({names:arg.name,description:arg.description??"",default:typeof defaultValue!=="undefined"?`(default: ${JSON.stringify(defaultValue)})`:"",optional:arg.type.isOptional()?"[optional]":"",example:arg.example??""});const cmdLength=arg.name.length;if(cmdLength>longest)longest=cmdLength;}return[argsToPrint,longest];}function printPreparedOptions(optionsToPrint,c,longest){if(!optionsToPrint.length)return;(0,_utils.print)(c.title(" OPTIONS "));(0,_utils.println)();for(const{names,placeholder,description,example,optional,default:def}of optionsToPrint){const optLength=names.length+(placeholder?.length??0);const spacing=longest+1-optLength;const normalizeDesc=description.replace(/\n/g,"\n"+(0,_utils.indent)(longest+7)+c.punctuation("└"));const coloredNames=names.split(/(,)/).map(name=>name===","?c.punctuation(name):c.option(name)).join("");(0,_utils.println)((0,_utils.indent)(2),coloredNames,c.placeholder(placeholder),(0,_utils.indent)(spacing),c.description(normalizeDesc),def?c.default(def):c.optional(optional));if(example){const normalizeExample=example.replace(/\n/g,"\n"+(0,_utils.indent)(longest+17));(0,_utils.println)((0,_utils.indent)(longest+6),c.punctuation("└")+c.exampleTitle("Example:"),c.example(normalizeExample));}}(0,_utils.println)();}function printPreparedCommands(commandsToPrint,c,longest){if(!commandsToPrint.length)return;(0,_utils.print)(c.title(" COMMANDS "));(0,_utils.println)();for(const{names,placeholder,description}of commandsToPrint){const optLength=names.length+(placeholder?.length??0);const spacing=longest+1-optLength;const normalizeDesc=description.replace(/\n/g,"\n"+(0,_utils.indent)(longest+7)+c.punctuation("└"));const coloredNames=names.split(/(,)/).map(name=>name===","?c.punctuation(name):c.command(name)).join("");(0,_utils.println)((0,_utils.indent)(2),coloredNames,c.placeholder(placeholder),(0,_utils.indent)(spacing),c.description(normalizeDesc));}(0,_utils.println)();}function printPreparedArguments(argsToPrint,c,longest){if(!argsToPrint.length)return;(0,_utils.print)(c.title(" ARGUMENTS "));(0,_utils.println)();for(const{names,description,example,optional,default:def}of argsToPrint){const spacing=longest+2-names.length;const normalizeDesc=description.replace(/\n/g,"\n"+(0,_utils.indent)(longest+6)+c.punctuation("└"));(0,_utils.println)((0,_utils.indent)(2),c.argument(names),(0,_utils.indent)(spacing),c.description(normalizeDesc),def?c.default(def):c.optional(optional));if(example){const normalizeExample=example.replace(/\n/g,"\n"+(0,_utils.indent)(longest+16));(0,_utils.println)((0,_utils.indent)(longest+5),c.punctuation("└")+c.exampleTitle("Example:"),c.example(normalizeExample));}}(0,_utils.println)();}const help=exports.help={printCliHelp,printSubcommandHelp};
@@ -1 +1 @@
1
- {"version":3,"names":["_chalk","_interopRequireDefault","require","_utils","e","__esModule","default","colors","title","chalk","bold","blue","description","white","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","print","toUpperCase","cliName","usage","concat","options","allowPositional","println","indent","ln","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","transformOptionToArg","defaultValue","getDefaultValueFromSchema","type","push","JSON","stringify","isOptional","optLength","cmdLength","args","arg","def","spacing","coloredNames","split","help","exports"],"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":"0FAAA,IAAAA,MAAA,CAAAC,sBAAA,CAAAC,OAAA,WACA,IAAAC,MAAA,CAAAD,OAAA,eAAiH,SAAAD,uBAAAG,CAAA,SAAAA,CAAA,EAAAA,CAAA,CAAAC,UAAA,CAAAD,CAAA,EAAAE,OAAA,CAAAF,CAAA,GAKjH,KAAM,CAAAG,MAA2D,CAAG,CAClEC,KAAK,CAAEC,cAAK,CAACC,IAAI,CAACC,IAAI,CACtBC,WAAW,CAAEH,cAAK,CAACI,KAAK,CACxBP,OAAO,CAAEG,cAAK,CAACK,GAAG,CAACC,MAAM,CACzBC,QAAQ,CAAEP,cAAK,CAACK,GAAG,CAACC,MAAM,CAC1BE,YAAY,CAAER,cAAK,CAACS,MAAM,CAC1BC,OAAO,CAAEV,cAAK,CAACK,GAAG,CAACC,MAAM,CACzBK,OAAO,CAAEX,cAAK,CAACS,MAAM,CACrBG,MAAM,CAAEZ,cAAK,CAACa,IAAI,CAClBC,QAAQ,CAAEd,cAAK,CAACe,KAAK,CACrBC,WAAW,CAAEhB,cAAK,CAACiB,GAAG,CAAC,SAAS,CAAC,CACjCC,WAAW,CAAElB,cAAK,CAACI,KAAK,CAACC,GAC3B,CAAC,CAWD,QAAS,CAAAc,YAAYA,CAACC,MAA8B,CAAmC,IAAjC,CAAAC,YAA0B,CAAAC,SAAA,CAAAC,MAAA,IAAAD,SAAA,MA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AgB,CAAC,CAAC,CAC5G,CACF,CAEA,GAAAhB,cAAO,EAAC,CAAC,CACX,CAEO,KAAM,CAAA8C,IAAI,CAAAC,OAAA,CAAAD,IAAA,CAAG,CAClB5E,YAAY,CACZgD,mBACF,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_chalk","_interopRequireDefault","require","_utils","e","__esModule","default","colors","title","chalk","bold","blue","description","white","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","print","toUpperCase","cliName","usage","concat","options","allowPositional","println","indent","ln","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","transformOptionToArg","defaultValue","getDefaultValueFromSchema","type","push","JSON","stringify","isOptional","optLength","cmdLength","args","arg","def","spacing","coloredNames","split","help","exports"],"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":"0FAAA,IAAAA,MAAA,CAAAC,sBAAA,CAAAC,OAAA,WACA,IAAAC,MAAA,CAAAD,OAAA,eAAiH,SAAAD,uBAAAG,CAAA,SAAAA,CAAA,EAAAA,CAAA,CAAAC,UAAA,CAAAD,CAAA,EAAAE,OAAA,CAAAF,CAAA,GAIjH,KAAM,CAAAG,MAA2D,CAAG,CAClEC,KAAK,CAAEC,cAAK,CAACC,IAAI,CAACC,IAAI,CACtBC,WAAW,CAAEH,cAAK,CAACI,KAAK,CACxBP,OAAO,CAAEG,cAAK,CAACK,GAAG,CAACC,MAAM,CACzBC,QAAQ,CAAEP,cAAK,CAACK,GAAG,CAACC,MAAM,CAC1BE,YAAY,CAAER,cAAK,CAACS,MAAM,CAC1BC,OAAO,CAAEV,cAAK,CAACK,GAAG,CAClBM,OAAO,CAAEX,cAAK,CAACS,MAAM,CACrBG,MAAM,CAAEZ,cAAK,CAACa,IAAI,CAClBC,QAAQ,CAAEd,cAAK,CAACe,KAAK,CACrBC,WAAW,CAAEhB,cAAK,CAACiB,GAAG,CAAC,SAAS,CAAC,CACjCC,WAAW,CAAElB,cAAK,CAACI,KAAK,CAACC,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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,CAAC,CAC5G,CACF,CAEA,GAAAhB,cAAO,EAAC,CAAC,CACX,CAEO,KAAM,CAAA8C,IAAI,CAAAC,OAAA,CAAAD,IAAA,CAAG,CAClB5E,YAAY,CACZgD,mBACF,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.parse=parse;exports.safeParse=safeParse;var _help=require("./help.js");var _utils=require("./utils.js");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=(0,_utils.decoupleFlags)(argsv);const results={subcommand:undefined,printCliHelp(opt){_help.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.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((0,_utils.isOptionArg)(argument)){if((0,_utils.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=(0,_utils.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&&(0,_utils.noName)(o.name)===optionName)return true;if(!o.aliases)return false;if(o.aliases.includes(optionName))return true;if(isNegative&&o.aliases.map(_utils.noName).includes(optionName))return true;return false;});if(!option){throw new Error(`Unknown option: "${argument}"`);}const isTypeBoolean=(0,_utils.isBooleanSchema)(option.type);const nextArg=argsv[i+1];let optionValue=argWithEquals?argValue:nextArg;if(isTypeBoolean){if(argWithEquals){const parsedBoolean=(0,_utils.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&&(0,_utils.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=(0,_utils.isBooleanSchema)(argType);if(isTypeBoolean)argValue=(0,_utils.stringToBoolean)(argValue);const res=argType.safeParse(argValue);if(!res.success){throw new Error(`The ${(0,_utils.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: ${(0,_utils.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 ${(0,_utils.getOrdinalPlacement)(i)} argument is required: "${subcommandProps.arguments[i].name}"`);}}}if(subcommandProps?.action){subcommandProps.action(results);}return results;}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.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.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
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.parse=parse;exports.safeParse=safeParse;var _help=require("./help.js");var _utils=require("./utils.js");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=(0,_utils.decoupleFlags)(argsv);const results={subcommand:undefined,printCliHelp(opt){_help.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.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((0,_utils.isOptionArg)(argument)){if((0,_utils.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=(0,_utils.transformArg)(argument);const isNegative=argument.startsWith("--no-");const option=subcommandProps.options.find(o=>{if(o.name===optionName)return true;if(isNegative&&(0,_utils.noName)(o.name)===optionName)return true;if(!o.aliases)return false;if(o.aliases.includes(optionName))return true;if(isNegative&&o.aliases.map(_utils.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=(0,_utils.isBooleanSchema)(option.type);const nextArg=argsv[i+1];let optionValue=argWithEquals?argValue:nextArg;if(isTypeBoolean){if(argWithEquals){const parsedBoolean=(0,_utils.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&&(0,_utils.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=(0,_utils.isBooleanSchema)(argType);if(isTypeBoolean)argValue=(0,_utils.stringToBoolean)(argValue);const res=argType.safeParse(argValue);if(!res.success){throw new Error(`The ${(0,_utils.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: ${(0,_utils.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 ${(0,_utils.getOrdinalPlacement)(i)} argument is required: "${subcommandProps.arguments[i].name}"`);}}}if(subcommandProps?.action){subcommandProps.action(results);}return results;}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.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.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","require","_utils","parse","argsv","_len","arguments","length","params","Array","_key","cliOptions","subcommandArr","allSubcommands","Set","flatMap","c","name","aliases","decoupleFlags","results","subcommand","undefined","printCliHelp","opt","help","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","isOptionArg","isFlagArg","Error","options","msg","transformArg","isNegative","startsWith","option","o","noName","map","isTypeBoolean","isBooleanSchema","type","nextArg","optionValue","parsedBoolean","stringToBoolean","res","safeParse","success","errors","message","data","rawVal","currentArgCount","argType","getOrdinalPlacement","push","isOptional","hasDefault","_def","defaultValue","transformOptionToArg","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":"sHAAA,IAAAA,KAAA,CAAAC,OAAA,cACA,IAAAC,MAAA,CAAAD,OAAA,eA4BO,QAAS,CAAAE,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,CAAC,CAAC,CAAC,CAAGA,MAAM,CAAC,CAAC,CAAC,CAAG,CAAC,CAAO,CACjE,KAAM,CAAAI,aAAa,CAAGJ,MAAsB,CAC5C,KAAM,CAAAK,cAAc,CAAG,GAAI,CAAAC,GAAG,CAASF,aAAa,CAACG,OAAO,CAACC,CAAC,EAAI,CAACA,CAAC,CAACC,IAAI,CAAE,IAAID,CAAC,CAACE,OAAO,EAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAGlGd,KAAK,CAAG,GAAAe,oBAAa,EAACf,KAAK,CAAC,CAW5B,KAAM,CAAAgB,OAAkB,CAAG,CACzBC,UAAU,CAAEC,SAAS,CACrBC,YAAYA,CAACC,GAAG,CAAE,CAChBC,UAAI,CAACF,YAAY,CAACf,MAAM,CAAEgB,GAAG,CAAC,CAChC,CAAC,CACDE,mBAAmBA,CAACC,aAAa,CAAEH,GAAG,CAAE,CACtC,KAAM,CAAAH,UAAU,CAAGT,aAAa,CAACgB,IAAI,CAACZ,CAAC,E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gB,IAAI,CAACZ,CAAC,EAAIA,CAAC,CAACC,IAAI,GAAKU,aAAa,CAAC,CACpE,GAAI,CAACN,UAAU,CAAE,MAAO,CAAAQ,OAAO,CAACC,KAAK,CAAC,qCAAqCH,aAAa,wBAAwB,CAAC,CACjHF,UAAI,CAACC,mBAAmB,CAACL,UAAU,CAAEG,GAAG,CAAEb,UAAU,CAACoB,OAAO,CAAC,CAC/D,CAAC,CAED,GAAI,CACF,KAAM,CAAAoD,IAAI,CAAGhF,KAAK,CAACC,KAAK,CAAE,GAAGI,MAAM,CAAC,CAEpC,MAAO,CAAA2E,IAAI,CAAC5D,YAAY,CAExB,MAAO,CAAA4D,IAAI,CAACzD,mBAAmB,CAE/B,MAAO,CACLsD,OAAO,CAAE,IAAI,CACbG,IAAI,CAAEA,IAAiE,CACvE5D,YAAY,CACZG,mBACF,CAAC,CACH,CAAE,MAAOyE,CAAC,CAAE,CACV,MAAO,CAAEnB,OAAO,CAAE,KAAK,CAAElD,KAAK,CAAEqE,CAAU,CAAE5E,YAAY,CAAEG,mBAAoB,CAAC,CACjF,CACF","ignoreList":[]}
1
+ {"version":3,"names":["_help","require","_utils","parse","argsv","_len","arguments","length","params","Array","_key","cliOptions","subcommandArr","allSubcommands","Set","flatMap","c","name","aliases","decoupleFlags","results","subcommand","undefined","printCliHelp","opt","help","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","isOptionArg","isFlagArg","Error","options","msg","transformArg","isNegative","startsWith","option","o","noName","map","isTypeBoolean","isBooleanSchema","type","nextArg","optionValue","parsedBoolean","stringToBoolean","res","safeParse","success","errors","message","data","rawVal","currentArgCount","argType","getOrdinalPlacement","push","isOptional","hasDefault","_def","defaultValue","transformOptionToArg","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":"sHAAA,IAAAA,KAAA,CAAAC,OAAA,cACA,IAAAC,MAAA,CAAAD,OAAA,eA4BO,QAAS,CAAAE,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,CAAC,CAAC,CAAC,CAAGA,MAAM,CAAC,CAAC,CAAC,CAAG,CAAC,CAAO,CACjE,KAAM,CAAAI,aAAa,CAAGJ,MAAsB,CAC5C,KAAM,CAAAK,cAAc,CAAG,GAAI,CAAAC,GAAG,CAASF,aAAa,CAACG,OAAO,CAACC,CAAC,EAAI,CAACA,CAAC,CAACC,IAAI,CAAE,IAAID,CAAC,CAACE,OAAO,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AAA6E,IAAI,CAAC9D,YAAY,CAExB,MAAO,CAAA8D,IAAI,CAAC3D,mBAAmB,CAE/B,MAAO,CACLwD,OAAO,CAAE,IAAI,CACbG,IAAI,CAAEA,IAAiE,CACvE9D,YAAY,CACZG,mBACF,CAAC,CACH,CAAE,MAAO2E,CAAC,CAAE,CACV,MAAO,CAAEnB,OAAO,CAAE,KAAK,CAAEnD,KAAK,CAAEsE,CAAU,CAAE9E,YAAY,CAAEG,mBAAoB,CAAC,CACjF,CACF","ignoreList":[]}
@@ -1 +1 @@
1
- import chalk from"chalk";import{concat,getDefaultValueFromSchema,indent,ln,print,println,transformOptionToArg}from"./utils.js";const colors={title:chalk.bold.blue,description:chalk.white,default:chalk.dim.italic,optional:chalk.dim.italic,exampleTitle:chalk.yellow,example:chalk.dim.italic,command:chalk.yellow,option:chalk.cyan,argument:chalk.green,placeholder:chalk.hex("#FF9800"),punctuation:chalk.white.dim};function printCliHelp(params){let printOptions=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};printOptions.colors??=true;const noColors=new Proxy(colors,{get:()=>{return function(){for(var _len=arguments.length,str=new Array(_len),_key=0;_key<_len;_key++){str[_key]=arguments[_key];}return str.join(" ");};}});const c=printOptions.colors?colors:noColors;if(printOptions.customColors){Object.assign(c,printOptions.customColors);}const isFirstParamCli="cliName"in params[0];const cliOptions=isFirstParamCli?params.shift():{};const subcommands=params;const printTitle=title=>{print(c.title(` ${title.toUpperCase()} `));};const cliName=cliOptions.cliName??"";const usage=cliOptions.usage??concat(c.punctuation("$"),cliName,subcommands.length?c.command("[command]"):"",cliOptions.options?.length?c.option("[options]"):"",cliOptions.arguments?.length||cliOptions.allowPositional?c.argument("<arguments>"):"");printTitle("Usage");println();println(indent(2),usage,ln(1));if(cliOptions.description){printTitle("Description");println();println(indent(2),c.description(cliOptions.description),ln(1));}let longest=0;const[optionsToPrint,longestOptionIndent]=prepareOptionsToPrint(cliOptions.options);if(longestOptionIndent>longest)longest=longestOptionIndent;const[commandsToPrint,longestSubcommandIndent]=prepareCommandsToPrint(subcommands);if(longestSubcommandIndent>longest)longest=longestSubcommandIndent;const[argsToPrint,longestArgIndent]=prepareArgumentsToPrint(cliOptions.arguments);if(longestArgIndent>longest)longest=longestArgIndent;printPreparedOptions(optionsToPrint,c,longest);printPreparedCommands(commandsToPrint,c,longest);printPreparedArguments(argsToPrint,c,longest);if(cliOptions.example){printTitle("Example");println();const normalizeExample=cliOptions.example.replace(/\n/g,"\n"+indent(3));println(indent(2),c.example(normalizeExample),ln(1));}}function printSubcommandHelp(subcommand){let printOptions=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};let cliName=arguments.length>2&&arguments[2]!==undefined?arguments[2]:"";printOptions.colors??=true;const noColors=new Proxy(colors,{get:()=>{return function(){for(var _len2=arguments.length,str=new Array(_len2),_key2=0;_key2<_len2;_key2++){str[_key2]=arguments[_key2];}return str.join(" ");};}});const c=printOptions.colors?colors:noColors;if(printOptions.customColors){Object.assign(c,printOptions.customColors);}const printTitle=title=>{print(c.title(` ${title.toUpperCase()} `));};const usage=concat(c.punctuation("$"),cliName,c.command(subcommand.name),subcommand.options?.length?c.option("[options]"):"",subcommand.arguments?.length||subcommand.allowPositional?c.argument("<arguments>"):"");printTitle("Usage");println();println(indent(2),usage,ln(1));if(subcommand.description){printTitle("Description");println();const normalizeDesc=subcommand.description.replace(/\n/g,"\n"+indent(3));println(indent(2),c.description(normalizeDesc),ln(1));}let longest=0;const[optionsToPrint,longestOptionIndent]=prepareOptionsToPrint(subcommand.options);if(longestOptionIndent>longest)longest=longestOptionIndent;const[argsToPrint,longestArgIndent]=prepareArgumentsToPrint(subcommand.arguments);if(longestArgIndent>longest)longest=longestArgIndent;printPreparedOptions(optionsToPrint,c,longest);printPreparedArguments(argsToPrint,c,longest);if(subcommand.example){printTitle("Example");println();const normalizeExample=subcommand.example.replace(/\n/g,"\n"+indent(3));println(indent(2),c.example(normalizeExample),ln(1));}}function prepareOptionsToPrint(options){if(!options||!options.length)return[[],0];const optionsToPrint=[];let longest=0;for(const option of options){const nameWithAliases=option.aliases?[...option.aliases,option.name]:[option.name];const names=Array.from(new Set(nameWithAliases.map(name=>transformOptionToArg(name)))).join(", ");const defaultValue=getDefaultValueFromSchema(option.type);const placeholder=option.placeholder??" ";optionsToPrint.push({names,placeholder,description:option.description??option.type.description??"",default:typeof defaultValue!=="undefined"?`(default: ${JSON.stringify(defaultValue)})`:"",optional:option.type.isOptional()?"[optional]":"",example:option.example??""});const optLength=names.length+placeholder.length;if(optLength>longest)longest=optLength;}return[optionsToPrint,longest];}function prepareCommandsToPrint(subcommands){if(!subcommands||!subcommands.length)return[[],0];const commandsToPrint=[];let longest=0;for(const subcommand of subcommands){const{name,aliases,description}=subcommand;const names=Array.from(new Set([...(aliases??[]),name])).join(", ");const placeholder=subcommand.placeholder??(subcommand.options?"[options]":subcommand.allowPositional?"<args>":" ");commandsToPrint.push({names,placeholder,description:description??""});const cmdLength=names.length+placeholder.length;if(cmdLength>longest)longest=cmdLength;}return[commandsToPrint,longest];}function prepareArgumentsToPrint(args){if(!args||!args.length)return[[],0];const argsToPrint=[];let longest=0;for(const arg of args){const defaultValue=getDefaultValueFromSchema(arg.type);argsToPrint.push({names:arg.name,description:arg.description??"",default:typeof defaultValue!=="undefined"?`(default: ${JSON.stringify(defaultValue)})`:"",optional:arg.type.isOptional()?"[optional]":"",example:arg.example??""});const cmdLength=arg.name.length;if(cmdLength>longest)longest=cmdLength;}return[argsToPrint,longest];}function printPreparedOptions(optionsToPrint,c,longest){if(!optionsToPrint.length)return;print(c.title(" OPTIONS "));println();for(const{names,placeholder,description,example,optional,default:def}of optionsToPrint){const optLength=names.length+(placeholder?.length??0);const spacing=longest+1-optLength;const normalizeDesc=description.replace(/\n/g,"\n"+indent(longest+7)+c.punctuation("└"));const coloredNames=names.split(/(,)/).map(name=>name===","?c.punctuation(name):c.option(name)).join("");println(indent(2),coloredNames,c.placeholder(placeholder),indent(spacing),c.description(normalizeDesc),def?c.default(def):c.optional(optional));if(example){const normalizeExample=example.replace(/\n/g,"\n"+indent(longest+17));println(indent(longest+6),c.punctuation("└")+c.exampleTitle("Example:"),c.example(normalizeExample));}}println();}function printPreparedCommands(commandsToPrint,c,longest){if(!commandsToPrint.length)return;print(c.title(" COMMANDS "));println();for(const{names,placeholder,description}of commandsToPrint){const optLength=names.length+(placeholder?.length??0);const spacing=longest+1-optLength;const normalizeDesc=description.replace(/\n/g,"\n"+indent(longest+7));const coloredNames=names.split(/(,)/).map(name=>name===","?c.punctuation(name):c.command(name)).join("");println(indent(2),coloredNames,c.placeholder(placeholder),indent(spacing),c.description(normalizeDesc));}println();}function printPreparedArguments(argsToPrint,c,longest){if(!argsToPrint.length)return;print(c.title(" ARGUMENTS "));println();for(const{names,description,example,optional,default:def}of argsToPrint){const spacing=longest+2-names.length;const normalizeDesc=description.replace(/\n/g,"\n"+indent(longest+6)+c.punctuation("└"));println(indent(2),c.argument(names),indent(spacing),c.description(normalizeDesc),def?c.default(def):c.optional(optional));if(example){const normalizeExample=example.replace(/\n/g,"\n"+indent(longest+16));println(indent(longest+5),c.punctuation("└")+c.exampleTitle("Example:"),c.example(normalizeExample));}}println();}export const help={printCliHelp,printSubcommandHelp};
1
+ import chalk from"chalk";import{concat,getDefaultValueFromSchema,indent,ln,print,println,transformOptionToArg}from"./utils.js";const colors={title:chalk.bold.blue,description:chalk.white,default:chalk.dim.italic,optional:chalk.dim.italic,exampleTitle:chalk.yellow,example:chalk.dim,command:chalk.yellow,option:chalk.cyan,argument:chalk.green,placeholder:chalk.hex("#FF9800"),punctuation:chalk.white.dim};function printCliHelp(params){let printOptions=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};printOptions.colors??=true;const noColors=new Proxy(colors,{get:()=>{return function(){for(var _len=arguments.length,str=new Array(_len),_key=0;_key<_len;_key++){str[_key]=arguments[_key];}return str.join(" ");};}});const c=printOptions.colors?colors:noColors;if(printOptions.customColors){Object.assign(c,printOptions.customColors);}const isFirstParamCli="cliName"in params[0];const cliOptions=isFirstParamCli?params.shift():{};const subcommands=params;const printTitle=title=>{print(c.title(` ${title.toUpperCase()} `));};const cliName=cliOptions.cliName??"";const usage=cliOptions.usage??concat(c.punctuation("$"),cliName,subcommands.length?c.command("[command]"):"",cliOptions.options?.length?c.option("[options]"):"",cliOptions.arguments?.length||cliOptions.allowPositional?c.argument("<arguments>"):"");printTitle("Usage");println();println(indent(2),usage,ln(1));if(cliOptions.description){printTitle("Description");println();println(indent(2),c.description(cliOptions.description),ln(1));}let longest=0;const[optionsToPrint,longestOptionIndent]=prepareOptionsToPrint(cliOptions.options);if(longestOptionIndent>longest)longest=longestOptionIndent;const[commandsToPrint,longestSubcommandIndent]=prepareCommandsToPrint(subcommands);if(longestSubcommandIndent>longest)longest=longestSubcommandIndent;const[argsToPrint,longestArgIndent]=prepareArgumentsToPrint(cliOptions.arguments);if(longestArgIndent>longest)longest=longestArgIndent;printPreparedOptions(optionsToPrint,c,longest);printPreparedCommands(commandsToPrint,c,longest);printPreparedArguments(argsToPrint,c,longest);if(cliOptions.example){printTitle("Example");println();const normalizeExample=cliOptions.example.replace(/\n/g,"\n"+indent(3));println(indent(2),c.example(normalizeExample),ln(1));}}function printSubcommandHelp(subcommand){let printOptions=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};let cliName=arguments.length>2&&arguments[2]!==undefined?arguments[2]:"";printOptions.colors??=true;const noColors=new Proxy(colors,{get:()=>{return function(){for(var _len2=arguments.length,str=new Array(_len2),_key2=0;_key2<_len2;_key2++){str[_key2]=arguments[_key2];}return str.join(" ");};}});const c=printOptions.colors?colors:noColors;if(printOptions.customColors){Object.assign(c,printOptions.customColors);}const printTitle=title=>{print(c.title(` ${title.toUpperCase()} `));};const usage=subcommand.usage??concat(c.punctuation("$"),cliName,c.command(subcommand.name),subcommand.options?.length?c.option("[options]"):"",subcommand.arguments?.length||subcommand.allowPositional?c.argument("<arguments>"):"");printTitle("Usage");println();println(indent(2),usage,ln(1));if(subcommand.description){printTitle("Description");println();const normalizeDesc=subcommand.description.replace(/\n/g,"\n"+indent(3));println(indent(2),c.description(normalizeDesc),ln(1));}let longest=0;const[optionsToPrint,longestOptionIndent]=prepareOptionsToPrint(subcommand.options);if(longestOptionIndent>longest)longest=longestOptionIndent;const[argsToPrint,longestArgIndent]=prepareArgumentsToPrint(subcommand.arguments);if(longestArgIndent>longest)longest=longestArgIndent;printPreparedOptions(optionsToPrint,c,longest);printPreparedArguments(argsToPrint,c,longest);if(subcommand.example){printTitle("Example");println();const normalizeExample=subcommand.example.replace(/\n/g,"\n"+indent(3));println(indent(2),c.example(normalizeExample),ln(1));}}function prepareOptionsToPrint(options){if(!options||!options.length)return[[],0];const optionsToPrint=[];let longest=0;for(const option of options){const nameWithAliases=option.aliases?[...option.aliases,option.name]:[option.name];const names=Array.from(new Set(nameWithAliases.map(name=>transformOptionToArg(name)))).join(", ");const defaultValue=getDefaultValueFromSchema(option.type);const placeholder=option.placeholder??" ";optionsToPrint.push({names,placeholder,description:option.description??option.type.description??"",default:typeof defaultValue!=="undefined"?`(default: ${JSON.stringify(defaultValue)})`:"",optional:option.type.isOptional()?"[optional]":"",example:option.example??""});const optLength=names.length+placeholder.length;if(optLength>longest)longest=optLength;}return[optionsToPrint,longest];}function prepareCommandsToPrint(subcommands){if(!subcommands||!subcommands.length)return[[],0];const commandsToPrint=[];let longest=0;for(const subcommand of subcommands){const{name,aliases,description}=subcommand;const names=Array.from(new Set([...(aliases??[]),name])).join(", ");const placeholder=subcommand.placeholder??(subcommand.options?"[options]":subcommand.allowPositional?"<args>":" ");commandsToPrint.push({names,placeholder,description:description??""});const cmdLength=names.length+placeholder.length;if(cmdLength>longest)longest=cmdLength;}return[commandsToPrint,longest];}function prepareArgumentsToPrint(args){if(!args||!args.length)return[[],0];const argsToPrint=[];let longest=0;for(const arg of args){const defaultValue=getDefaultValueFromSchema(arg.type);argsToPrint.push({names:arg.name,description:arg.description??"",default:typeof defaultValue!=="undefined"?`(default: ${JSON.stringify(defaultValue)})`:"",optional:arg.type.isOptional()?"[optional]":"",example:arg.example??""});const cmdLength=arg.name.length;if(cmdLength>longest)longest=cmdLength;}return[argsToPrint,longest];}function printPreparedOptions(optionsToPrint,c,longest){if(!optionsToPrint.length)return;print(c.title(" OPTIONS "));println();for(const{names,placeholder,description,example,optional,default:def}of optionsToPrint){const optLength=names.length+(placeholder?.length??0);const spacing=longest+1-optLength;const normalizeDesc=description.replace(/\n/g,"\n"+indent(longest+7)+c.punctuation("└"));const coloredNames=names.split(/(,)/).map(name=>name===","?c.punctuation(name):c.option(name)).join("");println(indent(2),coloredNames,c.placeholder(placeholder),indent(spacing),c.description(normalizeDesc),def?c.default(def):c.optional(optional));if(example){const normalizeExample=example.replace(/\n/g,"\n"+indent(longest+17));println(indent(longest+6),c.punctuation("└")+c.exampleTitle("Example:"),c.example(normalizeExample));}}println();}function printPreparedCommands(commandsToPrint,c,longest){if(!commandsToPrint.length)return;print(c.title(" COMMANDS "));println();for(const{names,placeholder,description}of commandsToPrint){const optLength=names.length+(placeholder?.length??0);const spacing=longest+1-optLength;const normalizeDesc=description.replace(/\n/g,"\n"+indent(longest+7)+c.punctuation("└"));const coloredNames=names.split(/(,)/).map(name=>name===","?c.punctuation(name):c.command(name)).join("");println(indent(2),coloredNames,c.placeholder(placeholder),indent(spacing),c.description(normalizeDesc));}println();}function printPreparedArguments(argsToPrint,c,longest){if(!argsToPrint.length)return;print(c.title(" ARGUMENTS "));println();for(const{names,description,example,optional,default:def}of argsToPrint){const spacing=longest+2-names.length;const normalizeDesc=description.replace(/\n/g,"\n"+indent(longest+6)+c.punctuation("└"));println(indent(2),c.argument(names),indent(spacing),c.description(normalizeDesc),def?c.default(def):c.optional(optional));if(example){const normalizeExample=example.replace(/\n/g,"\n"+indent(longest+16));println(indent(longest+5),c.punctuation("└")+c.exampleTitle("Example:"),c.example(normalizeExample));}}println();}export const help={printCliHelp,printSubcommandHelp};
@@ -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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AAC,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,CAACC,MAAM,CACzBC,QAAQ,CAAEjB,KAAK,CAACe,GAAG,CAACC,MAAM,CAC1BE,YAAY,CAAElB,KAAK,CAACmB,MAAM,CAC1BC,OAAO,CAAEpB,KAAK,CAACe,GAAG,CAClBM,OAAO,CAAEr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AC,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{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,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EZ,UAAU,CAACkB,OAAO,CAAC,CAC/D,CAAC,CAED,GAAI,CACF,KAAM,CAAA8C,IAAI,CAAGxE,KAAK,CAACC,KAAK,CAAE,GAAGI,MAAM,CAAC,CAEpC,MAAO,CAAAmE,IAAI,CAACrD,YAAY,CAExB,MAAO,CAAAqD,IAAI,CAACnD,mBAAmB,CAE/B,MAAO,CACLgD,OAAO,CAAE,IAAI,CACbG,IAAI,CAAEA,IAAiE,CACvErD,YAAY,CACZE,mBACF,CAAC,CACH,CAAE,MAAOiE,CAAC,CAAE,CACV,MAAO,CAAEjB,OAAO,CAAE,KAAK,CAAE5C,KAAK,CAAE6D,CAAU,CAAEnE,YAAY,CAAEE,mBAAoB,CAAC,CACjF,CACF","ignoreList":[]}
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","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,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,CAAC,CAAC,CAAC,CAAGA,MAAM,CAAC,CAAC,CAAC,CAAG,CAAC,CAAO,CACjE,KAAM,CAAAI,aAAa,CAAGJ,MAAsB,CAC5C,KAAM,CAAAK,cAAc,CAAG,GAAI,CAAAC,GAAG,CAASF,aAAa,CAACG,OAAO,CAACC,CAAC,EAAI,CAACA,CAAC,CAACC,IAAI,CAAE,IAAID,CAAC,CAACE,OAAO,EAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAGlGd,KAAK,CAAGV,aAAa,CAACU,KAAK,CAAC,CAW5B,KAAM,CAAAe,OAAkB,CAAG,CACzBC,UAAU,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AAE,CACV,MAAO,CAAEjB,OAAO,CAAE,KAAK,CAAE7C,KAAK,CAAE8D,CAAU,CAAErE,YAAY,CAAEE,mBAAoB,CAAC,CACjF,CACF","ignoreList":[]}
@@ -1 +1 @@
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;AA0BlF,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,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 +1 @@
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,CA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,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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AAC,KAAK,CAAC,SAAS,CAAC,SAAS,MAAM,EAAE,GAAG,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,wBAAwB,CAAC,IAAI,CAAC,CAAC,GAClH,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,SAAS,MAAM,EAAE,GAAG,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,CAAC,GACjF,EAAE,CAAC;AAEP;;;GAGG;AACH,KAAK,iBAAiB,CAAC,KAAK,SAAS,GAAG,EAAE,IAAI,KAAK,SAAS,CAAC,MAAM,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,GACnF,IAAI,SAAS,GAAG,EAAE,GAChB,IAAI,SAAS,IAAI,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,6 +1,6 @@
1
1
  {
2
2
  "name": "zod-args-parser",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "A strictly typed command-line arguments parser powered by Zod.",
5
5
  "author": "Ahmed ALABSI <alabsi91@gmail>",
6
6
  "license": "MIT",
@@ -10,7 +10,7 @@
10
10
  },
11
11
  "type": "module",
12
12
  "scripts": {
13
- "dev": "tsx watch src/test.ts",
13
+ "dev": "tsx watch example/cli.ts",
14
14
  "build": "node scripts/build.mjs",
15
15
  "test": "eslint src/** --fix && tsc --noEmit && tsx test/test.ts",
16
16
  "prepare": "npm run test && npm run build"
@@ -46,6 +46,7 @@
46
46
  "@babel/core": "^7.26.0",
47
47
  "@babel/preset-env": "^7.26.0",
48
48
  "@babel/preset-typescript": "^7.26.0",
49
+ "@eslint/compat": "^1.2.3",
49
50
  "@eslint/js": "^9.14.0",
50
51
  "@types/babel__core": "^7.20.5",
51
52
  "@types/node": "^22.9.0",
@@ -60,4 +61,4 @@
60
61
  "typescript": "^5.6.3",
61
62
  "typescript-eslint": "^8.14.0"
62
63
  }
63
- }
64
+ }
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/parser.ts CHANGED
@@ -50,12 +50,27 @@ export function parse<T extends Subcommand[], U extends Cli>(argsv: string[], ..
50
50
  help.printCliHelp(params, opt);
51
51
  },
52
52
  printSubcommandHelp(subcommandStr, opt) {
53
- const subcommand = subcommandArr.find(c => c.name === subcommandStr);
53
+ const subcommand = subcommandArr.find(c => {
54
+ if (c.name === subcommandStr) return true;
55
+ if (!subcommandStr) return false;
56
+ if (!c.aliases?.length) return false;
57
+ return c.aliases.includes(subcommandStr);
58
+ });
54
59
  if (!subcommand) return console.error(`Cannot print help for subcommand "${subcommandStr}" as it does not exist`);
55
60
  help.printSubcommandHelp(subcommand, opt, cliOptions.cliName);
56
61
  },
57
62
  };
58
63
 
64
+ /** - Get current subcommand props */
65
+ const GetSubcommandProps = (cmd = results.subcommand) => {
66
+ return subcommandArr.find(c => {
67
+ if (c.name === cmd) return true;
68
+ if (!cmd) return false;
69
+ if (!c.aliases?.length) return false;
70
+ return c.aliases.includes(cmd);
71
+ });
72
+ };
73
+
59
74
  const addRawArg = (optionName: string, rawArg: string) => {
60
75
  if (!results._info) results._info = {};
61
76
  if (!results._info[optionName]) results._info[optionName] = Object.create({});
@@ -88,7 +103,7 @@ export function parse<T extends Subcommand[], U extends Cli>(argsv: string[], ..
88
103
  results.subcommand = allSubcommands.has(arg) ? arg : undefined;
89
104
 
90
105
  // add positional and arguments array
91
- const subcommandProps = subcommandArr.find(c => c.name === results.subcommand);
106
+ const subcommandProps = GetSubcommandProps();
92
107
  if (subcommandProps?.allowPositional) results.positional = [];
93
108
  if (subcommandProps?.arguments?.length) results.arguments = [];
94
109
 
@@ -106,7 +121,7 @@ export function parse<T extends Subcommand[], U extends Cli>(argsv: string[], ..
106
121
  throw new Error(`Flag arguments cannot be assigned using "=": "${arg}"`);
107
122
  }
108
123
 
109
- const subcommandProps = subcommandArr.find(c => c.name === results.subcommand);
124
+ const subcommandProps = GetSubcommandProps();
110
125
  if (!subcommandProps) throw new Error(`Unknown subcommand: "${results.subcommand}"`);
111
126
 
112
127
  if (!subcommandProps.options) {
@@ -117,8 +132,6 @@ export function parse<T extends Subcommand[], U extends Cli>(argsv: string[], ..
117
132
  }
118
133
 
119
134
  const optionName = transformArg(argument);
120
- if (optionName in results) throw new Error(`Duplicate option: "${argument}"`);
121
-
122
135
  const isNegative = argument.startsWith("--no-");
123
136
 
124
137
  const option = subcommandProps.options.find(o => {
@@ -136,6 +149,10 @@ export function parse<T extends Subcommand[], U extends Cli>(argsv: string[], ..
136
149
  throw new Error(`Unknown option: "${argument}"`);
137
150
  }
138
151
 
152
+ if (option.name in results) {
153
+ throw new Error(`Duplicated option: "${argument}"`);
154
+ }
155
+
139
156
  const isTypeBoolean = isBooleanSchema(option.type);
140
157
  const nextArg = argsv[i + 1];
141
158
 
@@ -173,7 +190,7 @@ export function parse<T extends Subcommand[], U extends Cli>(argsv: string[], ..
173
190
  continue;
174
191
  }
175
192
 
176
- const subcommandProps = subcommandArr.find(c => c.name === results.subcommand);
193
+ const subcommandProps = GetSubcommandProps();
177
194
 
178
195
  // * arguments
179
196
  if (subcommandProps?.arguments?.length) {
@@ -212,7 +229,7 @@ export function parse<T extends Subcommand[], U extends Cli>(argsv: string[], ..
212
229
  }
213
230
 
214
231
  // check for missing options - set defaults - add _source
215
- const subcommandProps = subcommandArr.find(c => c.name === results.subcommand);
232
+ const subcommandProps = GetSubcommandProps();
216
233
  if (subcommandProps?.options?.length) {
217
234
  for (const option of subcommandProps.options) {
218
235
  if (option.name in results) {
package/src/types.ts CHANGED
@@ -11,22 +11,15 @@ export type Subcommand = {
11
11
  */
12
12
  name: string;
13
13
 
14
- /**
15
- * - The action is executed with the result of the parsed arguments.
16
- * - To get typescript types use `setAction` instead of this.
17
- *
18
- * @example
19
- * const helpCommand = createSubcommand({ name: "help", options: [...] });
20
- * helpCommand.setAction(res => console.log(res));
21
- */
22
- action?: (results?: any) => void;
23
-
24
14
  /**
25
15
  * - The description of the subcommand.
26
16
  * - Used for generating the help message.
27
17
  */
28
18
  description?: string;
29
19
 
20
+ /** - The usage message in the help message. */
21
+ usage?: string;
22
+
30
23
  /** - Used for generating the help message. */
31
24
  placeholder?: string;
32
25
 
@@ -64,18 +57,22 @@ export type Subcommand = {
64
57
  * which arguments are optional.
65
58
  */
66
59
  arguments?: [Argument, ...Argument[]];
60
+
61
+ /**
62
+ * - The action is executed with the result of the parsed arguments.
63
+ * - To get typescript types use `setAction` instead of this.
64
+ *
65
+ * @example
66
+ * const helpCommand = createSubcommand({ name: "help", options: [...] });
67
+ * helpCommand.setAction(res => console.log(res));
68
+ */
69
+ action?: (results?: any) => void;
67
70
  };
68
71
 
69
72
  export type Cli = Prettify<
70
73
  Omit<Subcommand, "name"> & {
71
74
  /** - The name of the CLI program. */
72
75
  cliName: string;
73
-
74
- /**
75
- * - The usage of the CLI program.
76
- * - Used for generating the help message.
77
- */
78
- usage?: string;
79
76
  }
80
77
  >;
81
78
 
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sourceRoot":"../../src","sources":["types.ts"],"sourcesContent":["import type { z } from \"zod\";\n\nexport type Subcommand = {\n /**\n * - The subcommand name, use `kebab-case`.\n * - Make sure to not duplicate commands and aliases.\n *\n * @example\n * name: \"test\";\n * name: \"run-app\";\n */\n name: string;\n\n /**\n * - The action is executed with the result of the parsed arguments.\n * - To get typescript types use `setAction` instead of this.\n *\n * @example\n * const helpCommand = createSubcommand({ name: \"help\", options: [...] });\n * helpCommand.setAction(res => console.log(res));\n */\n action?: (results?: any) => void;\n\n /**\n * - The description of the subcommand.\n * - Used for generating the help message.\n */\n description?: string;\n\n /** - Used for generating the help message. */\n placeholder?: string;\n\n /**\n * - Provide an example to show to the user.\n * - Used for generating the help message.\n */\n example?: string;\n\n /**\n * - The aliases of the subcommand.\n * - Make sure to not duplicate aliases and commands.\n */\n aliases?: string[];\n\n /**\n * - Allows positional arguments for this subcommand.\n * - Unlike `arguments`, which are strictly typed, positional arguments are untyped and represented as a string array of\n * variable length.\n * - When enabled and `arguments` are provided, `arguments` will be parsed first. Any remaining arguments will be\n * considered positional arguments and added to the `positional` property in the result.\n */\n allowPositional?: boolean;\n\n /**\n * - The options of the command.\n * - Those options are specific to this subcommand.\n */\n options?: [Option, ...Option[]];\n\n /**\n * - Specifies a list of strictly typed arguments.\n * - The order is important; for example, the first argument will be validated against the first specified type.\n * - It is recommended to not use optional arguments as the parser will fill the arguments by order and can't determine\n * which arguments are optional.\n */\n arguments?: [Argument, ...Argument[]];\n};\n\nexport type Cli = Prettify<\n Omit<Subcommand, \"name\"> & {\n /** - The name of the CLI program. */\n cliName: string;\n\n /**\n * - The usage of the CLI program.\n * - Used for generating the help message.\n */\n usage?: string;\n }\n>;\n\nexport type Option = {\n /**\n * - The name of the option, use `CamelCase`.\n * - For example: the syntax for the option `rootPath` is `--root-path`.\n */\n name: string;\n\n /**\n * - The will be used to validate the user input.\n *\n * @example\n * type: z.boolean().default(false);\n * type: z.coerce.number(); // will be coerced to number by Zod\n * type: z.preprocess(parseStringToArrFn, z.array(z.coerce.number())); // array of numbers\n *\n * @see https://zod.dev/?id=types\n */\n type: z.ZodTypeAny;\n\n /**\n * - The description of the option.\n * - Used for generating the help message.\n */\n description?: string;\n\n /** - Used for generating the help message. */\n placeholder?: string;\n\n /**\n * - The example of using the option.\n * - Used for generating the help message.\n */\n example?: string;\n\n /**\n * - The aliases of the option, use `CamelCase`.\n * - Here you can specify short names or flags.\n * - Make sure to not duplicate aliases.\n */\n aliases?: [string, ...string[]];\n};\n\nexport type Argument = {\n /** - The name of the argument. */\n name: string;\n\n /**\n * - The will be used to validate the user input.\n *\n * @example\n * type: z.boolean();\n * type: z.coerce.number(); // will be coerced to number by Zod\n * type: z.preprocess(ParseStringToArrFn, z.array(z.coerce.number())); // array of numbers\n *\n * @see https://zod.dev/?id=types\n */\n type: z.ZodTypeAny;\n\n /**\n * - The description of the argument.\n * - Used for generating the help message.\n */\n description?: string;\n\n /**\n * - The example of using the argument.\n * - Used for generating the help message.\n */\n example?: string;\n};\n\nexport type ColorFnType = (...text: unknown[]) => string;\n\nexport type PrintHelpOpt = {\n /**\n * - **Optional** `boolean`\n * - Whether to print colors or not.\n * - Default: `true`\n */\n colors?: boolean;\n\n /**\n * - **Optional** `object`\n * - The colors to use for the help message.\n */\n customColors?: {\n title?: ColorFnType;\n description?: ColorFnType;\n default?: ColorFnType;\n optional?: ColorFnType;\n exampleTitle?: ColorFnType;\n example?: ColorFnType;\n command?: ColorFnType;\n option?: ColorFnType;\n argument?: ColorFnType;\n placeholder?: ColorFnType;\n punctuation?: ColorFnType;\n };\n};\n\nexport type _Info = {\n /**\n * - The raw argument as it was passed in\n * - For options that have a default value and are not passed in, the raw argument will be `undefined`\n */\n rawArg?: string;\n /**\n * - The raw value of the argument as it was passed in\n * - It will be empty string for `boolean` options. E.g. `--help` or `-h`\n * - For options that have a default value and are not passed in, the raw value will be `undefined`\n */\n rawValue?: string;\n /**\n * - The source value of the argument:\n * - `cli`: The argument was passed in by the user\n * - `default`: The argument was not passed in and has a default value\n */\n source: \"cli\" | \"default\";\n};\n\n/**\n * - Infer the options type from a subcommand.\n *\n * @example\n * const subcommand = createSubcommand({ name: \"build\", options: [...] });\n * type OptionsType = InferOptionsType<typeof subcommand>;\n */\nexport type InferOptionsType<T extends Partial<Subcommand>> = T[\"options\"] extends infer U extends Option[]\n ? ToOptional<{ [K in U[number][\"name\"]]: z.infer<Extract<U[number], { name: K }>[\"type\"]> }>\n : undefined;\n\n/**\n * - Infer the arguments type from a subcommand.\n *\n * @example\n * const subcommand = createSubcommand({ name: \"build\", arguments: [...] });\n * type ArgumentsType = InferArgumentsType<typeof subcommand>;\n */\nexport type InferArgumentsType<T extends Partial<Subcommand>> = T[\"arguments\"] extends infer U extends Argument[]\n ? { [K in keyof U]: U[K] extends { type: z.ZodTypeAny } ? z.infer<U[K][\"type\"]> : never }\n : undefined;\n\n/** `{ some props } & { other props }` => `{ some props, other props }` */\nexport type Prettify<T> = { [K in keyof T]: T[K] } & {};\n\n/** Allow string type for literal union and get auto completion */\nexport type LiteralUnion<T extends string> = T | (string & {});\n\n/** Extract the undefined properties from an object */\ntype UndefinedProperties<T> = { [P in keyof T]-?: undefined extends T[P] ? P : never }[keyof T];\n\n/** Make undefined properties optional? */\ntype ToOptional<T> = Prettify<\n Partial<Pick<T, UndefinedProperties<T>>> & Pick<T, Exclude<keyof T, UndefinedProperties<T>>>\n>;\n\nexport type OptionsArr2RecordType<T extends Option[] | undefined> = T extends Option[]\n ? ToOptional<{ [K in T[number][\"name\"]]: z.infer<Extract<T[number], { name: K }>[\"type\"]> }>\n : object;\n\nexport type ArgumentsArr2ArrType<T extends Argument[] | undefined> = T extends Argument[]\n ? { arguments: { [K in keyof T]: T[K] extends { type: z.ZodTypeAny } ? z.infer<T[K][\"type\"]> : never } }\n : object;\n\nexport type Positional<S extends Partial<Subcommand>> = S[\"allowPositional\"] extends true\n ? { positional: string[] }\n : object;\n\nexport type Info<T extends Option[] | undefined> = T extends Option[]\n ? {\n _info: ToOptional<{\n [K in T[number][\"name\"]]: Extract<T[number], { name: K }> extends infer U extends Option\n ? undefined extends z.infer<U[\"type\"]>\n ? undefined | Prettify<_Info & U> // if optional add undefined\n : Prettify<_Info & U>\n : never;\n }>;\n }\n : object;\n\nexport type NoSubcommand = { name: undefined };\n\nexport type ParseResult<S extends Partial<Subcommand>[]> = {\n [K in keyof S]: Prettify<\n { subcommand: S[K][\"name\"] } & Positional<S[K]> &\n Info<S[K][\"options\"]> &\n OptionsArr2RecordType<S[K][\"options\"]> &\n ArgumentsArr2ArrType<S[K][\"arguments\"]>\n >;\n}[number];\n\nexport type PrintMethods<N extends Subcommand[\"name\"] | undefined> = {\n printCliHelp: (options?: PrintHelpOpt) => void;\n printSubcommandHelp: (subcommand: LiteralUnion<NonNullable<N>>, options?: PrintHelpOpt) => void;\n};\n\nexport type UnSafeParseResult<S extends Partial<Subcommand>[]> =\n CheckDuplicatedSubcommands<S> extends infer E extends string\n ? E\n : Prettify<ParseResult<S> & PrintMethods<S[number][\"name\"]>>;\n\nexport type SafeParseResult<S extends Partial<Subcommand>[]> =\n CheckDuplicatedSubcommands<S> extends infer E extends string\n ? E\n : Prettify<\n ({ success: false; error: Error } | { success: true; data: ParseResult<S> }) & PrintMethods<S[number][\"name\"]>\n >;\n\nexport type ActionFn<T extends Subcommand | Cli> = {\n setAction: (actions: (res: UnSafeParseResult<[T]>) => void) => void;\n};\n\n/** - Combine `name` and `aliases` to a `string[]` */\ntype MapNameAndAliases2StrArr<T extends { name?: string; aliases?: string[] }[]> = T extends [\n infer First extends Subcommand,\n ...infer Rest,\n]\n ? Rest extends { name?: string; aliases?: string[] }[]\n ? [First[\"name\"], ...(First[\"aliases\"] extends string[] ? First[\"aliases\"] : []), ...MapNameAndAliases2StrArr<Rest>]\n : [First[\"name\"], ...(First[\"aliases\"] extends string[] ? First[\"aliases\"] : [])]\n : [];\n\n/**\n * - Find duplicated items in an array and return it\n * - Return `false` if not found\n */\ntype IsDuplicatesInArr<Input extends any[]> = Input extends [infer Item, ...infer Rest]\n ? Rest extends any[]\n ? Item extends Rest[number]\n ? Item\n : IsDuplicatesInArr<Rest>\n : false\n : false;\n\n/**\n * - Check if there are duplicated options including aliases in `subcommand`\n * - Return an error message if duplicated is found\n * - Return `subcommand` if not found\n */\nexport type CheckDuplicatedOptions<T extends Subcommand | Cli> = T[\"options\"] extends infer O extends Option[]\n ? IsDuplicatesInArr<MapNameAndAliases2StrArr<O>> extends infer D extends string\n ? `>>> Error: Duplicated Options \\`${D}\\` <<<`\n : T\n : T;\n\n/**\n * - Check for duplicated subcommands including aliases\n * - Return an error message if duplicated is found\n * - Return the `subcommand[]` if no error\n */\nexport type CheckDuplicatedSubcommands<T extends Partial<Subcommand>[]> =\n IsDuplicatesInArr<MapNameAndAliases2StrArr<T>> extends infer D extends string\n ? `>>> Error: Duplicated Subcommand \\`${D}\\` <<<`\n : T;\n"],"mappings":"","ignoreList":[]}
@@ -1 +0,0 @@
1
- export{};
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sourceRoot":"../../src","sources":["types.ts"],"sourcesContent":["import type { z } from \"zod\";\n\nexport type Subcommand = {\n /**\n * - The subcommand name, use `kebab-case`.\n * - Make sure to not duplicate commands and aliases.\n *\n * @example\n * name: \"test\";\n * name: \"run-app\";\n */\n name: string;\n\n /**\n * - The action is executed with the result of the parsed arguments.\n * - To get typescript types use `setAction` instead of this.\n *\n * @example\n * const helpCommand = createSubcommand({ name: \"help\", options: [...] });\n * helpCommand.setAction(res => console.log(res));\n */\n action?: (results?: any) => void;\n\n /**\n * - The description of the subcommand.\n * - Used for generating the help message.\n */\n description?: string;\n\n /** - Used for generating the help message. */\n placeholder?: string;\n\n /**\n * - Provide an example to show to the user.\n * - Used for generating the help message.\n */\n example?: string;\n\n /**\n * - The aliases of the subcommand.\n * - Make sure to not duplicate aliases and commands.\n */\n aliases?: string[];\n\n /**\n * - Allows positional arguments for this subcommand.\n * - Unlike `arguments`, which are strictly typed, positional arguments are untyped and represented as a string array of\n * variable length.\n * - When enabled and `arguments` are provided, `arguments` will be parsed first. Any remaining arguments will be\n * considered positional arguments and added to the `positional` property in the result.\n */\n allowPositional?: boolean;\n\n /**\n * - The options of the command.\n * - Those options are specific to this subcommand.\n */\n options?: [Option, ...Option[]];\n\n /**\n * - Specifies a list of strictly typed arguments.\n * - The order is important; for example, the first argument will be validated against the first specified type.\n * - It is recommended to not use optional arguments as the parser will fill the arguments by order and can't determine\n * which arguments are optional.\n */\n arguments?: [Argument, ...Argument[]];\n};\n\nexport type Cli = Prettify<\n Omit<Subcommand, \"name\"> & {\n /** - The name of the CLI program. */\n cliName: string;\n\n /**\n * - The usage of the CLI program.\n * - Used for generating the help message.\n */\n usage?: string;\n }\n>;\n\nexport type Option = {\n /**\n * - The name of the option, use `CamelCase`.\n * - For example: the syntax for the option `rootPath` is `--root-path`.\n */\n name: string;\n\n /**\n * - The will be used to validate the user input.\n *\n * @example\n * type: z.boolean().default(false);\n * type: z.coerce.number(); // will be coerced to number by Zod\n * type: z.preprocess(parseStringToArrFn, z.array(z.coerce.number())); // array of numbers\n *\n * @see https://zod.dev/?id=types\n */\n type: z.ZodTypeAny;\n\n /**\n * - The description of the option.\n * - Used for generating the help message.\n */\n description?: string;\n\n /** - Used for generating the help message. */\n placeholder?: string;\n\n /**\n * - The example of using the option.\n * - Used for generating the help message.\n */\n example?: string;\n\n /**\n * - The aliases of the option, use `CamelCase`.\n * - Here you can specify short names or flags.\n * - Make sure to not duplicate aliases.\n */\n aliases?: [string, ...string[]];\n};\n\nexport type Argument = {\n /** - The name of the argument. */\n name: string;\n\n /**\n * - The will be used to validate the user input.\n *\n * @example\n * type: z.boolean();\n * type: z.coerce.number(); // will be coerced to number by Zod\n * type: z.preprocess(ParseStringToArrFn, z.array(z.coerce.number())); // array of numbers\n *\n * @see https://zod.dev/?id=types\n */\n type: z.ZodTypeAny;\n\n /**\n * - The description of the argument.\n * - Used for generating the help message.\n */\n description?: string;\n\n /**\n * - The example of using the argument.\n * - Used for generating the help message.\n */\n example?: string;\n};\n\nexport type ColorFnType = (...text: unknown[]) => string;\n\nexport type PrintHelpOpt = {\n /**\n * - **Optional** `boolean`\n * - Whether to print colors or not.\n * - Default: `true`\n */\n colors?: boolean;\n\n /**\n * - **Optional** `object`\n * - The colors to use for the help message.\n */\n customColors?: {\n title?: ColorFnType;\n description?: ColorFnType;\n default?: ColorFnType;\n optional?: ColorFnType;\n exampleTitle?: ColorFnType;\n example?: ColorFnType;\n command?: ColorFnType;\n option?: ColorFnType;\n argument?: ColorFnType;\n placeholder?: ColorFnType;\n punctuation?: ColorFnType;\n };\n};\n\nexport type _Info = {\n /**\n * - The raw argument as it was passed in\n * - For options that have a default value and are not passed in, the raw argument will be `undefined`\n */\n rawArg?: string;\n /**\n * - The raw value of the argument as it was passed in\n * - It will be empty string for `boolean` options. E.g. `--help` or `-h`\n * - For options that have a default value and are not passed in, the raw value will be `undefined`\n */\n rawValue?: string;\n /**\n * - The source value of the argument:\n * - `cli`: The argument was passed in by the user\n * - `default`: The argument was not passed in and has a default value\n */\n source: \"cli\" | \"default\";\n};\n\n/**\n * - Infer the options type from a subcommand.\n *\n * @example\n * const subcommand = createSubcommand({ name: \"build\", options: [...] });\n * type OptionsType = InferOptionsType<typeof subcommand>;\n */\nexport type InferOptionsType<T extends Partial<Subcommand>> = T[\"options\"] extends infer U extends Option[]\n ? ToOptional<{ [K in U[number][\"name\"]]: z.infer<Extract<U[number], { name: K }>[\"type\"]> }>\n : undefined;\n\n/**\n * - Infer the arguments type from a subcommand.\n *\n * @example\n * const subcommand = createSubcommand({ name: \"build\", arguments: [...] });\n * type ArgumentsType = InferArgumentsType<typeof subcommand>;\n */\nexport type InferArgumentsType<T extends Partial<Subcommand>> = T[\"arguments\"] extends infer U extends Argument[]\n ? { [K in keyof U]: U[K] extends { type: z.ZodTypeAny } ? z.infer<U[K][\"type\"]> : never }\n : undefined;\n\n/** `{ some props } & { other props }` => `{ some props, other props }` */\nexport type Prettify<T> = { [K in keyof T]: T[K] } & {};\n\n/** Allow string type for literal union and get auto completion */\nexport type LiteralUnion<T extends string> = T | (string & {});\n\n/** Extract the undefined properties from an object */\ntype UndefinedProperties<T> = { [P in keyof T]-?: undefined extends T[P] ? P : never }[keyof T];\n\n/** Make undefined properties optional? */\ntype ToOptional<T> = Prettify<\n Partial<Pick<T, UndefinedProperties<T>>> & Pick<T, Exclude<keyof T, UndefinedProperties<T>>>\n>;\n\nexport type OptionsArr2RecordType<T extends Option[] | undefined> = T extends Option[]\n ? ToOptional<{ [K in T[number][\"name\"]]: z.infer<Extract<T[number], { name: K }>[\"type\"]> }>\n : object;\n\nexport type ArgumentsArr2ArrType<T extends Argument[] | undefined> = T extends Argument[]\n ? { arguments: { [K in keyof T]: T[K] extends { type: z.ZodTypeAny } ? z.infer<T[K][\"type\"]> : never } }\n : object;\n\nexport type Positional<S extends Partial<Subcommand>> = S[\"allowPositional\"] extends true\n ? { positional: string[] }\n : object;\n\nexport type Info<T extends Option[] | undefined> = T extends Option[]\n ? {\n _info: ToOptional<{\n [K in T[number][\"name\"]]: Extract<T[number], { name: K }> extends infer U extends Option\n ? undefined extends z.infer<U[\"type\"]>\n ? undefined | Prettify<_Info & U> // if optional add undefined\n : Prettify<_Info & U>\n : never;\n }>;\n }\n : object;\n\nexport type NoSubcommand = { name: undefined };\n\nexport type ParseResult<S extends Partial<Subcommand>[]> = {\n [K in keyof S]: Prettify<\n { subcommand: S[K][\"name\"] } & Positional<S[K]> &\n Info<S[K][\"options\"]> &\n OptionsArr2RecordType<S[K][\"options\"]> &\n ArgumentsArr2ArrType<S[K][\"arguments\"]>\n >;\n}[number];\n\nexport type PrintMethods<N extends Subcommand[\"name\"] | undefined> = {\n printCliHelp: (options?: PrintHelpOpt) => void;\n printSubcommandHelp: (subcommand: LiteralUnion<NonNullable<N>>, options?: PrintHelpOpt) => void;\n};\n\nexport type UnSafeParseResult<S extends Partial<Subcommand>[]> =\n CheckDuplicatedSubcommands<S> extends infer E extends string\n ? E\n : Prettify<ParseResult<S> & PrintMethods<S[number][\"name\"]>>;\n\nexport type SafeParseResult<S extends Partial<Subcommand>[]> =\n CheckDuplicatedSubcommands<S> extends infer E extends string\n ? E\n : Prettify<\n ({ success: false; error: Error } | { success: true; data: ParseResult<S> }) & PrintMethods<S[number][\"name\"]>\n >;\n\nexport type ActionFn<T extends Subcommand | Cli> = {\n setAction: (actions: (res: UnSafeParseResult<[T]>) => void) => void;\n};\n\n/** - Combine `name` and `aliases` to a `string[]` */\ntype MapNameAndAliases2StrArr<T extends { name?: string; aliases?: string[] }[]> = T extends [\n infer First extends Subcommand,\n ...infer Rest,\n]\n ? Rest extends { name?: string; aliases?: string[] }[]\n ? [First[\"name\"], ...(First[\"aliases\"] extends string[] ? First[\"aliases\"] : []), ...MapNameAndAliases2StrArr<Rest>]\n : [First[\"name\"], ...(First[\"aliases\"] extends string[] ? First[\"aliases\"] : [])]\n : [];\n\n/**\n * - Find duplicated items in an array and return it\n * - Return `false` if not found\n */\ntype IsDuplicatesInArr<Input extends any[]> = Input extends [infer Item, ...infer Rest]\n ? Rest extends any[]\n ? Item extends Rest[number]\n ? Item\n : IsDuplicatesInArr<Rest>\n : false\n : false;\n\n/**\n * - Check if there are duplicated options including aliases in `subcommand`\n * - Return an error message if duplicated is found\n * - Return `subcommand` if not found\n */\nexport type CheckDuplicatedOptions<T extends Subcommand | Cli> = T[\"options\"] extends infer O extends Option[]\n ? IsDuplicatesInArr<MapNameAndAliases2StrArr<O>> extends infer D extends string\n ? `>>> Error: Duplicated Options \\`${D}\\` <<<`\n : T\n : T;\n\n/**\n * - Check for duplicated subcommands including aliases\n * - Return an error message if duplicated is found\n * - Return the `subcommand[]` if no error\n */\nexport type CheckDuplicatedSubcommands<T extends Partial<Subcommand>[]> =\n IsDuplicatesInArr<MapNameAndAliases2StrArr<T>> extends infer D extends string\n ? `>>> Error: Duplicated Subcommand \\`${D}\\` <<<`\n : T;\n"],"mappings":"","ignoreList":[]}