zod-args-parser 1.0.16 → 1.1.0

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.
Files changed (36) hide show
  1. package/README.md +1 -1
  2. package/lib/commonjs/metadata/get-arguments-metadata.js +1 -1
  3. package/lib/commonjs/metadata/get-arguments-metadata.js.map +1 -1
  4. package/lib/commonjs/metadata/get-options-metadata.js +1 -1
  5. package/lib/commonjs/metadata/get-options-metadata.js.map +1 -1
  6. package/lib/commonjs/parser/parse.js +1 -1
  7. package/lib/commonjs/parser/parse.js.map +1 -1
  8. package/lib/commonjs/utils.js +1 -1
  9. package/lib/commonjs/utils.js.map +1 -1
  10. package/lib/commonjs/zodUtils.js +1 -0
  11. package/lib/commonjs/zodUtils.js.map +1 -0
  12. package/lib/module/metadata/get-arguments-metadata.js +1 -1
  13. package/lib/module/metadata/get-arguments-metadata.js.map +1 -1
  14. package/lib/module/metadata/get-options-metadata.js +1 -1
  15. package/lib/module/metadata/get-options-metadata.js.map +1 -1
  16. package/lib/module/parser/parse.js +1 -1
  17. package/lib/module/parser/parse.js.map +1 -1
  18. package/lib/module/utils.js +1 -1
  19. package/lib/module/utils.js.map +1 -1
  20. package/lib/module/zodUtils.js +1 -0
  21. package/lib/module/zodUtils.js.map +1 -0
  22. package/lib/typescript/metadata/get-options-metadata.d.ts.map +1 -1
  23. package/lib/typescript/parser/parse.d.ts.map +1 -1
  24. package/lib/typescript/types.d.ts +17 -12
  25. package/lib/typescript/types.d.ts.map +1 -1
  26. package/lib/typescript/utils.d.ts +1 -5
  27. package/lib/typescript/utils.d.ts.map +1 -1
  28. package/lib/typescript/zodUtils.d.ts +14 -0
  29. package/lib/typescript/zodUtils.d.ts.map +1 -0
  30. package/package.json +17 -17
  31. package/src/metadata/get-arguments-metadata.ts +4 -4
  32. package/src/metadata/get-options-metadata.ts +5 -4
  33. package/src/parser/parse.ts +18 -16
  34. package/src/types.ts +17 -10
  35. package/src/utils.ts +1 -34
  36. package/src/zodUtils.ts +151 -0
package/README.md CHANGED
@@ -13,7 +13,7 @@ A strictly typed command-line arguments parser powered by Zod.
13
13
  ## Installation
14
14
 
15
15
  > [!IMPORTANT]
16
- > `zod` version `4` is not supported at this time.
16
+ > `zod` version `3.25.0` or later (including `4.0.0`) is required.
17
17
 
18
18
  ```bash
19
19
  npm install zod chalk zod-args-parser
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.getArgumentsMetadata=getArgumentsMetadata;var _utils=require("../utils.js");function getArgumentsMetadata(args){const outputMetadata=[];for(const arg of args){const defaultValue=(0,_utils.getDefaultValueFromSchema)(arg.type);outputMetadata.push({name:arg.name,description:arg.description??arg.type.description??"",defaultValue,defaultValueAsString:JSON.stringify(defaultValue),optional:arg.type.isOptional(),example:arg.example??"",type:arg.type});}return outputMetadata;}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.getArgumentsMetadata=getArgumentsMetadata;var _zodUtils=require("../zodUtils.js");function getArgumentsMetadata(args){const outputMetadata=[];for(const arg of args){const defaultValue=(0,_zodUtils.schemaDefaultValue)(arg.type);outputMetadata.push({name:arg.name,description:arg.description??(0,_zodUtils.schemaDescription)(arg.type)??"",defaultValue,defaultValueAsString:JSON.stringify(defaultValue),optional:(0,_zodUtils.isOptionalSchema)(arg.type),example:arg.example??"",type:arg.type});}return outputMetadata;}
@@ -1 +1 @@
1
- {"version":3,"names":["_utils","require","getArgumentsMetadata","args","outputMetadata","arg","defaultValue","getDefaultValueFromSchema","type","push","name","description","defaultValueAsString","JSON","stringify","optional","isOptional","example"],"sourceRoot":"../../../src/metadata","sources":["get-arguments-metadata.ts"],"sourcesContent":["import { getDefaultValueFromSchema } from \"../utils.js\";\n\nimport type { Argument, ArgumentMetadata } from \"../types.js\";\n\nexport function getArgumentsMetadata(args: Argument[]): ArgumentMetadata[] {\n const outputMetadata: ArgumentMetadata[] = [];\n\n for (const arg of args) {\n const defaultValue = getDefaultValueFromSchema(arg.type);\n\n outputMetadata.push({\n name: arg.name,\n description: arg.description ?? arg.type.description ?? \"\",\n defaultValue,\n defaultValueAsString: JSON.stringify(defaultValue),\n optional: arg.type.isOptional(),\n example: arg.example ?? \"\",\n type: arg.type,\n });\n }\n\n return outputMetadata;\n}\n"],"mappings":"wHAAA,IAAAA,MAAA,CAAAC,OAAA,gBAIO,QAAS,CAAAC,oBAAoBA,CAACC,IAAgB,CAAsB,CACzE,KAAM,CAAAC,cAAkC,CAAG,EAAE,CAE7C,IAAK,KAAM,CAAAC,GAAG,GAAI,CAAAF,IAAI,CAAE,CACtB,KAAM,CAAAG,YAAY,CAAG,GAAAC,gCAAyB,EAACF,GAAG,CAACG,IAAI,CAAC,CAExDJ,cAAc,CAACK,IAAI,CAAC,CAClBC,IAAI,CAAEL,GAAG,CAACK,IAAI,CACdC,WAAW,CAAEN,GAAG,CAACM,WAAW,EAAIN,GAAG,CAACG,IAAI,CAACG,WAAW,EAAI,EAAE,CAC1DL,YAAY,CACZM,oBAAoB,CAAEC,IAAI,CAACC,SAAS,CAACR,YAAY,CAAC,CAClDS,QAAQ,CAAEV,GAAG,CAACG,IAAI,CAACQ,UAAU,CAAC,CAAC,CAC/BC,OAAO,CAAEZ,GAAG,CAACY,OAAO,EAAI,EAAE,CAC1BT,IAAI,CAAEH,GAAG,CAACG,IACZ,CAAC,CAAC,CACJ,CAEA,MAAO,CAAAJ,cAAc,CACvB","ignoreList":[]}
1
+ {"version":3,"names":["_zodUtils","require","getArgumentsMetadata","args","outputMetadata","arg","defaultValue","schemaDefaultValue","type","push","name","description","schemaDescription","defaultValueAsString","JSON","stringify","optional","isOptionalSchema","example"],"sourceRoot":"../../../src/metadata","sources":["get-arguments-metadata.ts"],"sourcesContent":["import { isOptionalSchema, schemaDefaultValue, schemaDescription } from \"../zodUtils.js\";\n\nimport type { Argument, ArgumentMetadata } from \"../types.js\";\n\nexport function getArgumentsMetadata(args: Argument[]): ArgumentMetadata[] {\n const outputMetadata: ArgumentMetadata[] = [];\n\n for (const arg of args) {\n const defaultValue = schemaDefaultValue(arg.type);\n\n outputMetadata.push({\n name: arg.name,\n description: arg.description ?? schemaDescription(arg.type) ?? \"\",\n defaultValue,\n defaultValueAsString: JSON.stringify(defaultValue),\n optional: isOptionalSchema(arg.type),\n example: arg.example ?? \"\",\n type: arg.type,\n });\n }\n\n return outputMetadata;\n}\n"],"mappings":"wHAAA,IAAAA,SAAA,CAAAC,OAAA,mBAIO,QAAS,CAAAC,oBAAoBA,CAACC,IAAgB,CAAsB,CACzE,KAAM,CAAAC,cAAkC,CAAG,EAAE,CAE7C,IAAK,KAAM,CAAAC,GAAG,GAAI,CAAAF,IAAI,CAAE,CACtB,KAAM,CAAAG,YAAY,CAAG,GAAAC,4BAAkB,EAACF,GAAG,CAACG,IAAI,CAAC,CAEjDJ,cAAc,CAACK,IAAI,CAAC,CAClBC,IAAI,CAAEL,GAAG,CAACK,IAAI,CACdC,WAAW,CAAEN,GAAG,CAACM,WAAW,EAAI,GAAAC,2BAAiB,EAACP,GAAG,CAACG,IAAI,CAAC,EAAI,EAAE,CACjEF,YAAY,CACZO,oBAAoB,CAAEC,IAAI,CAACC,SAAS,CAACT,YAAY,CAAC,CAClDU,QAAQ,CAAE,GAAAC,0BAAgB,EAACZ,GAAG,CAACG,IAAI,CAAC,CACpCU,OAAO,CAAEb,GAAG,CAACa,OAAO,EAAI,EAAE,CAC1BV,IAAI,CAAEH,GAAG,CAACG,IACZ,CAAC,CAAC,CACJ,CAEA,MAAO,CAAAJ,cAAc,CACvB","ignoreList":[]}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.getOptionsMetadata=getOptionsMetadata;var _utils=require("../utils.js");function getOptionsMetadata(options){const outputMetadata=[];if(!options||!options.length)return outputMetadata;for(const option of options){const defaultValue=(0,_utils.getDefaultValueFromSchema)(option.type);const aliases=option.aliases??[];outputMetadata.push({name:option.name,nameAsArg:(0,_utils.transformOptionToArg)(option.name),aliases,aliasesAsArgs:aliases.map(_utils.transformOptionToArg),placeholder:option.placeholder??"",description:option.description??option.type.description??"",optional:option.type.isOptional(),example:option.example??"",defaultValue,defaultValueAsString:JSON.stringify(defaultValue),type:option.type});}return outputMetadata;}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.getOptionsMetadata=getOptionsMetadata;var _utils=require("../utils.js");var _zodUtils=require("../zodUtils.js");function getOptionsMetadata(options){const outputMetadata=[];if(!options||!options.length)return outputMetadata;for(const option of options){const defaultValue=(0,_zodUtils.schemaDefaultValue)(option.type);const aliases=option.aliases??[];outputMetadata.push({name:option.name,nameAsArg:(0,_utils.transformOptionToArg)(option.name),aliases,aliasesAsArgs:aliases.map(_utils.transformOptionToArg),placeholder:option.placeholder??"",description:option.description??(0,_zodUtils.schemaDescription)(option.type)??"",optional:(0,_zodUtils.isOptionalSchema)(option.type),example:option.example??"",defaultValue,defaultValueAsString:JSON.stringify(defaultValue),type:option.type});}return outputMetadata;}
@@ -1 +1 @@
1
- {"version":3,"names":["_utils","require","getOptionsMetadata","options","outputMetadata","length","option","defaultValue","getDefaultValueFromSchema","type","aliases","push","name","nameAsArg","transformOptionToArg","aliasesAsArgs","map","placeholder","description","optional","isOptional","example","defaultValueAsString","JSON","stringify"],"sourceRoot":"../../../src/metadata","sources":["get-options-metadata.ts"],"sourcesContent":["import { getDefaultValueFromSchema, transformOptionToArg } from \"../utils.js\";\n\nimport type { Option, OptionMetadata } from \"../types.js\";\n\nexport function getOptionsMetadata(options: Option[]): OptionMetadata[] {\n const outputMetadata: OptionMetadata[] = [];\n\n if (!options || !options.length) return outputMetadata;\n\n for (const option of options) {\n const defaultValue = getDefaultValueFromSchema(option.type);\n const aliases = option.aliases ?? [];\n\n outputMetadata.push({\n name: option.name,\n nameAsArg: transformOptionToArg(option.name),\n aliases,\n aliasesAsArgs: aliases.map(transformOptionToArg),\n placeholder: option.placeholder ?? \"\",\n description: option.description ?? option.type.description ?? \"\",\n optional: option.type.isOptional(),\n example: option.example ?? \"\",\n defaultValue,\n defaultValueAsString: JSON.stringify(defaultValue),\n type: option.type,\n });\n }\n\n return outputMetadata;\n}\n"],"mappings":"oHAAA,IAAAA,MAAA,CAAAC,OAAA,gBAIO,QAAS,CAAAC,kBAAkBA,CAACC,OAAiB,CAAoB,CACtE,KAAM,CAAAC,cAAgC,CAAG,EAAE,CAE3C,GAAI,CAACD,OAAO,EAAI,CAACA,OAAO,CAACE,MAAM,CAAE,MAAO,CAAAD,cAAc,CAEtD,IAAK,KAAM,CAAAE,MAAM,GAAI,CAAAH,OAAO,CAAE,CAC5B,KAAM,CAAAI,YAAY,CAAG,GAAAC,gCAAyB,EAACF,MAAM,CAACG,IAAI,CAAC,CAC3D,KAAM,CAAAC,OAAO,CAAGJ,MAAM,CAACI,OAAO,EAAI,EAAE,CAEpCN,cAAc,CAACO,IAAI,CAAC,CAClBC,IAAI,CAAEN,MAAM,CAACM,IAAI,CACjBC,SAAS,CAAE,GAAAC,2BAAoB,EAACR,MAAM,CAACM,IAAI,CAAC,CAC5CF,OAAO,CACPK,aAAa,CAAEL,OAAO,CAACM,GAAG,CAACF,2BAAoB,CAAC,CAChDG,WAAW,CAAEX,MAAM,CAACW,WAAW,EAAI,EAAE,CACrCC,WAAW,CAAEZ,MAAM,CAACY,WAAW,EAAIZ,MAAM,CAACG,IAAI,CAACS,WAAW,EAAI,EAAE,CAChEC,QAAQ,CAAEb,MAAM,CAACG,IAAI,CAACW,UAAU,CAAC,CAAC,CAClCC,OAAO,CAAEf,MAAM,CAACe,OAAO,EAAI,EAAE,CAC7Bd,YAAY,CACZe,oBAAoB,CAAEC,IAAI,CAACC,SAAS,CAACjB,YAAY,CAAC,CAClDE,IAAI,CAAEH,MAAM,CAACG,IACf,CAAC,CAAC,CACJ,CAEA,MAAO,CAAAL,cAAc,CACvB","ignoreList":[]}
1
+ {"version":3,"names":["_utils","require","_zodUtils","getOptionsMetadata","options","outputMetadata","length","option","defaultValue","schemaDefaultValue","type","aliases","push","name","nameAsArg","transformOptionToArg","aliasesAsArgs","map","placeholder","description","schemaDescription","optional","isOptionalSchema","example","defaultValueAsString","JSON","stringify"],"sourceRoot":"../../../src/metadata","sources":["get-options-metadata.ts"],"sourcesContent":["import { transformOptionToArg } from \"../utils.js\";\nimport { isOptionalSchema, schemaDefaultValue, schemaDescription } from \"../zodUtils.js\";\n\nimport type { Option, OptionMetadata } from \"../types.js\";\n\nexport function getOptionsMetadata(options: Option[]): OptionMetadata[] {\n const outputMetadata: OptionMetadata[] = [];\n\n if (!options || !options.length) return outputMetadata;\n\n for (const option of options) {\n const defaultValue = schemaDefaultValue(option.type);\n const aliases = option.aliases ?? [];\n\n outputMetadata.push({\n name: option.name,\n nameAsArg: transformOptionToArg(option.name),\n aliases,\n aliasesAsArgs: aliases.map(transformOptionToArg),\n placeholder: option.placeholder ?? \"\",\n description: option.description ?? schemaDescription(option.type) ?? \"\",\n optional: isOptionalSchema(option.type),\n example: option.example ?? \"\",\n defaultValue,\n defaultValueAsString: JSON.stringify(defaultValue),\n type: option.type,\n });\n }\n\n return outputMetadata;\n}\n"],"mappings":"oHAAA,IAAAA,MAAA,CAAAC,OAAA,gBACA,IAAAC,SAAA,CAAAD,OAAA,mBAIO,QAAS,CAAAE,kBAAkBA,CAACC,OAAiB,CAAoB,CACtE,KAAM,CAAAC,cAAgC,CAAG,EAAE,CAE3C,GAAI,CAACD,OAAO,EAAI,CAACA,OAAO,CAACE,MAAM,CAAE,MAAO,CAAAD,cAAc,CAEtD,IAAK,KAAM,CAAAE,MAAM,GAAI,CAAAH,OAAO,CAAE,CAC5B,KAAM,CAAAI,YAAY,CAAG,GAAAC,4BAAkB,EAACF,MAAM,CAACG,IAAI,CAAC,CACpD,KAAM,CAAAC,OAAO,CAAGJ,MAAM,CAACI,OAAO,EAAI,EAAE,CAEpCN,cAAc,CAACO,IAAI,CAAC,CAClBC,IAAI,CAAEN,MAAM,CAACM,IAAI,CACjBC,SAAS,CAAE,GAAAC,2BAAoB,EAACR,MAAM,CAACM,IAAI,CAAC,CAC5CF,OAAO,CACPK,aAAa,CAAEL,OAAO,CAACM,GAAG,CAACF,2BAAoB,CAAC,CAChDG,WAAW,CAAEX,MAAM,CAACW,WAAW,EAAI,EAAE,CACrCC,WAAW,CAAEZ,MAAM,CAACY,WAAW,EAAI,GAAAC,2BAAiB,EAACb,MAAM,CAACG,IAAI,CAAC,EAAI,EAAE,CACvEW,QAAQ,CAAE,GAAAC,0BAAgB,EAACf,MAAM,CAACG,IAAI,CAAC,CACvCa,OAAO,CAAEhB,MAAM,CAACgB,OAAO,EAAI,EAAE,CAC7Bf,YAAY,CACZgB,oBAAoB,CAAEC,IAAI,CAACC,SAAS,CAAClB,YAAY,CAAC,CAClDE,IAAI,CAAEH,MAAM,CAACG,IACf,CAAC,CAAC,CACJ,CAEA,MAAO,CAAAL,cAAc,CACvB","ignoreList":[]}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.parse=parse;var help=_interopRequireWildcard(require("../help-message/print-help-message.js"));var _utils=require("../utils.js");function _interopRequireWildcard(e,t){if("function"==typeof WeakMap)var r=new WeakMap(),n=new WeakMap();return(_interopRequireWildcard=function(e,t){if(!t&&e&&e.__esModule)return e;var o,i,f={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return f;if(o=t?n:r){if(o.has(e))return o.get(e);o.set(e,f);}for(const t in e)"default"!==t&&{}.hasOwnProperty.call(e,t)&&((i=(o=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,t))&&(i.get||i.set)?o(f,t,i):f[t]=e[t]);return f;})(e,t);}function parse(argsv,...params){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.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=(cmd=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;}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.parse=parse;var z=_interopRequireWildcard(require("zod/v4/core"));var help=_interopRequireWildcard(require("../help-message/print-help-message.js"));var _utils=require("../utils.js");var _zodUtils=require("../zodUtils.js");function _interopRequireWildcard(e,t){if("function"==typeof WeakMap)var r=new WeakMap(),n=new WeakMap();return(_interopRequireWildcard=function(e,t){if(!t&&e&&e.__esModule)return e;var o,i,f={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return f;if(o=t?n:r){if(o.has(e))return o.get(e);o.set(e,f);}for(const t in e)"default"!==t&&{}.hasOwnProperty.call(e,t)&&((i=(o=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,t))&&(i.get||i.set)?o(f,t,i):f[t]=e[t]);return f;})(e,t);}function parse(argsv,...params){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.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=(cmd=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.negateOption)(o.name)===optionName)return true;if(!o.aliases)return false;if(o.aliases.includes(optionName))return true;if(isNegative&&o.aliases.map(_utils.negateOption).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,_zodUtils.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=(0,_zodUtils.safeParseSchema)(option.type,optionValue);if(!res.success){throw new Error(`Invalid value "${optionValue}" for "${argument}": ${z.prettifyError(res.error)}`);}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,_zodUtils.isBooleanSchema)(argType);if(isTypeBoolean)argValue=(0,_utils.stringToBoolean)(argValue);const res=(0,_zodUtils.safeParseSchema)(argType,argValue);if(!res.success){throw new Error(`The ${(0,_utils.getOrdinalPlacement)(currentArgCount)} argument "${arg}" is invalid: ${z.prettifyError(res.error)}`);}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((0,_zodUtils.isOptionalSchema)(option.type)){const optionDefaultValue=(0,_zodUtils.schemaDefaultValue)(option.type);if(optionDefaultValue===undefined)continue;results[option.name]=optionDefaultValue;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 argumentDefaultValue=(0,_zodUtils.schemaDefaultValue)(argumentType);if(argumentDefaultValue!==undefined&&results.arguments){results.arguments.push(argumentDefaultValue);continue;}if((0,_zodUtils.isOptionalSchema)(argumentType))continue;throw new Error(`the ${(0,_utils.getOrdinalPlacement)(i)} argument is required: "${subcommandProps.arguments[i].name}"`);}}}if(subcommandProps?.action){subcommandProps.action(results);}return results;}
@@ -1 +1 @@
1
- {"version":3,"names":["help","_interopRequireWildcard","require","_utils","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","parse","argsv","params","cliOptions","subcommandArr","allSubcommands","Set","flatMap","c","name","aliases","decoupleFlags","results","subcommand","undefined","printCliHelp","opt","printSubcommandHelp","subcommandStr","find","length","includes","console","error","cliName","GetSubcommandProps","cmd","addRawArg","optionName","rawArg","_info","create","addRawValue","rawValue","addSource","source","fillOption","value","assign","arg","subcommandProps","allowPositional","positional","arguments","argAndValue","split","filter","Boolean","argWithEquals","argument","argValue","isOptionArg","isFlagArg","Error","options","msg","transformArg","isNegative","startsWith","option","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"],"sourceRoot":"../../../src/parser","sources":["parse.ts"],"sourcesContent":["import * as help from \"../help-message/print-help-message.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 { Cli, NoSubcommand, Option, PrintHelpOpt, Subcommand, UnSafeParseResult } from \"../types.js\";\n\nexport function parse<T extends Subcommand[], U extends Cli>(\n argsv: string[],\n ...params: [U, ...T]\n): UnSafeParseResult<[...T, NoSubcommand & U]> {\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"],"mappings":"0FAAA,IAAAA,IAAA,CAAAC,uBAAA,CAAAC,OAAA,2CACA,IAAAC,MAAA,CAAAD,OAAA,gBAUqB,SAAAD,wBAAAG,CAAA,CAAAC,CAAA,wBAAAC,O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AAS,CAACvD,CAAC,CAAC,CAACqB,IAAI,GAAG,CAAC,CAC/G,CACF,CACF,CAEA,GAAI+B,eAAe,EAAE+C,MAAM,CAAE,CAC3B/C,eAAe,CAAC+C,MAAM,CAAC3E,OAAO,CAAC,CACjC,CAEA,MAAO,CAAAA,OAAO,CAChB","ignoreList":[]}
1
+ {"version":3,"names":["z","_interopRequireWildcard","require","help","_utils","_zodUtils","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","parse","argsv","params","cliOptions","subcommandArr","allSubcommands","Set","flatMap","c","name","aliases","decoupleFlags","results","subcommand","undefined","printCliHelp","opt","printSubcommandHelp","subcommandStr","find","length","includes","console","error","cliName","GetSubcommandProps","cmd","addRawArg","optionName","rawArg","_info","create","addRawValue","rawValue","addSource","source","fillOption","value","assign","arg","subcommandProps","allowPositional","positional","arguments","argAndValue","split","filter","Boolean","argWithEquals","argument","argValue","isOptionArg","isFlagArg","Error","options","msg","transformArg","isNegative","startsWith","option","negateOption","map","isTypeBoolean","isBooleanSchema","type","nextArg","optionValue","parsedBoolean","stringToBoolean","res","safeParseSchema","success","prettifyError","data","rawVal","currentArgCount","argType","getOrdinalPlacement","push","isOptionalSchema","optionDefaultValue","schemaDefaultValue","transformOptionToArg","subcommandArgCount","argumentType","argumentDefaultValue","action"],"sourceRoot":"../../../src/parser","sources":["parse.ts"],"sourcesContent":["import * as z from \"zod/v4/core\";\n\nimport * as help from \"../help-message/print-help-message.js\";\nimport {\n decoupleFlags,\n getOrdinalPlacement,\n isFlagArg,\n isOptionArg,\n negateOption,\n stringToBoolean,\n transformArg,\n transformOptionToArg,\n} from \"../utils.js\";\nimport { isBooleanSchema, isOptionalSchema, safeParseSchema, schemaDefaultValue } from \"../zodUtils.js\";\n\nimport type { Cli, NoSubcommand, Option, PrintHelpOpt, Subcommand, UnSafeParseResult } from \"../types.js\";\n\nexport function parse<T extends Subcommand[], U extends Cli>(\n argsv: string[],\n ...params: [U, ...T]\n): UnSafeParseResult<[...T, NoSubcommand & U]> {\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 && negateOption(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(negateOption).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 = safeParseSchema(option.type, optionValue);\n if (!res.success) {\n throw new Error(`Invalid value \"${optionValue}\" for \"${argument}\": ${z.prettifyError(res.error)}`);\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 = safeParseSchema(argType, argValue);\n if (!res.success) {\n throw new Error(\n `The ${getOrdinalPlacement(currentArgCount)} argument \"${arg}\" is invalid: ${z.prettifyError(res.error)}`,\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 (isOptionalSchema(option.type)) {\n const optionDefaultValue = schemaDefaultValue(option.type);\n if (optionDefaultValue === undefined) continue;\n results[option.name] = optionDefaultValue;\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 argumentDefaultValue = schemaDefaultValue(argumentType);\n if (argumentDefaultValue !== undefined && results.arguments) {\n results.arguments.push(argumentDefaultValue);\n continue;\n }\n\n if (isOptionalSchema(argumentType)) 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"],"mappings":"0FAAA,IAAAA,CAAA,CAAAC,uBAAA,CAAAC,OAAA,iBAEA,IAAAC,IAAA,CAAAF,uBAAA,CAAAC,OAAA,2CACA,IAAAE,MAAA,CAAAF,OAAA,gBAUA,IAAAG,SAAA,CAAAH,OAAA,mBAAwG,SAAAD,wBAAAK,CAAA,CAAAC,CAAA,wBAAAC,OAAA,KAAAC,CAAA,KAAAD,OAAA,GAAAE,CAAA,KAAAF,OAAA,UAAAP,uBAAA,SAAAA,CAAAK,CAAA,CAAAC,CAAA,MAAAA,CAAA,EAAAD,CAAA,EAAAA,CAAA,CAAAK,UAAA,QAAAL,CAAA,KAAAM,CAAA,CAAAC,CAAA,CAAAC,CAAA,EAAAC,SAAA,MAAAC,OAAA,CAAAV,CAAA,YAAAA,CAAA,mBAAAA,CAAA,qBAAAA,CAAA,QAAAQ,CAAA,IAAAF,CAAA,CAAAL,CAAA,CAAAG,CA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EAAEG,SAAS,EAAEvB,MAAM,CAAE,CACtC,KAAM,CAAAuD,eAAe,CAAG/D,OAAO,CAAC+B,SAAS,EAAEvB,MAAM,EAAI,CAAC,CACtD,KAAM,CAAA+D,kBAAkB,CAAG3C,eAAe,CAACG,SAAS,CAACvB,MAAM,CAG3D,GAAIuD,eAAe,CAAGQ,kBAAkB,CAAE,CACxC,IAAK,GAAI,CAAA/F,CAAC,CAAGuF,eAAe,CAAEvF,CAAC,CAAG+F,kBAAkB,CAAE/F,CAAC,EAAE,CAAE,CACzD,KAAM,CAAAgG,YAAY,CAAG5C,eAAe,CAACG,SAAS,CAACvD,CAAC,CAAC,CAAC4E,IAAI,CACtD,KAAM,CAAAqB,oBAAoB,CAAG,GAAAJ,4BAAkB,EAACG,YAAY,CAAC,CAC7D,GAAIC,oBAAoB,GAAKvE,SAAS,EAAIF,OAAO,CAAC+B,SAAS,CAAE,CAC3D/B,OAAO,CAAC+B,SAAS,CAACmC,IAAI,CAACO,oBAAoB,CAAC,CAC5C,SACF,CAEA,GAAI,GAAAN,0BAAgB,EAACK,YAAY,CAAC,CAAE,SAEpC,KAAM,IAAI,CAAA/B,KAAK,CAAC,OAAO,GAAAwB,0BAAmB,EAACzF,CAAC,CAAC,2BAA2BoD,eAAe,CAACG,SAAS,CAACvD,CAAC,CAAC,CAACqB,IAAI,GAAG,CAAC,CAC/G,CACF,CACF,CAEA,GAAI+B,eAAe,EAAE8C,MAAM,CAAE,CAC3B9C,eAAe,CAAC8C,MAAM,CAAC1E,OAAO,CAAC,CACjC,CAEA,MAAO,CAAAA,OAAO,CAChB","ignoreList":[]}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.decoupleFlags=decoupleFlags;exports.getDefaultValueFromSchema=getDefaultValueFromSchema;exports.getOrdinalPlacement=getOrdinalPlacement;exports.isBooleanSchema=isBooleanSchema;exports.isFlagArg=isFlagArg;exports.isLongArg=isLongArg;exports.isOptionArg=isOptionArg;exports.noName=noName;exports.stringToBoolean=stringToBoolean;exports.transformArg=transformArg;exports.transformOptionToArg=transformOptionToArg;var _nodeAssert=_interopRequireDefault(require("node:assert"));var _zod=require("zod");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e};}function transformArg(name){(0,_nodeAssert.default)(name.startsWith("-"),`[transformArg] Invalid arg name: ${name}`);name=name.startsWith("--")?name.substring(2):name.substring(1);return name.replace(/-([a-z])/g,g=>g[1].toUpperCase());}function transformOptionToArg(name){name=name.replace(/^[A-Z]/g,g=>g.toLowerCase());if(name.length===1)return`-${name}`;return`--${name.replace(/[A-Z]/g,g=>"-"+g.toLowerCase())}`;}function isFlagArg(name){return /^-[A-Z-a-z]$/.test(name);}function isLongArg(name){return /^--[A-Z-a-z-]+[A-Z-a-z]$/.test(name);}function isOptionArg(name){if(typeof name!=="string")return false;return isFlagArg(name)||isLongArg(name);}function noName(name){if(name.length===1)return name;return"no"+name.replace(/^[a-z]/,g=>g.toUpperCase());}function stringToBoolean(str){if(str.toLowerCase()==="true")return true;if(str.toLowerCase()==="false")return false;throw new Error(`[stringToBoolean] Invalid boolean value: "${str}"; Expected "true" or "false"`);}function getOrdinalPlacement(index){if(index<0)return"";const suffixes=["th","st","nd","rd"];const lastDigit=index%10;const lastTwoDigits=index%100;const suffix=lastDigit===1&&lastTwoDigits!==11?suffixes[1]:lastDigit===2&&lastTwoDigits!==12?suffixes[2]:lastDigit===3&&lastTwoDigits!==13?suffixes[3]:suffixes[0];return`${index+1}${suffix}`;}function isBooleanSchema(schema){let type=schema;while(type){if(type instanceof _zod.z.ZodBoolean){return true;}if(type instanceof _zod.z.ZodLiteral){return type.value===true||type.value===false;}type=type._def.innerType;}return false;}function getDefaultValueFromSchema(schema){let type=schema;while(type){if(type instanceof _zod.z.ZodDefault){const defaultValue=type._def.defaultValue();return defaultValue;}type=type._def.innerType;}return undefined;}function decoupleFlags(args){const flagsRe=/^-[a-z]{2,}$/i;const result=[];for(let i=0;i<args.length;i++){const arg=args[i];const isCoupled=flagsRe.test(arg);if(!isCoupled){result.push(arg);continue;}const decoupledArr=arg.substring(1).split("").map(c=>"-"+c);result.push(...decoupledArr);}return result;}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.decoupleFlags=decoupleFlags;exports.getOrdinalPlacement=getOrdinalPlacement;exports.isFlagArg=isFlagArg;exports.isLongArg=isLongArg;exports.isOptionArg=isOptionArg;exports.negateOption=negateOption;exports.stringToBoolean=stringToBoolean;exports.transformArg=transformArg;exports.transformOptionToArg=transformOptionToArg;var _nodeAssert=_interopRequireDefault(require("node:assert"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e};}function transformArg(name){(0,_nodeAssert.default)(name.startsWith("-"),`[transformArg] Invalid arg name: ${name}`);name=name.startsWith("--")?name.substring(2):name.substring(1);return name.replace(/-([a-z])/g,g=>g[1].toUpperCase());}function transformOptionToArg(name){name=name.replace(/^[A-Z]/g,g=>g.toLowerCase());if(name.length===1)return`-${name}`;return`--${name.replace(/[A-Z]/g,g=>"-"+g.toLowerCase())}`;}function isFlagArg(name){return /^-[A-Z-a-z]$/.test(name);}function isLongArg(name){return /^--[A-Z-a-z-]+[A-Z-a-z]$/.test(name);}function isOptionArg(name){if(typeof name!=="string")return false;return isFlagArg(name)||isLongArg(name);}function negateOption(name){if(name.length===1)return name;return"no"+name.replace(/^[a-z]/,g=>g.toUpperCase());}function stringToBoolean(str){if(str.toLowerCase()==="true")return true;if(str.toLowerCase()==="false")return false;throw new Error(`[stringToBoolean] Invalid boolean value: "${str}"; Expected "true" or "false"`);}function getOrdinalPlacement(index){if(index<0)return"";const suffixes=["th","st","nd","rd"];const lastDigit=index%10;const lastTwoDigits=index%100;const suffix=lastDigit===1&&lastTwoDigits!==11?suffixes[1]:lastDigit===2&&lastTwoDigits!==12?suffixes[2]:lastDigit===3&&lastTwoDigits!==13?suffixes[3]:suffixes[0];return`${index+1}${suffix}`;}function decoupleFlags(args){const flagsRe=/^-[a-z]{2,}$/i;const result=[];for(let i=0;i<args.length;i++){const arg=args[i];const isCoupled=flagsRe.test(arg);if(!isCoupled){result.push(arg);continue;}const decoupledArr=arg.substring(1).split("").map(c=>"-"+c);result.push(...decoupledArr);}return result;}
@@ -1 +1 @@
1
- {"version":3,"names":["_nodeAssert","_interopRequireDefault","require","_zod","e","__esModule","default","transformArg","name","assert","startsWith","substring","replace","g","toUpperCase","transformOptionToArg","toLowerCase","length","isFlagArg","test","isLongArg","isOptionArg","noName","stringToBoolean","str","Error","getOrdinalPlacement","index","suffixes","lastDigit","lastTwoDigits","suffix","isBooleanSchema","schema","type","z","ZodBoolean","ZodLiteral","value","_def","innerType","getDefaultValueFromSchema","ZodDefault","defaultValue","undefined","decoupleFlags","args","flagsRe","result","i","arg","isCoupled","push","decoupledArr","split","map","c"],"sourceRoot":"../../src","sources":["utils.ts"],"sourcesContent":["import assert from \"node:assert\";\nimport { z } from \"zod\";\n\n/**\n * @param name - Should start with `'--'`\n * @returns - The transformed name E.g. `--input-dir` -> `InputDir`\n */\nexport function transformArg(name: string): string {\n assert(name.startsWith(\"-\"), `[transformArg] Invalid arg name: ${name}`);\n name = name.startsWith(\"--\") ? name.substring(2) : name.substring(1);\n return name.replace(/-([a-z])/g, g => g[1].toUpperCase());\n}\n\n/** - Reverse of `transformArg`. E.g. `InputDir` -> `--input-dir` , `i` -> `-i` */\nexport function transformOptionToArg(name: string): string {\n name = name.replace(/^[A-Z]/g, g => g.toLowerCase()); // first letter always lower case\n if (name.length === 1) return `-${name}`;\n return `--${name.replace(/[A-Z]/g, g => \"-\" + g.toLowerCase())}`;\n}\n\n/** - Check if an arg string is a short arg. E.g. `-i` -> `true` */\nexport function isFlagArg(name: string): boolean {\n return /^-[A-Z-a-z]$/.test(name);\n}\n\n/** - Check if an arg string is a long arg. E.g. `--input-dir` -> `true` */\nexport function isLongArg(name: string): boolean {\n return /^--[A-Z-a-z-]+[A-Z-a-z]$/.test(name);\n}\n\n/** - Check if an arg string is an options arg. E.g. `--input-dir` -> `true` , `-i` -> `true` */\nexport function isOptionArg(name: string | boolean): boolean {\n if (typeof name !== \"string\") return false;\n return isFlagArg(name) || isLongArg(name);\n}\n\n/**\n * - Transform option name to no name. E.g. `include` -> `noInclude`\n * - For short name like `-i` it will be ignored\n */\nexport function noName(name: string): string {\n if (name.length === 1) return name;\n return \"no\" + name.replace(/^[a-z]/, g => g.toUpperCase());\n}\n\n/** - Convert string to boolean. E.g. `\"true\"` -> `true` , `\"false\"` -> `false` */\nexport function stringToBoolean(str: string): boolean {\n if (str.toLowerCase() === \"true\") return true;\n if (str.toLowerCase() === \"false\") return false;\n throw new Error(`[stringToBoolean] Invalid boolean value: \"${str}\"; Expected \"true\" or \"false\"`);\n}\n\nexport function getOrdinalPlacement(index: number): string {\n if (index < 0) return \"\";\n\n const suffixes = [\"th\", \"st\", \"nd\", \"rd\"];\n const lastDigit = index % 10;\n const lastTwoDigits = index % 100;\n\n const suffix =\n lastDigit === 1 && lastTwoDigits !== 11\n ? suffixes[1]\n : lastDigit === 2 && lastTwoDigits !== 12\n ? suffixes[2]\n : lastDigit === 3 && lastTwoDigits !== 13\n ? suffixes[3]\n : suffixes[0];\n\n return `${index + 1}${suffix}`;\n}\n\n/** - Check if a schema is a boolean */\nexport function isBooleanSchema(schema: z.ZodTypeAny): boolean {\n let type = schema;\n while (type) {\n if (type instanceof z.ZodBoolean) {\n return true;\n }\n\n if (type instanceof z.ZodLiteral) {\n return type.value === true || type.value === false;\n }\n\n type = type._def.innerType;\n }\n\n return false;\n}\n\nexport function getDefaultValueFromSchema(schema: z.ZodTypeAny): unknown | undefined {\n let type = schema;\n while (type) {\n if (type instanceof z.ZodDefault) {\n const defaultValue = type._def.defaultValue();\n return defaultValue;\n }\n\n type = type._def.innerType;\n }\n\n return undefined;\n}\n\n/** - Decouple flags E.g. `-rf` -> `-r, -f` */\nexport function decoupleFlags(args: string[]): string[] {\n const flagsRe = /^-[a-z]{2,}$/i;\n\n const result = [];\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n const isCoupled = flagsRe.test(arg);\n\n if (!isCoupled) {\n result.push(arg);\n continue;\n }\n\n const decoupledArr = arg\n .substring(1)\n .split(\"\")\n .map(c => \"-\" + c);\n\n result.push(...decoupledArr);\n }\n\n return result;\n}\n"],"mappings":"weAAA,IAAAA,WAAA,CAAAC,sBAAA,CAAAC,OAAA,iBACA,IAAAC,IAAA,CAAAD,OAAA,QAAwB,SAAAD,uBAAAG,CAAA,SAAAA,CAAA,EAAAA,CAAA,CAAAC,UAAA,CAAAD,CAAA,EAAAE,OAAA,CAAAF,CAAA,GAMjB,QAAS,CAAAG,YAAYA,CAACC,IAAY,CAAU,CACjD,GAAAC,mBAAM,EAACD,IAAI,CAACE,UAAU,CAAC,GAAG,CAAC,CAAE,oCAAoCF,IAAI,EAAE,CAAC,CACxEA,IAAI,CAAGA,IAAI,CAACE,UAAU,CAAC,IAAI,CAAC,CAAGF,IAAI,CAACG,SAAS,CAAC,CAAC,CAAC,CAAGH,IAAI,CAACG,SAAS,CAAC,CAAC,CAAC,CACpE,MAAO,CAAAH,IAAI,CAACI,OAAO,CAAC,WAAW,CAAEC,CAAC,EAAIA,CAAC,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC,CAAC,CAC3D,CAGO,QAAS,CAAAC,oBAAoBA,CAACP,IAAY,CAAU,CACzDA,IAAI,CAAGA,IAAI,CAACI,OAAO,CAAC,SAAS,CAAEC,CAAC,EAAIA,CAAC,CAACG,WAAW,CAAC,CAAC,CAAC,CACpD,GAAIR,IAAI,CAACS,MAAM,GAAK,CAAC,CAAE,MAAO,IAAIT,IAAI,EAAE,CACxC,MAAO,KAAKA,IAAI,CAACI,OAAO,CAAC,QAAQ,CAAEC,CAAC,EAAI,GAAG,CAAGA,CAAC,CAACG,WAAW,CAAC,CAAC,CAAC,EAAE,CAClE,CAGO,QAAS,CAAAE,SAASA,CAACV,IAAY,CAAW,CAC/C,MAAO,eAAc,CAACW,IAAI,CAACX,IAAI,CAAC,CAClC,CA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,CACpC,KAAM,CAAAC,GAAG,CAAGJ,IAAI,CAACG,CAAC,CAAC,CACnB,KAAM,CAAAE,SAAS,CAAGJ,OAAO,CAAC5B,IAAI,CAAC+B,GAAG,CAAC,CAEnC,GAAI,CAACC,SAAS,CAAE,CACdH,MAAM,CAACI,IAAI,CAACF,GAAG,CAAC,CAChB,SACF,CAEA,KAAM,CAAAG,YAAY,CAAGH,GAAG,CACrBvC,SAAS,CAAC,CAAC,CAAC,CACZ2C,KAAK,CAAC,EAAE,CAAC,CACTC,GAAG,CAACC,CAAC,EAAI,GAAG,CAAGA,CAAC,CAAC,CAEpBR,MAAM,CAACI,IAAI,CAAC,GAAGC,YAAY,CAAC,CAC9B,CAEA,MAAO,CAAAL,MAAM,CACf","ignoreList":[]}
1
+ {"version":3,"names":["_nodeAssert","_interopRequireDefault","require","e","__esModule","default","transformArg","name","assert","startsWith","substring","replace","g","toUpperCase","transformOptionToArg","toLowerCase","length","isFlagArg","test","isLongArg","isOptionArg","negateOption","stringToBoolean","str","Error","getOrdinalPlacement","index","suffixes","lastDigit","lastTwoDigits","suffix","decoupleFlags","args","flagsRe","result","i","arg","isCoupled","push","decoupledArr","split","map","c"],"sourceRoot":"../../src","sources":["utils.ts"],"sourcesContent":["import assert from \"node:assert\";\n\n/**\n * @param name - Should start with `'--'`\n * @returns - The transformed name E.g. `--input-dir` -> `InputDir`\n */\nexport function transformArg(name: string): string {\n assert(name.startsWith(\"-\"), `[transformArg] Invalid arg name: ${name}`);\n name = name.startsWith(\"--\") ? name.substring(2) : name.substring(1);\n return name.replace(/-([a-z])/g, g => g[1].toUpperCase());\n}\n\n/** - Reverse of `transformArg`. E.g. `InputDir` -> `--input-dir` , `i` -> `-i` */\nexport function transformOptionToArg(name: string): string {\n name = name.replace(/^[A-Z]/g, g => g.toLowerCase()); // first letter always lower case\n if (name.length === 1) return `-${name}`;\n return `--${name.replace(/[A-Z]/g, g => \"-\" + g.toLowerCase())}`;\n}\n\n/** - Check if an arg string is a short arg. E.g. `-i` -> `true` */\nexport function isFlagArg(name: string): boolean {\n return /^-[A-Z-a-z]$/.test(name);\n}\n\n/** - Check if an arg string is a long arg. E.g. `--input-dir` -> `true` */\nexport function isLongArg(name: string): boolean {\n return /^--[A-Z-a-z-]+[A-Z-a-z]$/.test(name);\n}\n\n/** - Check if an arg string is an options arg. E.g. `--input-dir` -> `true` , `-i` -> `true` */\nexport function isOptionArg(name: string | boolean): boolean {\n if (typeof name !== \"string\") return false;\n return isFlagArg(name) || isLongArg(name);\n}\n\n/**\n * - Transform option name to no name. E.g. `include` -> `noInclude`\n * - For short name like `-i` it will be ignored\n */\nexport function negateOption(name: string): string {\n if (name.length === 1) return name;\n return \"no\" + name.replace(/^[a-z]/, g => g.toUpperCase());\n}\n\n/** - Convert string to boolean. E.g. `\"true\"` -> `true` , `\"false\"` -> `false` */\nexport function stringToBoolean(str: string): boolean {\n if (str.toLowerCase() === \"true\") return true;\n if (str.toLowerCase() === \"false\") return false;\n throw new Error(`[stringToBoolean] Invalid boolean value: \"${str}\"; Expected \"true\" or \"false\"`);\n}\n\nexport function getOrdinalPlacement(index: number): string {\n if (index < 0) return \"\";\n\n const suffixes = [\"th\", \"st\", \"nd\", \"rd\"];\n const lastDigit = index % 10;\n const lastTwoDigits = index % 100;\n\n const suffix =\n lastDigit === 1 && lastTwoDigits !== 11\n ? suffixes[1]\n : lastDigit === 2 && lastTwoDigits !== 12\n ? suffixes[2]\n : lastDigit === 3 && lastTwoDigits !== 13\n ? suffixes[3]\n : suffixes[0];\n\n return `${index + 1}${suffix}`;\n}\n\n/** - Decouple flags E.g. `-rf` -> `-r, -f` */\nexport function decoupleFlags(args: string[]): string[] {\n const flagsRe = /^-[a-z]{2,}$/i;\n\n const result = [];\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n const isCoupled = flagsRe.test(arg);\n\n if (!isCoupled) {\n result.push(arg);\n continue;\n }\n\n const decoupledArr = arg\n .substring(1)\n .split(\"\")\n .map(c => \"-\" + c);\n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CAErB,MAAO,GAAGD,KAAK,CAAG,CAAC,GAAGI,MAAM,EAAE,CAChC,CAGO,QAAS,CAAAC,aAAaA,CAACC,IAAc,CAAY,CACtD,KAAM,CAAAC,OAAO,CAAG,eAAe,CAE/B,KAAM,CAAAC,MAAM,CAAG,EAAE,CACjB,IAAK,GAAI,CAAAC,CAAC,CAAG,CAAC,CAAEA,CAAC,CAAGH,IAAI,CAAChB,MAAM,CAAEmB,CAAC,EAAE,CAAE,CACpC,KAAM,CAAAC,GAAG,CAAGJ,IAAI,CAACG,CAAC,CAAC,CACnB,KAAM,CAAAE,SAAS,CAAGJ,OAAO,CAACf,IAAI,CAACkB,GAAG,CAAC,CAEnC,GAAI,CAACC,SAAS,CAAE,CACdH,MAAM,CAACI,IAAI,CAACF,GAAG,CAAC,CAChB,SACF,CAEA,KAAM,CAAAG,YAAY,CAAGH,GAAG,CACrB1B,SAAS,CAAC,CAAC,CAAC,CACZ8B,KAAK,CAAC,EAAE,CAAC,CACTC,GAAG,CAACC,CAAC,EAAI,GAAG,CAAGA,CAAC,CAAC,CAEpBR,MAAM,CAACI,IAAI,CAAC,GAAGC,YAAY,CAAC,CAC9B,CAEA,MAAO,CAAAL,MAAM,CACf","ignoreList":[]}
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.isBooleanSchema=isBooleanSchema;exports.isOptionalSchema=isOptionalSchema;exports.safeParseSchema=safeParseSchema;exports.schemaDefaultValue=schemaDefaultValue;exports.schemaDescription=schemaDescription;var Z3=_interopRequireWildcard(require("zod/v3"));var Z4=_interopRequireWildcard(require("zod/v4/core"));function _interopRequireWildcard(e,t){if("function"==typeof WeakMap)var r=new WeakMap(),n=new WeakMap();return(_interopRequireWildcard=function(e,t){if(!t&&e&&e.__esModule)return e;var o,i,f={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return f;if(o=t?n:r){if(o.has(e))return o.get(e);o.set(e,f);}for(const t in e)"default"!==t&&{}.hasOwnProperty.call(e,t)&&((i=(o=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,t))&&(i.get||i.set)?o(f,t,i):f[t]=e[t]);return f;})(e,t);}function isV4Schema(schema){return"_zod"in schema;}function safeParseSchema(schema,value){if(isV4Schema(schema)){return Z4.safeParse(schema,value);}return schema.safeParse(value);}function isBooleanSchema(schema){if(isV4Schema(schema)){return isBooleanV4Schema(schema);}return isBooleanV3Schema(schema);}function isBooleanV4Schema(schema){let def=schema._zod.def;while(def){if(def.type==="boolean"){return true;}if(isLiteralV4Def(def)){return def.values.includes(true)||def.values.includes(false);}if(!isV4DefWithInnerType(def)){return false;}def=def.innerType._zod.def;}return false;}function isBooleanV3Schema(schema){let type=schema;while(type){if(type instanceof Z3.ZodBoolean){return true;}if(type instanceof Z3.ZodLiteral){return type.value===true||type.value===false;}type=type._def.innerType;}return false;}function schemaDefaultValue(schema){if(isV4Schema(schema)){return schemaV4DefaultValue(schema);}return schemaV3DefaultValue(schema);}function schemaV4DefaultValue(schema){let def=schema._zod.def;while(def){if(isDefaultV4Def(def))return def.defaultValue;if(!isV4DefWithInnerType(def))return undefined;def=def.innerType._zod.def;}return undefined;}function schemaV3DefaultValue(schema){let type=schema;while(type){if(type instanceof Z3.ZodDefault){const defaultValue=type._def.defaultValue();return defaultValue;}type=type._def.innerType;}return undefined;}function schemaDescription(schema){if(isV4Schema(schema)){if(!("meta"in schema)||typeof schema.meta!=="function")return;return schema.meta()?.description;}return schema.description;}function isOptionalSchema(schema){if(isV4Schema(schema)){return schema._zod.def.type==="optional"||schema._zod.def.type==="default";}return schema.isOptional();}function isDefaultV4Def(def){return def.type==="default";}function isLiteralV4Def(def){return def.type==="literal";}function isV4DefWithInnerType(def){return new Set(["default","prefault","optional","nonoptional","nullable","success","catch","readonly","promise"]).has(def.type);}
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Z3","_interopRequireWildcard","require","Z4","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","isV4Schema","schema","safeParseSchema","value","safeParse","isBooleanSchema","isBooleanV4Schema","isBooleanV3Schema","def","_zod","type","isLiteralV4Def","values","includes","isV4DefWithInnerType","innerType","ZodBoolean","ZodLiteral","_def","schemaDefaultValue","schemaV4DefaultValue","schemaV3DefaultValue","isDefaultV4Def","defaultValue","undefined","ZodDefault","schemaDescription","meta","description","isOptionalSchema","isOptional","Set"],"sourceRoot":"../../src","sources":["zodUtils.ts"],"sourcesContent":["import * as Z3 from \"zod/v3\";\nimport * as Z4 from \"zod/v4/core\";\n\nimport type { Schema, SchemaV3, SchemaV4 } from \"./types.js\";\n\nfunction isV4Schema(schema: Schema): schema is SchemaV4 {\n return \"_zod\" in schema;\n}\n\n/** - Safe parse a value against a schema */\nexport function safeParseSchema(schema: Schema, value: unknown) {\n if (isV4Schema(schema)) {\n return Z4.safeParse(schema, value);\n }\n\n return schema.safeParse(value);\n}\n\n/** - Check if a schema is a boolean */\nexport function isBooleanSchema(schema: Schema): boolean {\n if (isV4Schema(schema)) {\n return isBooleanV4Schema(schema);\n }\n\n return isBooleanV3Schema(schema);\n}\n\nfunction isBooleanV4Schema(schema: SchemaV4): boolean {\n let def = schema._zod.def;\n\n while (def) {\n if (def.type === \"boolean\") {\n return true;\n }\n\n if (isLiteralV4Def(def)) {\n return def.values.includes(true) || def.values.includes(false);\n }\n\n if (!isV4DefWithInnerType(def)) {\n return false;\n }\n\n def = def.innerType._zod.def;\n }\n\n return false;\n}\n\nfunction isBooleanV3Schema(schema: SchemaV3): boolean {\n let type = schema;\n while (type) {\n if (type instanceof Z3.ZodBoolean) {\n return true;\n }\n\n if (type instanceof Z3.ZodLiteral) {\n return type.value === true || type.value === false;\n }\n\n type = type._def.innerType;\n }\n\n return false;\n}\n\n/** - Get the default value of a schema */\nexport function schemaDefaultValue(schema: Schema): unknown | undefined {\n if (isV4Schema(schema)) {\n return schemaV4DefaultValue(schema);\n }\n\n return schemaV3DefaultValue(schema);\n}\n\nfunction schemaV4DefaultValue(schema: SchemaV4): unknown | undefined {\n let def = schema._zod.def;\n\n while (def) {\n if (isDefaultV4Def(def)) return def.defaultValue;\n if (!isV4DefWithInnerType(def)) return undefined;\n def = def.innerType._zod.def;\n }\n\n return undefined;\n}\n\nfunction schemaV3DefaultValue(schema: SchemaV3): unknown | undefined {\n let type = schema;\n while (type) {\n if (type instanceof Z3.ZodDefault) {\n const defaultValue = type._def.defaultValue();\n return defaultValue;\n }\n\n type = type._def.innerType;\n }\n\n return undefined;\n}\n\n/** - Get the description of a schema */\nexport function schemaDescription(schema: Schema): string | undefined {\n if (isV4Schema(schema)) {\n if (!(\"meta\" in schema) || typeof schema.meta !== \"function\") return;\n return schema.meta()?.description;\n }\n\n return schema.description;\n}\n/** - Check if a schema is optional */\nexport function isOptionalSchema(schema: Schema): schema is Z4.$ZodOptional {\n if (isV4Schema(schema)) {\n return schema._zod.def.type === \"optional\" || schema._zod.def.type === \"default\";\n }\n\n return schema.isOptional();\n}\n\nfunction isDefaultV4Def(def: Z4.$ZodTypeDef): def is Z4.$ZodDefaultDef {\n return def.type === \"default\";\n}\n\nfunction isLiteralV4Def(def: Z4.$ZodTypeDef): def is Z4.$ZodLiteralDef<any> {\n return def.type === \"literal\";\n}\n\ntype SchemaWithInnerType =\n | Z4.$ZodDefaultDef\n | Z4.$ZodPrefaultDef\n | Z4.$ZodOptionalDef\n | Z4.$ZodNonOptionalDef\n | Z4.$ZodNullableDef\n | Z4.$ZodSuccessDef\n | Z4.$ZodCatchDef\n | Z4.$ZodReadonlyDef\n | Z4.$ZodPromiseDef;\n\nfunction isV4DefWithInnerType(def: Z4.$ZodTypeDef): def is SchemaWithInnerType {\n return new Set([\n \"default\",\n \"prefault\",\n \"optional\",\n \"nonoptional\",\n \"nullable\",\n \"success\",\n \"catch\",\n \"readonly\",\n \"promise\",\n ]).has(def.type);\n}\n"],"mappings":"0RAAA,IAAAA,EAAA,CAAAC,uBAAA,CAAAC,OAA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,CAAC,CAAC,EAAEC,WAAW,CACnC,CAEA,MAAO,CAAA3B,MAAM,CAAC2B,WAAW,CAC3B,CAEO,QAAS,CAAAC,gBAAgBA,CAAC5B,MAAc,CAA6B,CAC1E,GAAID,UAAU,CAACC,MAAM,CAAC,CAAE,CACtB,MAAO,CAAAA,MAAM,CAACQ,IAAI,CAACD,GAAG,CAACE,IAAI,GAAK,UAAU,EAAIT,MAAM,CAACQ,IAAI,CAACD,GAAG,CAACE,IAAI,GAAK,SAAS,CAClF,CAEA,MAAO,CAAAT,MAAM,CAAC6B,UAAU,CAAC,CAAC,CAC5B,CAEA,QAAS,CAAAR,cAAcA,CAACd,GAAmB,CAA4B,CACrE,MAAO,CAAAA,GAAG,CAACE,IAAI,GAAK,SAAS,CAC/B,CAEA,QAAS,CAAAC,cAAcA,CAACH,GAAmB,CAAiC,CAC1E,MAAO,CAAAA,GAAG,CAACE,IAAI,GAAK,SAAS,CAC/B,CAaA,QAAS,CAAAI,oBAAoBA,CAACN,GAAmB,CAA8B,CAC7E,MAAO,IAAI,CAAAuB,GAAG,CAAC,CACb,SAAS,CACT,UAAU,CACV,UAAU,CACV,aAAa,CACb,UAAU,CACV,SAAS,CACT,OAAO,CACP,UAAU,CACV,SAAS,CACV,CAAC,CAACvC,GAAG,CAACgB,GAAG,CAACE,IAAI,CAAC,CAClB","ignoreList":[]}
@@ -1 +1 @@
1
- import{getDefaultValueFromSchema}from"../utils.js";export function getArgumentsMetadata(args){const outputMetadata=[];for(const arg of args){const defaultValue=getDefaultValueFromSchema(arg.type);outputMetadata.push({name:arg.name,description:arg.description??arg.type.description??"",defaultValue,defaultValueAsString:JSON.stringify(defaultValue),optional:arg.type.isOptional(),example:arg.example??"",type:arg.type});}return outputMetadata;}
1
+ import{isOptionalSchema,schemaDefaultValue,schemaDescription}from"../zodUtils.js";export function getArgumentsMetadata(args){const outputMetadata=[];for(const arg of args){const defaultValue=schemaDefaultValue(arg.type);outputMetadata.push({name:arg.name,description:arg.description??schemaDescription(arg.type)??"",defaultValue,defaultValueAsString:JSON.stringify(defaultValue),optional:isOptionalSchema(arg.type),example:arg.example??"",type:arg.type});}return outputMetadata;}
@@ -1 +1 @@
1
- {"version":3,"names":["getDefaultValueFromSchema","getArgumentsMetadata","args","outputMetadata","arg","defaultValue","type","push","name","description","defaultValueAsString","JSON","stringify","optional","isOptional","example"],"sourceRoot":"../../../src/metadata","sources":["get-arguments-metadata.ts"],"sourcesContent":["import { getDefaultValueFromSchema } from \"../utils.js\";\n\nimport type { Argument, ArgumentMetadata } from \"../types.js\";\n\nexport function getArgumentsMetadata(args: Argument[]): ArgumentMetadata[] {\n const outputMetadata: ArgumentMetadata[] = [];\n\n for (const arg of args) {\n const defaultValue = getDefaultValueFromSchema(arg.type);\n\n outputMetadata.push({\n name: arg.name,\n description: arg.description ?? arg.type.description ?? \"\",\n defaultValue,\n defaultValueAsString: JSON.stringify(defaultValue),\n optional: arg.type.isOptional(),\n example: arg.example ?? \"\",\n type: arg.type,\n });\n }\n\n return outputMetadata;\n}\n"],"mappings":"AAAA,OAASA,yBAAyB,KAAQ,aAAa,CAIvD,MAAO,SAAS,CAAAC,oBAAoBA,CAACC,IAAgB,CAAsB,CACzE,KAAM,CAAAC,cAAkC,CAAG,EAAE,CAE7C,IAAK,KAAM,CAAAC,GAAG,GAAI,CAAAF,IAAI,CAAE,CACtB,KAAM,CAAAG,YAAY,CAAGL,yBAAyB,CAACI,GAAG,CAACE,IAAI,CAAC,CAExDH,cAAc,CAACI,IAAI,CAAC,CAClBC,IAAI,CAAEJ,GAAG,CAACI,IAAI,CACdC,WAAW,CAAEL,GAAG,CAACK,WAAW,EAAIL,GAAG,CAACE,IAAI,CAACG,WAAW,EAAI,EAAE,CAC1DJ,YAAY,CACZK,oBAAoB,CAAEC,IAAI,CAACC,SAAS,CAACP,YAAY,CAAC,CAClDQ,QAAQ,CAAET,GAAG,CAACE,IAAI,CAACQ,UAAU,CAAC,CAAC,CAC/BC,OAAO,CAAEX,GAAG,CAACW,OAAO,EAAI,EAAE,CAC1BT,IAAI,CAAEF,GAAG,CAACE,IACZ,CAAC,CAAC,CACJ,CAEA,MAAO,CAAAH,cAAc,CACvB","ignoreList":[]}
1
+ {"version":3,"names":["isOptionalSchema","schemaDefaultValue","schemaDescription","getArgumentsMetadata","args","outputMetadata","arg","defaultValue","type","push","name","description","defaultValueAsString","JSON","stringify","optional","example"],"sourceRoot":"../../../src/metadata","sources":["get-arguments-metadata.ts"],"sourcesContent":["import { isOptionalSchema, schemaDefaultValue, schemaDescription } from \"../zodUtils.js\";\n\nimport type { Argument, ArgumentMetadata } from \"../types.js\";\n\nexport function getArgumentsMetadata(args: Argument[]): ArgumentMetadata[] {\n const outputMetadata: ArgumentMetadata[] = [];\n\n for (const arg of args) {\n const defaultValue = schemaDefaultValue(arg.type);\n\n outputMetadata.push({\n name: arg.name,\n description: arg.description ?? schemaDescription(arg.type) ?? \"\",\n defaultValue,\n defaultValueAsString: JSON.stringify(defaultValue),\n optional: isOptionalSchema(arg.type),\n example: arg.example ?? \"\",\n type: arg.type,\n });\n }\n\n return outputMetadata;\n}\n"],"mappings":"AAAA,OAASA,gBAAgB,CAAEC,kBAAkB,CAAEC,iBAAiB,KAAQ,gBAAgB,CAIxF,MAAO,SAAS,CAAAC,oBAAoBA,CAACC,IAAgB,CAAsB,CACzE,KAAM,CAAAC,cAAkC,CAAG,EAAE,CAE7C,IAAK,KAAM,CAAAC,GAAG,GAAI,CAAAF,IAAI,CAAE,CACtB,KAAM,CAAAG,YAAY,CAAGN,kBAAkB,CAACK,GAAG,CAACE,IAAI,CAAC,CAEjDH,cAAc,CAACI,IAAI,CAAC,CAClBC,IAAI,CAAEJ,GAAG,CAACI,IAAI,CACdC,WAAW,CAAEL,GAAG,CAACK,WAAW,EAAIT,iBAAiB,CAACI,GAAG,CAACE,IAAI,CAAC,EAAI,EAAE,CACjED,YAAY,CACZK,oBAAoB,CAAEC,IAAI,CAACC,SAAS,CAACP,YAAY,CAAC,CAClDQ,QAAQ,CAAEf,gBAAgB,CAACM,GAAG,CAACE,IAAI,CAAC,CACpCQ,OAAO,CAAEV,GAAG,CAACU,OAAO,EAAI,EAAE,CAC1BR,IAAI,CAAEF,GAAG,CAACE,IACZ,CAAC,CAAC,CACJ,CAEA,MAAO,CAAAH,cAAc,CACvB","ignoreList":[]}
@@ -1 +1 @@
1
- import{getDefaultValueFromSchema,transformOptionToArg}from"../utils.js";export function getOptionsMetadata(options){const outputMetadata=[];if(!options||!options.length)return outputMetadata;for(const option of options){const defaultValue=getDefaultValueFromSchema(option.type);const aliases=option.aliases??[];outputMetadata.push({name:option.name,nameAsArg:transformOptionToArg(option.name),aliases,aliasesAsArgs:aliases.map(transformOptionToArg),placeholder:option.placeholder??"",description:option.description??option.type.description??"",optional:option.type.isOptional(),example:option.example??"",defaultValue,defaultValueAsString:JSON.stringify(defaultValue),type:option.type});}return outputMetadata;}
1
+ import{transformOptionToArg}from"../utils.js";import{isOptionalSchema,schemaDefaultValue,schemaDescription}from"../zodUtils.js";export function getOptionsMetadata(options){const outputMetadata=[];if(!options||!options.length)return outputMetadata;for(const option of options){const defaultValue=schemaDefaultValue(option.type);const aliases=option.aliases??[];outputMetadata.push({name:option.name,nameAsArg:transformOptionToArg(option.name),aliases,aliasesAsArgs:aliases.map(transformOptionToArg),placeholder:option.placeholder??"",description:option.description??schemaDescription(option.type)??"",optional:isOptionalSchema(option.type),example:option.example??"",defaultValue,defaultValueAsString:JSON.stringify(defaultValue),type:option.type});}return outputMetadata;}
@@ -1 +1 @@
1
- {"version":3,"names":["getDefaultValueFromSchema","transformOptionToArg","getOptionsMetadata","options","outputMetadata","length","option","defaultValue","type","aliases","push","name","nameAsArg","aliasesAsArgs","map","placeholder","description","optional","isOptional","example","defaultValueAsString","JSON","stringify"],"sourceRoot":"../../../src/metadata","sources":["get-options-metadata.ts"],"sourcesContent":["import { getDefaultValueFromSchema, transformOptionToArg } from \"../utils.js\";\n\nimport type { Option, OptionMetadata } from \"../types.js\";\n\nexport function getOptionsMetadata(options: Option[]): OptionMetadata[] {\n const outputMetadata: OptionMetadata[] = [];\n\n if (!options || !options.length) return outputMetadata;\n\n for (const option of options) {\n const defaultValue = getDefaultValueFromSchema(option.type);\n const aliases = option.aliases ?? [];\n\n outputMetadata.push({\n name: option.name,\n nameAsArg: transformOptionToArg(option.name),\n aliases,\n aliasesAsArgs: aliases.map(transformOptionToArg),\n placeholder: option.placeholder ?? \"\",\n description: option.description ?? option.type.description ?? \"\",\n optional: option.type.isOptional(),\n example: option.example ?? \"\",\n defaultValue,\n defaultValueAsString: JSON.stringify(defaultValue),\n type: option.type,\n });\n }\n\n return outputMetadata;\n}\n"],"mappings":"AAAA,OAASA,yBAAyB,CAAEC,oBAAoB,KAAQ,aAAa,CAI7E,MAAO,SAAS,CAAAC,kBAAkBA,CAACC,OAAiB,CAAoB,CACtE,KAAM,CAAAC,cAAgC,CAAG,EAAE,CAE3C,GAAI,CAACD,OAAO,EAAI,CAACA,OAAO,CAACE,MAAM,CAAE,MAAO,CAAAD,cAAc,CAEtD,IAAK,KAAM,CAAAE,MAAM,GAAI,CAAAH,OAAO,CAAE,CAC5B,KAAM,CAAAI,YAAY,CAAGP,yBAAyB,CAACM,MAAM,CAACE,IAAI,CAAC,CAC3D,KAAM,CAAAC,OAAO,CAAGH,MAAM,CAACG,OAAO,EAAI,EAAE,CAEpCL,cAAc,CAACM,IAAI,CAAC,CAClBC,IAAI,CAAEL,MAAM,CAACK,IAAI,CACjBC,SAAS,CAAEX,oBAAoB,CAACK,MAAM,CAACK,IAAI,CAAC,CAC5CF,OAAO,CACPI,aAAa,CAAEJ,OAAO,CAACK,GAAG,CAACb,oBAAoB,CAAC,CAChDc,WAAW,CAAET,MAAM,CAACS,WAAW,EAAI,EAAE,CACrCC,WAAW,CAAEV,MAAM,CAACU,WAAW,EAAIV,MAAM,CAACE,IAAI,CAACQ,WAAW,EAAI,EAAE,CAChEC,QAAQ,CAAEX,MAAM,CAACE,IAAI,CAACU,UAAU,CAAC,CAAC,CAClCC,OAAO,CAAEb,MAAM,CAACa,OAAO,EAAI,EAAE,CAC7BZ,YAAY,CACZa,oBAAoB,CAAEC,IAAI,CAACC,SAAS,CAACf,YAAY,CAAC,CAClDC,IAAI,CAAEF,MAAM,CAACE,IACf,CAAC,CAAC,CACJ,CAEA,MAAO,CAAAJ,cAAc,CACvB","ignoreList":[]}
1
+ {"version":3,"names":["transformOptionToArg","isOptionalSchema","schemaDefaultValue","schemaDescription","getOptionsMetadata","options","outputMetadata","length","option","defaultValue","type","aliases","push","name","nameAsArg","aliasesAsArgs","map","placeholder","description","optional","example","defaultValueAsString","JSON","stringify"],"sourceRoot":"../../../src/metadata","sources":["get-options-metadata.ts"],"sourcesContent":["import { transformOptionToArg } from \"../utils.js\";\nimport { isOptionalSchema, schemaDefaultValue, schemaDescription } from \"../zodUtils.js\";\n\nimport type { Option, OptionMetadata } from \"../types.js\";\n\nexport function getOptionsMetadata(options: Option[]): OptionMetadata[] {\n const outputMetadata: OptionMetadata[] = [];\n\n if (!options || !options.length) return outputMetadata;\n\n for (const option of options) {\n const defaultValue = schemaDefaultValue(option.type);\n const aliases = option.aliases ?? [];\n\n outputMetadata.push({\n name: option.name,\n nameAsArg: transformOptionToArg(option.name),\n aliases,\n aliasesAsArgs: aliases.map(transformOptionToArg),\n placeholder: option.placeholder ?? \"\",\n description: option.description ?? schemaDescription(option.type) ?? \"\",\n optional: isOptionalSchema(option.type),\n example: option.example ?? \"\",\n defaultValue,\n defaultValueAsString: JSON.stringify(defaultValue),\n type: option.type,\n });\n }\n\n return outputMetadata;\n}\n"],"mappings":"AAAA,OAASA,oBAAoB,KAAQ,aAAa,CAClD,OAASC,gBAAgB,CAAEC,kBAAkB,CAAEC,iBAAiB,KAAQ,gBAAgB,CAIxF,MAAO,SAAS,CAAAC,kBAAkBA,CAACC,OAAiB,CAAoB,CACtE,KAAM,CAAAC,cAAgC,CAAG,EAAE,CAE3C,GAAI,CAACD,OAAO,EAAI,CAACA,OAAO,CAACE,MAAM,CAAE,MAAO,CAAAD,cAAc,CAEtD,IAAK,KAAM,CAAAE,MAAM,GAAI,CAAAH,OAAO,CAAE,CAC5B,KAAM,CAAAI,YAAY,CAAGP,kBAAkB,CAACM,MAAM,CAACE,IAAI,CAAC,CACpD,KAAM,CAAAC,OAAO,CAAGH,MAAM,CAACG,OAAO,EAAI,EAAE,CAEpCL,cAAc,CAACM,IAAI,CAAC,CAClBC,IAAI,CAAEL,MAAM,CAACK,IAAI,CACjBC,SAAS,CAAEd,oBAAoB,CAACQ,MAAM,CAACK,IAAI,CAAC,CAC5CF,OAAO,CACPI,aAAa,CAAEJ,OAAO,CAACK,GAAG,CAAChB,oBAAoB,CAAC,CAChDiB,WAAW,CAAET,MAAM,CAACS,WAAW,EAAI,EAAE,CACrCC,WAAW,CAAEV,MAAM,CAACU,WAAW,EAAIf,iBAAiB,CAACK,MAAM,CAACE,IAAI,CAAC,EAAI,EAAE,CACvES,QAAQ,CAAElB,gBAAgB,CAACO,MAAM,CAACE,IAAI,CAAC,CACvCU,OAAO,CAAEZ,MAAM,CAACY,OAAO,EAAI,EAAE,CAC7BX,YAAY,CACZY,oBAAoB,CAAEC,IAAI,CAACC,SAAS,CAACd,YAAY,CAAC,CAClDC,IAAI,CAAEF,MAAM,CAACE,IACf,CAAC,CAAC,CACJ,CAEA,MAAO,CAAAJ,cAAc,CACvB","ignoreList":[]}
@@ -1 +1 @@
1
- import*as help from"../help-message/print-help-message.js";import{decoupleFlags,getOrdinalPlacement,isBooleanSchema,isFlagArg,isOptionArg,noName,stringToBoolean,transformArg,transformOptionToArg}from"../utils.js";export function parse(argsv,...params){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=(cmd=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;}
1
+ import*as z from"zod/v4/core";import*as help from"../help-message/print-help-message.js";import{decoupleFlags,getOrdinalPlacement,isFlagArg,isOptionArg,negateOption,stringToBoolean,transformArg,transformOptionToArg}from"../utils.js";import{isBooleanSchema,isOptionalSchema,safeParseSchema,schemaDefaultValue}from"../zodUtils.js";export function parse(argsv,...params){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=(cmd=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&&negateOption(o.name)===optionName)return true;if(!o.aliases)return false;if(o.aliases.includes(optionName))return true;if(isNegative&&o.aliases.map(negateOption).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=safeParseSchema(option.type,optionValue);if(!res.success){throw new Error(`Invalid value "${optionValue}" for "${argument}": ${z.prettifyError(res.error)}`);}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=safeParseSchema(argType,argValue);if(!res.success){throw new Error(`The ${getOrdinalPlacement(currentArgCount)} argument "${arg}" is invalid: ${z.prettifyError(res.error)}`);}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(isOptionalSchema(option.type)){const optionDefaultValue=schemaDefaultValue(option.type);if(optionDefaultValue===undefined)continue;results[option.name]=optionDefaultValue;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 argumentDefaultValue=schemaDefaultValue(argumentType);if(argumentDefaultValue!==undefined&&results.arguments){results.arguments.push(argumentDefaultValue);continue;}if(isOptionalSchema(argumentType))continue;throw new Error(`the ${getOrdinalPlacement(i)} argument is required: "${subcommandProps.arguments[i].name}"`);}}}if(subcommandProps?.action){subcommandProps.action(results);}return results;}
@@ -1 +1 @@
1
- {"version":3,"names":["help","decoupleFlags","getOrdinalPlacement","isBooleanSchema","isFlagArg","isOptionArg","noName","stringToBoolean","transformArg","transformOptionToArg","parse","argsv","params","cliOptions","subcommandArr","allSubcommands","Set","flatMap","c","name","aliases","results","subcommand","undefined","printCliHelp","opt","printSubcommandHelp","subcommandStr","find","length","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","arguments","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"],"sourceRoot":"../../../src/parser","sources":["parse.ts"],"sourcesContent":["import * as help from \"../help-message/print-help-message.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 { Cli, NoSubcommand, Option, PrintHelpOpt, Subcommand, UnSafeParseResult } from \"../types.js\";\n\nexport function parse<T extends Subcommand[], U extends Cli>(\n argsv: string[],\n ...params: [U, ...T]\n): UnSafeParseResult<[...T, NoSubcommand & U]> {\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"],"mappings":"AAAA,MAAO,GAAK,CAAAA,IAAI,KAAM,uCAAuC,CAC7D,OACEC,aAAa,CACbC,mBAAmB,CACnBC,eAAe,CACfC,SAAS,CACTC,WAAW,CACXC,MAAM,CACNC,eAAe,CACfC,YAAY,CACZC,oBAAoB,KACf,aAAa,CAIpB,MAAO,SAAS,CAAAC,KAAKA,CACnBC,KAAe,CACf,GAAGC,MAAiB,CACyB,CAC7C,KAAM,CAAAC,UAAU,CAAI,SAAS,EAAI,CAAAD,MAAM,CAAC,CAAC,CAAC,CAAGA,MAAM,CAAC,CAAC,CAAC,CAAG,CAAC,CAAO,CACjE,KAAM,CAAAE,aAAa,CAAGF,MAAsB,CAC5C,KAAM,CAAAG,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,CAGlGT,KAAK,CAAGV,aAAa,CAACU,KAAK,CAAC,CAW5B,KAAM,CAAAU,OAAkB,CAAG,CACzBC,UAAU,CAAEC,SAAS,CACrBC,YAAYA,CAACC,GAAG,CAAE,CAChBzB,IAAI,CAACwB,YAAY,CAACZ,MAAM,CAAEa,GAAG,CAAC,CAChC,CAAC,CACDC,mBAAmBA,CAACC,aAAa,CAAEF,GAAG,CAAE,CACtC,KAA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M,CAAE,CACtC,KAAM,CAAAsD,eAAe,CAAG9D,OAAO,CAACkC,SAAS,EAAE1B,MAAM,EAAI,CAAC,CACtD,KAAM,CAAA6D,kBAAkB,CAAGtC,eAAe,CAACG,SAAS,CAAC1B,MAAM,CAG3D,GAAIsD,eAAe,CAAGO,kBAAkB,CAAE,CACxC,IAAK,GAAI,CAAAzC,CAAC,CAAGkC,eAAe,CAAElC,CAAC,CAAGyC,kBAAkB,CAAEzC,CAAC,EAAE,CAAE,CACzD,KAAM,CAAA0C,YAAY,CAAGvC,eAAe,CAACG,SAAS,CAACN,CAAC,CAAC,CAACuB,IAAI,CACtD,KAAM,CAAAe,UAAU,CAAG,MAAO,CAAAI,YAAY,CAACH,IAAI,CAACC,YAAY,GAAK,UAAU,CACvE,GAAIF,UAAU,EAAIlE,OAAO,CAACkC,SAAS,CAAE,CACnClC,OAAO,CAACkC,SAAS,CAAC8B,IAAI,CAACM,YAAY,CAACH,IAAI,CAACC,YAAY,CAAC,CAAC,CAAC,CACxD,SACF,CAEA,GAAIE,YAAY,CAACL,UAAU,CAAC,CAAC,CAAE,SAE/B,KAAM,IAAI,CAAAvB,KAAK,CAAC,OAAO7D,mBAAmB,CAAC+C,CAAC,CAAC,2BAA2BG,eAAe,CAACG,SAAS,CAACN,CAAC,CAAC,CAAC9B,IAAI,GAAG,CAAC,CAC/G,CACF,CACF,CAEA,GAAIiC,eAAe,EAAEwC,MAAM,CAAE,CAC3BxC,eAAe,CAACwC,MAAM,CAACvE,OAAO,CAAC,CACjC,CAEA,MAAO,CAAAA,OAAO,CAChB","ignoreList":[]}
1
+ {"version":3,"names":["z","help","decoupleFlags","getOrdinalPlacement","isFlagArg","isOptionArg","negateOption","stringToBoolean","transformArg","transformOptionToArg","isBooleanSchema","isOptionalSchema","safeParseSchema","schemaDefaultValue","parse","argsv","params","cliOptions","subcommandArr","allSubcommands","Set","flatMap","c","name","aliases","results","subcommand","undefined","printCliHelp","opt","printSubcommandHelp","subcommandStr","find","length","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","arguments","argAndValue","split","filter","Boolean","argWithEquals","argument","argValue","Error","options","msg","isNegative","startsWith","option","o","map","isTypeBoolean","type","nextArg","optionValue","parsedBoolean","res","success","prettifyError","data","rawVal","currentArgCount","argType","push","optionDefaultValue","subcommandArgCount","argumentType","argumentDefaultValue","action"],"sourceRoot":"../../../src/parser","sources":["parse.ts"],"sourcesContent":["import * as z from \"zod/v4/core\";\n\nimport * as help from \"../help-message/print-help-message.js\";\nimport {\n decoupleFlags,\n getOrdinalPlacement,\n isFlagArg,\n isOptionArg,\n negateOption,\n stringToBoolean,\n transformArg,\n transformOptionToArg,\n} from \"../utils.js\";\nimport { isBooleanSchema, isOptionalSchema, safeParseSchema, schemaDefaultValue } from \"../zodUtils.js\";\n\nimport type { Cli, NoSubcommand, Option, PrintHelpOpt, Subcommand, UnSafeParseResult } from \"../types.js\";\n\nexport function parse<T extends Subcommand[], U extends Cli>(\n argsv: string[],\n ...params: [U, ...T]\n): UnSafeParseResult<[...T, NoSubcommand & U]> {\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 && negateOption(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(negateOption).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 = safeParseSchema(option.type, optionValue);\n if (!res.success) {\n throw new Error(`Invalid value \"${optionValue}\" for \"${argument}\": ${z.prettifyError(res.error)}`);\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 = safeParseSchema(argType, argValue);\n if (!res.success) {\n throw new Error(\n `The ${getOrdinalPlacement(currentArgCount)} argument \"${arg}\" is invalid: ${z.prettifyError(res.error)}`,\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 (isOptionalSchema(option.type)) {\n const optionDefaultValue = schemaDefaultValue(option.type);\n if (optionDefaultValue === undefined) continue;\n results[option.name] = optionDefaultValue;\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 argumentDefaultValue = schemaDefaultValue(argumentType);\n if (argumentDefaultValue !== undefined && results.arguments) {\n results.arguments.push(argumentDefaultValue);\n continue;\n }\n\n if (isOptionalSchema(argumentType)) 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"],"mappings":"AAAA,MAAO,GAAK,CAAAA,CAAC,KAAM,aAAa,CAEhC,MAAO,GAAK,CAAAC,IAAI,KAAM,uCAAuC,CAC7D,OACEC,aAAa,CACbC,mBAAmB,CACnBC,SAAS,CACTC,WAAW,CACXC,YAAY,CACZC,eAAe,CACfC,YAAY,CACZC,oBAAoB,KACf,aAAa,CACpB,OAASC,eAAe,CAAEC,gBAAgB,CAAEC,eAAe,CAAEC,kBAAkB,KAAQ,gBAAgB,CAIvG,MAAO,SAAS,CAAAC,KAAKA,CACnBC,KAAe,CACf,GAAGC,MAAiB,CACyB,CAC7C,KAAM,CAAAC,UAAU,CAAI,SAAS,EAAI,CAAAD,MAAM,CAAC,CAAC,CAAC,CAAGA,MAAM,CAAC,CAAC,CAAC,CAAG,CAAC,CAAO,CACjE,KAAM,CAAAE,aAAa,CAAGF,MAAsB,CAC5C,KAAM,CAAAG,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,CAGlGT,KAAK,CAAGb,aAAa,CAACa,KAAK,CAAC,CAW5B,KAAM,CAAAU,OAAkB,CAAG,CACzBC,UAAU,CAAEC,SAAS,CACrBC,YAAYA,CAACC,GAAG,CAAE,CAChB5B,IAAI,CAAC2B,YAAY,CAACZ,MAAM,CAAEa,GAAG,CAAC,CAChC,CAAC,CACDC,mBAAmBA,CAACC,aAAa,CAAEF,GAAG,CAAE,CACtC,KAAM,CAAAH,UAAU,CAAGR,aAAa,CAACc,IAAI,CAACV,CAAC,EAAI,CACzC,GAAIA,CAAC,CAACC,IAAI,GAAKQ,aAAa,CAAE,MAAO,KAAI,CACzC,GAAI,C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AAK,GAAI,CAAApC,CAAC,CAAGgC,eAAe,CAAEhC,CAAC,CAAGoC,kBAAkB,CAAEpC,CAAC,EAAE,CAAE,CACzD,KAAM,CAAAqC,YAAY,CAAGlC,eAAe,CAACG,SAAS,CAACN,CAAC,CAAC,CAACuB,IAAI,CACtD,KAAM,CAAAe,oBAAoB,CAAG9E,kBAAkB,CAAC6E,YAAY,CAAC,CAC7D,GAAIC,oBAAoB,GAAKhE,SAAS,EAAIF,OAAO,CAACkC,SAAS,CAAE,CAC3DlC,OAAO,CAACkC,SAAS,CAAC4B,IAAI,CAACI,oBAAoB,CAAC,CAC5C,SACF,CAEA,GAAIhF,gBAAgB,CAAC+E,YAAY,CAAC,CAAE,SAEpC,KAAM,IAAI,CAAAvB,KAAK,CAAC,OAAOhE,mBAAmB,CAACkD,CAAC,CAAC,2BAA2BG,eAAe,CAACG,SAAS,CAACN,CAAC,CAAC,CAAC9B,IAAI,GAAG,CAAC,CAC/G,CACF,CACF,CAEA,GAAIiC,eAAe,EAAEoC,MAAM,CAAE,CAC3BpC,eAAe,CAACoC,MAAM,CAACnE,OAAO,CAAC,CACjC,CAEA,MAAO,CAAAA,OAAO,CAChB","ignoreList":[]}
@@ -1 +1 @@
1
- import assert from"node:assert";import{z}from"zod";export function transformArg(name){assert(name.startsWith("-"),`[transformArg] Invalid arg name: ${name}`);name=name.startsWith("--")?name.substring(2):name.substring(1);return name.replace(/-([a-z])/g,g=>g[1].toUpperCase());}export function transformOptionToArg(name){name=name.replace(/^[A-Z]/g,g=>g.toLowerCase());if(name.length===1)return`-${name}`;return`--${name.replace(/[A-Z]/g,g=>"-"+g.toLowerCase())}`;}export function isFlagArg(name){return /^-[A-Z-a-z]$/.test(name);}export function isLongArg(name){return /^--[A-Z-a-z-]+[A-Z-a-z]$/.test(name);}export function isOptionArg(name){if(typeof name!=="string")return false;return isFlagArg(name)||isLongArg(name);}export function noName(name){if(name.length===1)return name;return"no"+name.replace(/^[a-z]/,g=>g.toUpperCase());}export function stringToBoolean(str){if(str.toLowerCase()==="true")return true;if(str.toLowerCase()==="false")return false;throw new Error(`[stringToBoolean] Invalid boolean value: "${str}"; Expected "true" or "false"`);}export function getOrdinalPlacement(index){if(index<0)return"";const suffixes=["th","st","nd","rd"];const lastDigit=index%10;const lastTwoDigits=index%100;const suffix=lastDigit===1&&lastTwoDigits!==11?suffixes[1]:lastDigit===2&&lastTwoDigits!==12?suffixes[2]:lastDigit===3&&lastTwoDigits!==13?suffixes[3]:suffixes[0];return`${index+1}${suffix}`;}export function isBooleanSchema(schema){let type=schema;while(type){if(type instanceof z.ZodBoolean){return true;}if(type instanceof z.ZodLiteral){return type.value===true||type.value===false;}type=type._def.innerType;}return false;}export function getDefaultValueFromSchema(schema){let type=schema;while(type){if(type instanceof z.ZodDefault){const defaultValue=type._def.defaultValue();return defaultValue;}type=type._def.innerType;}return undefined;}export function decoupleFlags(args){const flagsRe=/^-[a-z]{2,}$/i;const result=[];for(let i=0;i<args.length;i++){const arg=args[i];const isCoupled=flagsRe.test(arg);if(!isCoupled){result.push(arg);continue;}const decoupledArr=arg.substring(1).split("").map(c=>"-"+c);result.push(...decoupledArr);}return result;}
1
+ import assert from"node:assert";export function transformArg(name){assert(name.startsWith("-"),`[transformArg] Invalid arg name: ${name}`);name=name.startsWith("--")?name.substring(2):name.substring(1);return name.replace(/-([a-z])/g,g=>g[1].toUpperCase());}export function transformOptionToArg(name){name=name.replace(/^[A-Z]/g,g=>g.toLowerCase());if(name.length===1)return`-${name}`;return`--${name.replace(/[A-Z]/g,g=>"-"+g.toLowerCase())}`;}export function isFlagArg(name){return /^-[A-Z-a-z]$/.test(name);}export function isLongArg(name){return /^--[A-Z-a-z-]+[A-Z-a-z]$/.test(name);}export function isOptionArg(name){if(typeof name!=="string")return false;return isFlagArg(name)||isLongArg(name);}export function negateOption(name){if(name.length===1)return name;return"no"+name.replace(/^[a-z]/,g=>g.toUpperCase());}export function stringToBoolean(str){if(str.toLowerCase()==="true")return true;if(str.toLowerCase()==="false")return false;throw new Error(`[stringToBoolean] Invalid boolean value: "${str}"; Expected "true" or "false"`);}export function getOrdinalPlacement(index){if(index<0)return"";const suffixes=["th","st","nd","rd"];const lastDigit=index%10;const lastTwoDigits=index%100;const suffix=lastDigit===1&&lastTwoDigits!==11?suffixes[1]:lastDigit===2&&lastTwoDigits!==12?suffixes[2]:lastDigit===3&&lastTwoDigits!==13?suffixes[3]:suffixes[0];return`${index+1}${suffix}`;}export function decoupleFlags(args){const flagsRe=/^-[a-z]{2,}$/i;const result=[];for(let i=0;i<args.length;i++){const arg=args[i];const isCoupled=flagsRe.test(arg);if(!isCoupled){result.push(arg);continue;}const decoupledArr=arg.substring(1).split("").map(c=>"-"+c);result.push(...decoupledArr);}return result;}
@@ -1 +1 @@
1
- {"version":3,"names":["assert","z","transformArg","name","startsWith","substring","replace","g","toUpperCase","transformOptionToArg","toLowerCase","length","isFlagArg","test","isLongArg","isOptionArg","noName","stringToBoolean","str","Error","getOrdinalPlacement","index","suffixes","lastDigit","lastTwoDigits","suffix","isBooleanSchema","schema","type","ZodBoolean","ZodLiteral","value","_def","innerType","getDefaultValueFromSchema","ZodDefault","defaultValue","undefined","decoupleFlags","args","flagsRe","result","i","arg","isCoupled","push","decoupledArr","split","map","c"],"sourceRoot":"../../src","sources":["utils.ts"],"sourcesContent":["import assert from \"node:assert\";\nimport { z } from \"zod\";\n\n/**\n * @param name - Should start with `'--'`\n * @returns - The transformed name E.g. `--input-dir` -> `InputDir`\n */\nexport function transformArg(name: string): string {\n assert(name.startsWith(\"-\"), `[transformArg] Invalid arg name: ${name}`);\n name = name.startsWith(\"--\") ? name.substring(2) : name.substring(1);\n return name.replace(/-([a-z])/g, g => g[1].toUpperCase());\n}\n\n/** - Reverse of `transformArg`. E.g. `InputDir` -> `--input-dir` , `i` -> `-i` */\nexport function transformOptionToArg(name: string): string {\n name = name.replace(/^[A-Z]/g, g => g.toLowerCase()); // first letter always lower case\n if (name.length === 1) return `-${name}`;\n return `--${name.replace(/[A-Z]/g, g => \"-\" + g.toLowerCase())}`;\n}\n\n/** - Check if an arg string is a short arg. E.g. `-i` -> `true` */\nexport function isFlagArg(name: string): boolean {\n return /^-[A-Z-a-z]$/.test(name);\n}\n\n/** - Check if an arg string is a long arg. E.g. `--input-dir` -> `true` */\nexport function isLongArg(name: string): boolean {\n return /^--[A-Z-a-z-]+[A-Z-a-z]$/.test(name);\n}\n\n/** - Check if an arg string is an options arg. E.g. `--input-dir` -> `true` , `-i` -> `true` */\nexport function isOptionArg(name: string | boolean): boolean {\n if (typeof name !== \"string\") return false;\n return isFlagArg(name) || isLongArg(name);\n}\n\n/**\n * - Transform option name to no name. E.g. `include` -> `noInclude`\n * - For short name like `-i` it will be ignored\n */\nexport function noName(name: string): string {\n if (name.length === 1) return name;\n return \"no\" + name.replace(/^[a-z]/, g => g.toUpperCase());\n}\n\n/** - Convert string to boolean. E.g. `\"true\"` -> `true` , `\"false\"` -> `false` */\nexport function stringToBoolean(str: string): boolean {\n if (str.toLowerCase() === \"true\") return true;\n if (str.toLowerCase() === \"false\") return false;\n throw new Error(`[stringToBoolean] Invalid boolean value: \"${str}\"; Expected \"true\" or \"false\"`);\n}\n\nexport function getOrdinalPlacement(index: number): string {\n if (index < 0) return \"\";\n\n const suffixes = [\"th\", \"st\", \"nd\", \"rd\"];\n const lastDigit = index % 10;\n const lastTwoDigits = index % 100;\n\n const suffix =\n lastDigit === 1 && lastTwoDigits !== 11\n ? suffixes[1]\n : lastDigit === 2 && lastTwoDigits !== 12\n ? suffixes[2]\n : lastDigit === 3 && lastTwoDigits !== 13\n ? suffixes[3]\n : suffixes[0];\n\n return `${index + 1}${suffix}`;\n}\n\n/** - Check if a schema is a boolean */\nexport function isBooleanSchema(schema: z.ZodTypeAny): boolean {\n let type = schema;\n while (type) {\n if (type instanceof z.ZodBoolean) {\n return true;\n }\n\n if (type instanceof z.ZodLiteral) {\n return type.value === true || type.value === false;\n }\n\n type = type._def.innerType;\n }\n\n return false;\n}\n\nexport function getDefaultValueFromSchema(schema: z.ZodTypeAny): unknown | undefined {\n let type = schema;\n while (type) {\n if (type instanceof z.ZodDefault) {\n const defaultValue = type._def.defaultValue();\n return defaultValue;\n }\n\n type = type._def.innerType;\n }\n\n return undefined;\n}\n\n/** - Decouple flags E.g. `-rf` -> `-r, -f` */\nexport function decoupleFlags(args: string[]): string[] {\n const flagsRe = /^-[a-z]{2,}$/i;\n\n const result = [];\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n const isCoupled = flagsRe.test(arg);\n\n if (!isCoupled) {\n result.push(arg);\n continue;\n }\n\n const decoupledArr = arg\n .substring(1)\n .split(\"\")\n .map(c => \"-\" + c);\n\n result.push(...decoupledArr);\n }\n\n return result;\n}\n"],"mappings":"AAAA,MAAO,CAAAA,MAAM,KAAM,aAAa,CAChC,OAASC,CAAC,KAAQ,KAAK,CAMvB,MAAO,SAAS,CAAAC,YAAYA,CAACC,IAAY,CAAU,CACjDH,MAAM,CAACG,IAAI,CAACC,UAAU,CAAC,GAAG,CAAC,CAAE,oCAAoCD,IAAI,EAAE,CAAC,CACxEA,IAAI,CAAGA,IAAI,CAACC,UAAU,CAAC,IAAI,CAAC,CAAGD,IAAI,CAACE,SAAS,CAAC,CAAC,CAAC,CAAGF,IAAI,CAACE,SAAS,CAAC,CAAC,CAAC,CACpE,MAAO,CAAAF,IAAI,CAACG,OAAO,CAAC,WAAW,CAAEC,CAAC,EAAIA,CAAC,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC,CAAC,CAC3D,CAGA,MAAO,SAAS,CAAAC,oBAAoBA,CAACN,IAAY,CAAU,CACzDA,IAAI,CAAGA,IAAI,CAACG,OAAO,CAAC,SAAS,CAAEC,CAAC,EAAIA,CAAC,CAACG,WAAW,CAAC,CAAC,CAAC,CACpD,GAAIP,IAAI,CAACQ,MAAM,GAAK,CAAC,CAAE,MAAO,IAAIR,IAAI,EAAE,CACxC,MAAO,KAAKA,IAAI,CAACG,OAAO,CAAC,QAAQ,C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AClB,CAGA,MAAO,SAAS,CAAAC,aAAaA,CAACC,IAAc,CAAY,CACtD,KAAM,CAAAC,OAAO,CAAG,eAAe,CAE/B,KAAM,CAAAC,MAAM,CAAG,EAAE,CACjB,IAAK,GAAI,CAAAC,CAAC,CAAG,CAAC,CAAEA,CAAC,CAAGH,IAAI,CAAC5B,MAAM,CAAE+B,CAAC,EAAE,CAAE,CACpC,KAAM,CAAAC,GAAG,CAAGJ,IAAI,CAACG,CAAC,CAAC,CACnB,KAAM,CAAAE,SAAS,CAAGJ,OAAO,CAAC3B,IAAI,CAAC8B,GAAG,CAAC,CAEnC,GAAI,CAACC,SAAS,CAAE,CACdH,MAAM,CAACI,IAAI,CAACF,GAAG,CAAC,CAChB,SACF,CAEA,KAAM,CAAAG,YAAY,CAAGH,GAAG,CACrBtC,SAAS,CAAC,CAAC,CAAC,CACZ0C,KAAK,CAAC,EAAE,CAAC,CACTC,GAAG,CAACC,CAAC,EAAI,GAAG,CAAGA,CAAC,CAAC,CAEpBR,MAAM,CAACI,IAAI,CAAC,GAAGC,YAAY,CAAC,CAC9B,CAEA,MAAO,CAAAL,MAAM,CACf","ignoreList":[]}
1
+ {"version":3,"names":["assert","transformArg","name","startsWith","substring","replace","g","toUpperCase","transformOptionToArg","toLowerCase","length","isFlagArg","test","isLongArg","isOptionArg","negateOption","stringToBoolean","str","Error","getOrdinalPlacement","index","suffixes","lastDigit","lastTwoDigits","suffix","decoupleFlags","args","flagsRe","result","i","arg","isCoupled","push","decoupledArr","split","map","c"],"sourceRoot":"../../src","sources":["utils.ts"],"sourcesContent":["import assert from \"node:assert\";\n\n/**\n * @param name - Should start with `'--'`\n * @returns - The transformed name E.g. `--input-dir` -> `InputDir`\n */\nexport function transformArg(name: string): string {\n assert(name.startsWith(\"-\"), `[transformArg] Invalid arg name: ${name}`);\n name = name.startsWith(\"--\") ? name.substring(2) : name.substring(1);\n return name.replace(/-([a-z])/g, g => g[1].toUpperCase());\n}\n\n/** - Reverse of `transformArg`. E.g. `InputDir` -> `--input-dir` , `i` -> `-i` */\nexport function transformOptionToArg(name: string): string {\n name = name.replace(/^[A-Z]/g, g => g.toLowerCase()); // first letter always lower case\n if (name.length === 1) return `-${name}`;\n return `--${name.replace(/[A-Z]/g, g => \"-\" + g.toLowerCase())}`;\n}\n\n/** - Check if an arg string is a short arg. E.g. `-i` -> `true` */\nexport function isFlagArg(name: string): boolean {\n return /^-[A-Z-a-z]$/.test(name);\n}\n\n/** - Check if an arg string is a long arg. E.g. `--input-dir` -> `true` */\nexport function isLongArg(name: string): boolean {\n return /^--[A-Z-a-z-]+[A-Z-a-z]$/.test(name);\n}\n\n/** - Check if an arg string is an options arg. E.g. `--input-dir` -> `true` , `-i` -> `true` */\nexport function isOptionArg(name: string | boolean): boolean {\n if (typeof name !== \"string\") return false;\n return isFlagArg(name) || isLongArg(name);\n}\n\n/**\n * - Transform option name to no name. E.g. `include` -> `noInclude`\n * - For short name like `-i` it will be ignored\n */\nexport function negateOption(name: string): string {\n if (name.length === 1) return name;\n return \"no\" + name.replace(/^[a-z]/, g => g.toUpperCase());\n}\n\n/** - Convert string to boolean. E.g. `\"true\"` -> `true` , `\"false\"` -> `false` */\nexport function stringToBoolean(str: string): boolean {\n if (str.toLowerCase() === \"true\") return true;\n if (str.toLowerCase() === \"false\") return false;\n throw new Error(`[stringToBoolean] Invalid boolean value: \"${str}\"; Expected \"true\" or \"false\"`);\n}\n\nexport function getOrdinalPlacement(index: number): string {\n if (index < 0) return \"\";\n\n const suffixes = [\"th\", \"st\", \"nd\", \"rd\"];\n const lastDigit = index % 10;\n const lastTwoDigits = index % 100;\n\n const suffix =\n lastDigit === 1 && lastTwoDigits !== 11\n ? suffixes[1]\n : lastDigit === 2 && lastTwoDigits !== 12\n ? suffixes[2]\n : lastDigit === 3 && lastTwoDigits !== 13\n ? suffixes[3]\n : suffixes[0];\n\n return `${index + 1}${suffix}`;\n}\n\n/** - Decouple flags E.g. `-rf` -> `-r, -f` */\nexport function decoupleFlags(args: string[]): string[] {\n const flagsRe = /^-[a-z]{2,}$/i;\n\n const result = [];\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n const isCoupled = flagsRe.test(arg);\n\n if (!isCoupled) {\n result.push(arg);\n continue;\n }\n\n const decoupledArr = arg\n .substring(1)\n .split(\"\")\n .map(c => \"-\" + c);\n\n result.push(...decoupledArr);\n }\n\n return result;\n}\n"],"mappings":"AAAA,MAAO,CAAAA,MAAM,KAAM,aAAa,CAMhC,MAAO,SAAS,CAAAC,YAAYA,CAACC,IAAY,CAAU,CACjDF,MAAM,CAACE,IAAI,CAACC,UAAU,CAAC,GAAG,CAAC,CAAE,oCAAoCD,IAAI,EAAE,CAAC,CACxEA,IAAI,CAAGA,IAAI,CAACC,UAAU,CAAC,IAAI,CAAC,CAAGD,IAAI,CAACE,SAAS,CAAC,CAAC,CAAC,CAAGF,IAAI,CAACE,SAAS,CAAC,CAAC,CAAC,CACpE,MAAO,CAAAF,IAAI,CAACG,OAAO,CAAC,WAAW,CAAEC,CAAC,EAAIA,CAAC,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC,CAAC,CAC3D,CAGA,MAAO,SAAS,CAAAC,oBAAoBA,CAACN,IAAY,CAAU,CACzDA,IAAI,CAAGA,IAAI,CAACG,OAAO,CAAC,SAAS,CAAEC,CAAC,EAAIA,CAAC,CAACG,WAAW,CAAC,CAAC,CAAC,CACpD,GAAIP,IAAI,CAACQ,MAAM,GAAK,CAAC,CAAE,MAAO,IAAIR,IAAI,EAAE,CACxC,MAAO,KAAKA,IAAI,CAACG,OAAO,CAAC,QAAQ,CAAEC,CAAC,EAAI,GAAG,CAAGA,CAAC,CAACG,WAAW,CAAC,CAAC,CAAC,EAAE,CAClE,CAGA,MAAO,SAAS,CAAAE,SAASA,CAACT,IAAY,CAAW,CAC/C,MAAO,eAAc,CAACU,IAAI,CAACV,IAAI,CAAC,CAClC,CAGA,MAAO,SAAS,CAAAW,SAASA,CAACX,IAAY,CAAW,CAC/C,M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C,CAAC,CAAC,CACXC,SAAS,GAAK,CAAC,EAAIC,aAAa,GAAK,EAAE,CACrCF,QAAQ,CAAC,CAAC,CAAC,CACXA,QAAQ,CAAC,CAAC,CAAC,CAErB,MAAO,GAAGD,KAAK,CAAG,CAAC,GAAGI,MAAM,EAAE,CAChC,CAGA,MAAO,SAAS,CAAAC,aAAaA,CAACC,IAAc,CAAY,CACtD,KAAM,CAAAC,OAAO,CAAG,eAAe,CAE/B,KAAM,CAAAC,MAAM,CAAG,EAAE,CACjB,IAAK,GAAI,CAAAC,CAAC,CAAG,CAAC,CAAEA,CAAC,CAAGH,IAAI,CAAChB,MAAM,CAAEmB,CAAC,EAAE,CAAE,CACpC,KAAM,CAAAC,GAAG,CAAGJ,IAAI,CAACG,CAAC,CAAC,CACnB,KAAM,CAAAE,SAAS,CAAGJ,OAAO,CAACf,IAAI,CAACkB,GAAG,CAAC,CAEnC,GAAI,CAACC,SAAS,CAAE,CACdH,MAAM,CAACI,IAAI,CAACF,GAAG,CAAC,CAChB,SACF,CAEA,KAAM,CAAAG,YAAY,CAAGH,GAAG,CACrB1B,SAAS,CAAC,CAAC,CAAC,CACZ8B,KAAK,CAAC,EAAE,CAAC,CACTC,GAAG,CAACC,CAAC,EAAI,GAAG,CAAGA,CAAC,CAAC,CAEpBR,MAAM,CAACI,IAAI,CAAC,GAAGC,YAAY,CAAC,CAC9B,CAEA,MAAO,CAAAL,MAAM,CACf","ignoreList":[]}
@@ -0,0 +1 @@
1
+ import*as Z3 from"zod/v3";import*as Z4 from"zod/v4/core";function isV4Schema(schema){return"_zod"in schema;}export function safeParseSchema(schema,value){if(isV4Schema(schema)){return Z4.safeParse(schema,value);}return schema.safeParse(value);}export function isBooleanSchema(schema){if(isV4Schema(schema)){return isBooleanV4Schema(schema);}return isBooleanV3Schema(schema);}function isBooleanV4Schema(schema){let def=schema._zod.def;while(def){if(def.type==="boolean"){return true;}if(isLiteralV4Def(def)){return def.values.includes(true)||def.values.includes(false);}if(!isV4DefWithInnerType(def)){return false;}def=def.innerType._zod.def;}return false;}function isBooleanV3Schema(schema){let type=schema;while(type){if(type instanceof Z3.ZodBoolean){return true;}if(type instanceof Z3.ZodLiteral){return type.value===true||type.value===false;}type=type._def.innerType;}return false;}export function schemaDefaultValue(schema){if(isV4Schema(schema)){return schemaV4DefaultValue(schema);}return schemaV3DefaultValue(schema);}function schemaV4DefaultValue(schema){let def=schema._zod.def;while(def){if(isDefaultV4Def(def))return def.defaultValue;if(!isV4DefWithInnerType(def))return undefined;def=def.innerType._zod.def;}return undefined;}function schemaV3DefaultValue(schema){let type=schema;while(type){if(type instanceof Z3.ZodDefault){const defaultValue=type._def.defaultValue();return defaultValue;}type=type._def.innerType;}return undefined;}export function schemaDescription(schema){if(isV4Schema(schema)){if(!("meta"in schema)||typeof schema.meta!=="function")return;return schema.meta()?.description;}return schema.description;}export function isOptionalSchema(schema){if(isV4Schema(schema)){return schema._zod.def.type==="optional"||schema._zod.def.type==="default";}return schema.isOptional();}function isDefaultV4Def(def){return def.type==="default";}function isLiteralV4Def(def){return def.type==="literal";}function isV4DefWithInnerType(def){return new Set(["default","prefault","optional","nonoptional","nullable","success","catch","readonly","promise"]).has(def.type);}
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Z3","Z4","isV4Schema","schema","safeParseSchema","value","safeParse","isBooleanSchema","isBooleanV4Schema","isBooleanV3Schema","def","_zod","type","isLiteralV4Def","values","includes","isV4DefWithInnerType","innerType","ZodBoolean","ZodLiteral","_def","schemaDefaultValue","schemaV4DefaultValue","schemaV3DefaultValue","isDefaultV4Def","defaultValue","undefined","ZodDefault","schemaDescription","meta","description","isOptionalSchema","isOptional","Set","has"],"sourceRoot":"../../src","sources":["zodUtils.ts"],"sourcesContent":["import * as Z3 from \"zod/v3\";\nimport * as Z4 from \"zod/v4/core\";\n\nimport type { Schema, SchemaV3, SchemaV4 } from \"./types.js\";\n\nfunction isV4Schema(schema: Schema): schema is SchemaV4 {\n return \"_zod\" in schema;\n}\n\n/** - Safe parse a value against a schema */\nexport function safeParseSchema(schema: Schema, value: unknown) {\n if (isV4Schema(schema)) {\n return Z4.safeParse(schema, value);\n }\n\n return schema.safeParse(value);\n}\n\n/** - Check if a schema is a boolean */\nexport function isBooleanSchema(schema: Schema): boolean {\n if (isV4Schema(schema)) {\n return isBooleanV4Schema(schema);\n }\n\n return isBooleanV3Schema(schema);\n}\n\nfunction isBooleanV4Schema(schema: SchemaV4): boolean {\n let def = schema._zod.def;\n\n while (def) {\n if (def.type === \"boolean\") {\n return true;\n }\n\n if (isLiteralV4Def(def)) {\n return def.values.includes(true) || def.values.includes(false);\n }\n\n if (!isV4DefWithInnerType(def)) {\n return false;\n }\n\n def = def.innerType._zod.def;\n }\n\n return false;\n}\n\nfunction isBooleanV3Schema(schema: SchemaV3): boolean {\n let type = schema;\n while (type) {\n if (type instanceof Z3.ZodBoolean) {\n return true;\n }\n\n if (type instanceof Z3.ZodLiteral) {\n return type.value === true || type.value === false;\n }\n\n type = type._def.innerType;\n }\n\n return false;\n}\n\n/** - Get the default value of a schema */\nexport function schemaDefaultValue(schema: Schema): unknown | undefined {\n if (isV4Schema(schema)) {\n return schemaV4DefaultValue(schema);\n }\n\n return schemaV3DefaultValue(schema);\n}\n\nfunction schemaV4DefaultValue(schema: SchemaV4): unknown | undefined {\n let def = schema._zod.def;\n\n while (def) {\n if (isDefaultV4Def(def)) return def.defaultValue;\n if (!isV4DefWithInnerType(def)) return undefined;\n def = def.innerType._zod.def;\n }\n\n return undefined;\n}\n\nfunction schemaV3DefaultValue(schema: SchemaV3): unknown | undefined {\n let type = schema;\n while (type) {\n if (type instanceof Z3.ZodDefault) {\n const defaultValue = type._def.defaultValue();\n return defaultValue;\n }\n\n type = type._def.innerType;\n }\n\n return undefined;\n}\n\n/** - Get the description of a schema */\nexport function schemaDescription(schema: Schema): string | undefined {\n if (isV4Schema(schema)) {\n if (!(\"meta\" in schema) || typeof schema.meta !== \"function\") return;\n return schema.meta()?.description;\n }\n\n return schema.description;\n}\n/** - Check if a schema is optional */\nexport function isOptionalSchema(schema: Schema): schema is Z4.$ZodOptional {\n if (isV4Schema(schema)) {\n return schema._zod.def.type === \"optional\" || schema._zod.def.type === \"default\";\n }\n\n return schema.isOptional();\n}\n\nfunction isDefaultV4Def(def: Z4.$ZodTypeDef): def is Z4.$ZodDefaultDef {\n return def.type === \"default\";\n}\n\nfunction isLiteralV4Def(def: Z4.$ZodTypeDef): def is Z4.$ZodLiteralDef<any> {\n return def.type === \"literal\";\n}\n\ntype SchemaWithInnerType =\n | Z4.$ZodDefaultDef\n | Z4.$ZodPrefaultDef\n | Z4.$ZodOptionalDef\n | Z4.$ZodNonOptionalDef\n | Z4.$ZodNullableDef\n | Z4.$ZodSuccessDef\n | Z4.$ZodCatchDef\n | Z4.$ZodReadonlyDef\n | Z4.$ZodPromiseDef;\n\nfunction isV4DefWithInnerType(def: Z4.$ZodTypeDef): def is SchemaWithInnerType {\n return new Set([\n \"default\",\n \"prefault\",\n \"optional\",\n \"nonoptional\",\n \"nullable\",\n \"success\",\n \"catch\",\n \"readonly\",\n \"promise\",\n ]).has(def.type);\n}\n"],"mappings":"AAAA,MAAO,GAAK,CAAAA,EAAE,KAAM,QAAQ,CAC5B,MAAO,GAAK,CAAAC,EAAE,KAAM,aAAa,CAIjC,QAAS,CAAAC,UAAUA,CAACC,MAAc,CAAsB,CACtD,MAAO,MAAM,EAAI,CAAAA,MAAM,CACzB,CAGA,MAAO,SAAS,CAAAC,eAAeA,CAACD,MAAc,CAAEE,KAAc,CAAE,CAC9D,GAAIH,UAAU,CAACC,MAAM,CAAC,CAAE,CACtB,MAAO,CAAAF,EAAE,CAACK,SAAS,CAACH,MAAM,CAAEE,KAAK,CAAC,CACpC,CAEA,MAAO,CAAAF,MAAM,CAACG,SAAS,CAACD,KAAK,CAAC,CAChC,CAGA,MAAO,SAAS,CAAAE,eAAeA,CAACJ,MAAc,CAAW,CACvD,GAAID,UAAU,CAACC,MAAM,CAAC,CAAE,CACtB,MA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E,CACtB,MAAO,CAAAA,MAAM,CAACQ,IAAI,CAACD,GAAG,CAACE,IAAI,GAAK,UAAU,EAAIT,MAAM,CAACQ,IAAI,CAACD,GAAG,CAACE,IAAI,GAAK,SAAS,CAClF,CAEA,MAAO,CAAAT,MAAM,CAAC6B,UAAU,CAAC,CAAC,CAC5B,CAEA,QAAS,CAAAR,cAAcA,CAACd,GAAmB,CAA4B,CACrE,MAAO,CAAAA,GAAG,CAACE,IAAI,GAAK,SAAS,CAC/B,CAEA,QAAS,CAAAC,cAAcA,CAACH,GAAmB,CAAiC,CAC1E,MAAO,CAAAA,GAAG,CAACE,IAAI,GAAK,SAAS,CAC/B,CAaA,QAAS,CAAAI,oBAAoBA,CAACN,GAAmB,CAA8B,CAC7E,MAAO,IAAI,CAAAuB,GAAG,CAAC,CACb,SAAS,CACT,UAAU,CACV,UAAU,CACV,aAAa,CACb,UAAU,CACV,SAAS,CACT,OAAO,CACP,UAAU,CACV,SAAS,CACV,CAAC,CAACC,GAAG,CAACxB,GAAG,CAACE,IAAI,CAAC,CAClB","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"get-options-metadata.d.ts","sourceRoot":"","sources":["../../../src/metadata/get-options-metadata.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE1D,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,CAyBtE"}
1
+ {"version":3,"file":"get-options-metadata.d.ts","sourceRoot":"","sources":["../../../src/metadata/get-options-metadata.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE1D,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,CAyBtE"}
@@ -1 +1 @@
1
- {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../src/parser/parse.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,GAAG,EAAE,YAAY,EAAwB,UAAU,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE1G,wBAAgB,KAAK,CAAC,CAAC,SAAS,UAAU,EAAE,EAAE,CAAC,SAAS,GAAG,EACzD,KAAK,EAAE,MAAM,EAAE,EACf,GAAG,MAAM,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,GACnB,iBAAiB,CAAC,CAAC,GAAG,CAAC,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC,CA2P7C"}
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../src/parser/parse.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,GAAG,EAAE,YAAY,EAAwB,UAAU,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE1G,wBAAgB,KAAK,CAAC,CAAC,SAAS,UAAU,EAAE,EAAE,CAAC,SAAS,GAAG,EACzD,KAAK,EAAE,MAAM,EAAE,EACf,GAAG,MAAM,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,GACnB,iBAAiB,CAAC,CAAC,GAAG,CAAC,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC,CA2P7C"}