@shell-shock/core 0.11.0 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/dist/components/docs.d.mts +5 -5
  2. package/dist/components/helpers.cjs +9 -0
  3. package/dist/components/helpers.cjs.map +1 -1
  4. package/dist/components/helpers.d.cts +15 -7
  5. package/dist/components/helpers.d.cts.map +1 -1
  6. package/dist/components/helpers.d.mts +15 -7
  7. package/dist/components/helpers.d.mts.map +1 -1
  8. package/dist/components/helpers.mjs +9 -1
  9. package/dist/components/helpers.mjs.map +1 -1
  10. package/dist/components/index.cjs +1 -0
  11. package/dist/components/index.d.cts +2 -2
  12. package/dist/components/index.d.mts +2 -2
  13. package/dist/components/index.mjs +2 -2
  14. package/dist/components/options-parser-logic.cjs +142 -62
  15. package/dist/components/options-parser-logic.cjs.map +1 -1
  16. package/dist/components/options-parser-logic.d.cts +17 -17
  17. package/dist/components/options-parser-logic.d.cts.map +1 -1
  18. package/dist/components/options-parser-logic.d.mts +17 -17
  19. package/dist/components/options-parser-logic.d.mts.map +1 -1
  20. package/dist/components/options-parser-logic.mjs +143 -63
  21. package/dist/components/options-parser-logic.mjs.map +1 -1
  22. package/dist/components/usage.d.cts +2 -2
  23. package/dist/components/usage.d.mts +2 -2
  24. package/dist/components/usage.d.mts.map +1 -1
  25. package/dist/components/utils-builtin.cjs +5 -9
  26. package/dist/components/utils-builtin.cjs.map +1 -1
  27. package/dist/components/utils-builtin.d.cts.map +1 -1
  28. package/dist/components/utils-builtin.d.mts.map +1 -1
  29. package/dist/components/utils-builtin.mjs +5 -9
  30. package/dist/components/utils-builtin.mjs.map +1 -1
  31. package/dist/helpers/automd.cjs +1 -1
  32. package/dist/helpers/automd.cjs.map +1 -1
  33. package/dist/helpers/automd.mjs +1 -1
  34. package/dist/helpers/automd.mjs.map +1 -1
  35. package/dist/plugin-utils/description-helpers.cjs +105 -0
  36. package/dist/plugin-utils/description-helpers.cjs.map +1 -0
  37. package/dist/plugin-utils/description-helpers.d.cts +44 -0
  38. package/dist/plugin-utils/description-helpers.d.cts.map +1 -0
  39. package/dist/plugin-utils/description-helpers.d.mts +44 -0
  40. package/dist/plugin-utils/description-helpers.d.mts.map +1 -0
  41. package/dist/plugin-utils/description-helpers.mjs +101 -0
  42. package/dist/plugin-utils/description-helpers.mjs.map +1 -0
  43. package/dist/plugin-utils/get-command-tree.cjs +26 -0
  44. package/dist/plugin-utils/get-command-tree.cjs.map +1 -1
  45. package/dist/plugin-utils/get-command-tree.d.cts +8 -1
  46. package/dist/plugin-utils/get-command-tree.d.cts.map +1 -1
  47. package/dist/plugin-utils/get-command-tree.d.mts +8 -1
  48. package/dist/plugin-utils/get-command-tree.d.mts.map +1 -1
  49. package/dist/plugin-utils/get-command-tree.mjs +26 -1
  50. package/dist/plugin-utils/get-command-tree.mjs.map +1 -1
  51. package/dist/plugin-utils/index.cjs +7 -1
  52. package/dist/plugin-utils/index.d.cts +3 -2
  53. package/dist/plugin-utils/index.d.mts +3 -2
  54. package/dist/plugin-utils/index.mjs +3 -2
  55. package/dist/plugin-utils/type-checks.d.cts.map +1 -1
  56. package/dist/plugin.cjs +5 -7
  57. package/dist/plugin.cjs.map +1 -1
  58. package/dist/plugin.d.cts.map +1 -1
  59. package/dist/plugin.d.mts.map +1 -1
  60. package/dist/plugin.mjs +5 -7
  61. package/dist/plugin.mjs.map +1 -1
  62. package/dist/resolver/deepkit.cjs +6 -3
  63. package/dist/resolver/deepkit.cjs.map +1 -1
  64. package/dist/resolver/deepkit.mjs +6 -3
  65. package/dist/resolver/deepkit.mjs.map +1 -1
  66. package/dist/resolver/helpers.cjs +16 -22
  67. package/dist/resolver/helpers.cjs.map +1 -1
  68. package/dist/resolver/helpers.mjs +16 -22
  69. package/dist/resolver/helpers.mjs.map +1 -1
  70. package/dist/resolver/module.cjs +2 -2
  71. package/dist/resolver/module.cjs.map +1 -1
  72. package/dist/resolver/module.mjs +2 -2
  73. package/dist/resolver/module.mjs.map +1 -1
  74. package/dist/resolver/resolve.cjs +13 -13
  75. package/dist/resolver/resolve.cjs.map +1 -1
  76. package/dist/resolver/resolve.mjs +13 -13
  77. package/dist/resolver/resolve.mjs.map +1 -1
  78. package/dist/types/config.cjs +5 -3
  79. package/dist/types/config.cjs.map +1 -1
  80. package/dist/types/config.d.cts +7 -3
  81. package/dist/types/config.d.cts.map +1 -1
  82. package/dist/types/config.d.mts +7 -3
  83. package/dist/types/config.d.mts.map +1 -1
  84. package/dist/types/config.mjs +5 -3
  85. package/dist/types/config.mjs.map +1 -1
  86. package/package.json +11 -11
@@ -1 +1 @@
1
- {"version":3,"file":"deepkit.mjs","names":[],"sources":["../../src/resolver/deepkit.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type {\n ReflectionParameter,\n ReflectionProperty,\n Type,\n TypeArray,\n TypeLiteral\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n reflect,\n ReflectionClass,\n ReflectionFunction,\n ReflectionKind,\n stringifyType\n} from \"@powerlines/deepkit/vendor/type\";\nimport { isBigInt } from \"@stryke/type-checks/is-bigint\";\nimport { isNumber } from \"@stryke/type-checks/is-number\";\nimport { isRegExp } from \"@stryke/type-checks/is-regexp\";\nimport type {\n CommandArgument,\n CommandOption,\n CommandParameterKind,\n Context,\n NumberCommandParameter,\n StringCommandParameter\n} from \"../types\";\nimport { CommandParameterKinds } from \"../types\";\nimport { mergeCommandParameter } from \"./helpers\";\nimport type { ResolverContext } from \"./types\";\n\nfunction extractCommandParameterKind(\n type: Type | ReflectionKind\n): CommandParameterKind {\n if (type === ReflectionKind.string) {\n return CommandParameterKinds.string;\n } else if (\n type === ReflectionKind.number ||\n type === ReflectionKind.bigint ||\n ((type as Type).kind === ReflectionKind.literal &&\n (isNumber((type as TypeLiteral).literal) ||\n isBigInt((type as TypeLiteral).literal)))\n ) {\n return CommandParameterKinds.number;\n } else if (type === ReflectionKind.boolean) {\n return CommandParameterKinds.boolean;\n } else {\n return CommandParameterKinds.string;\n }\n}\n\nfunction resolveCommandOption(\n ctx: ResolverContext,\n reflection: ReflectionProperty\n): CommandOption {\n const type = reflection.getType();\n const existing = (ctx.output.options[reflection.getNameAsString()] ??\n {}) as Partial<CommandOption>;\n\n const option = {\n name: reflection.getNameAsString(),\n alias: reflection.getTags().alias ?? [],\n title: reflection.getTags().title?.trim(),\n description: reflection.getDescription(),\n kind: extractCommandParameterKind(type),\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n variadic: reflection.isArray()\n };\n\n if (reflection.isArray()) {\n if (\n (type as TypeArray).type.kind === ReflectionKind.string ||\n (type as TypeArray).type.kind === ReflectionKind.number\n ) {\n (option as StringCommandParameter | NumberCommandParameter).variadic =\n true;\n (option as StringCommandParameter | NumberCommandParameter).kind =\n extractCommandParameterKind((type as TypeArray).type.kind) as\n | \"string\"\n | \"number\";\n } else {\n throw new Error(\n `Unsupported array type for option \"${reflection.getNameAsString()}\" in command \"${\n ctx.input.command.name\n }\". Only string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (type.kind === ReflectionKind.union) {\n option.kind = type.types.every(\n t =>\n t.kind === ReflectionKind.number ||\n (t.kind === ReflectionKind.literal &&\n (isNumber(t.literal) || isBigInt(t.literal)))\n )\n ? CommandParameterKinds.number\n : CommandParameterKinds.string;\n\n (option as StringCommandParameter | NumberCommandParameter).choices =\n type.types\n .map(t =>\n t.kind === ReflectionKind.literal\n ? isNumber(t.literal)\n ? t.literal\n : isBigInt(t.literal)\n ? Number(t.literal)\n : isRegExp(t.literal)\n ? t.literal.source\n : String(t.literal)\n : null\n )\n .filter(Boolean) as string[] | number[];\n } else if (type.kind === ReflectionKind.literal) {\n (option as StringCommandParameter | NumberCommandParameter).choices = [\n isNumber(type.literal)\n ? type.literal\n : isBigInt(type.literal)\n ? Number(type.literal)\n : isRegExp(type.literal)\n ? type.literal.source\n : String(type.literal)\n ].filter(Boolean) as string[] | number[];\n } else if (\n !existing.kind &&\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for option \"${reflection.getNameAsString()}\" in command \"${\n ctx.input.command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return mergeCommandParameter(existing, option) as CommandOption;\n}\n\nfunction resolveCommandArgument(\n ctx: ResolverContext,\n index: number,\n reflection: ReflectionParameter\n): CommandArgument {\n const type = reflection.getType();\n const existing = (\n ctx.output.args.length > index ? ctx.output.args[index] : {}\n ) as Partial<CommandArgument>;\n\n if (\n !existing.kind &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number &&\n type.kind !== ReflectionKind.boolean &&\n !(\n type.kind === ReflectionKind.array &&\n (type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number)\n )\n ) {\n throw new Error(\n `Unsupported type for argument \"${reflection.getName()}\" in command \"${\n ctx.input.command.name\n }\". Only string types (or an array of strings) are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n const argument = {\n name: reflection.getName() || reflection.parameter.name,\n alias: reflection.getAlias(),\n kind: extractCommandParameterKind(type.kind),\n title: reflection.getTitle() || reflection.parameter.tags?.title,\n description: reflection.parameter.description,\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue()\n };\n\n if (type.kind === ReflectionKind.array) {\n if (\n type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number\n ) {\n (argument as StringCommandParameter | NumberCommandParameter).variadic =\n true;\n (argument as StringCommandParameter | NumberCommandParameter).kind =\n extractCommandParameterKind(type.type.kind) as \"string\" | \"number\";\n } else if (!existing.kind) {\n throw new Error(\n `Unsupported array type for argument \"${reflection.getName()}\" in command \"${\n ctx.input.command.name\n }\". Only string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (\n !existing.kind &&\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for argument \"${reflection.getName()}\" in command \"${\n ctx.input.command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return mergeCommandParameter(existing, argument, {\n name: `arg${index}`\n }) as CommandArgument;\n}\n\nexport function resolveFromBytecode<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n) {\n const { input, module } = ctx;\n\n const type = reflect(module);\n if (type.kind !== ReflectionKind.function) {\n throw new Error(\n `The command entry file \"${\n input.command.entry.input?.file || input.command.path\n }\" does not export a valid function.`\n );\n }\n\n const reflection = new ReflectionFunction(type);\n\n ctx.output.description ??= (ctx.input.command.description ||\n reflection.getDescription() ||\n type.description)!;\n\n const parameters = reflection.getParameters();\n if (parameters.length > 0 && parameters[0]) {\n if (\n parameters[0].type.kind === ReflectionKind.objectLiteral ||\n parameters[0].type.kind === ReflectionKind.class\n ) {\n const optionsReflection = ReflectionClass.from(parameters[0].type);\n for (const propertyReflection of optionsReflection.getProperties()) {\n ctx.output.options[propertyReflection.getNameAsString()] =\n resolveCommandOption(ctx, propertyReflection);\n }\n } else if (!ctx.module?.options) {\n throw new Error(\n `The first parameter of the command handler function in \"${\n ctx.input.command.entry.input?.file || ctx.input.command.path\n }\" must be an object literal or class type representing the command options.`\n );\n }\n\n ctx.output.args = parameters\n .slice(1)\n .map((arg, index) => resolveCommandArgument(ctx, index, arg));\n }\n}\n"],"mappings":";;;;;;;;AAEA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;AAQX,SAAS,4BAA4B,MAAM;oCAEnC,QAAO,sBAAqB;UAEvB,SAAS,eAAe,4CAE5B,KAAG,SAAA,eAAA,YACC,SAAQ,KAAA,QAAA,IACL,SAAI,KAAA,QAAA,EACd,QAAA,sBAAA;UAEM,SAAA,eAAA,QACJ,QAAO,sBAAsB;KAG7B,QAAO,sBAAE;;AAGjB,4BAAc,SAAA;CAAA;OAAA;CAAA;CAAA;CAAA;CAAA;CAAA;AACd,SAAS,qBAAqB,KAAK,YAAK;CACpC,MAAM,OAAO,WAAW,SAAS;CACjC,MAAM,WAAY,IAAI,OAAO,QAAQ,WAAW,iBAAI,KAChD,EAAG;CACP,MAAM,SAAE;EACJ,MAAM,WAAG,iBAAA;EACT,OAAO,WAAA,SAAA,CAAA,SAAA,EAAA;EACP,OAAO,WAAO,SAAA,CAAA,OAAA,MAAA;EACd,aAAC,WAAA,gBAAA;EACD,MAAM,4BAAU,KAAA;EAChB,UAAU,WAAK,YAAA;EACf,SAAS,WAAA,iBAAA;EACT,UAAU,WAAW,SAAQ;EAChC;AACD,KAAI,WAAW,SAAS,kDAEhB,KAAK,KAAK,SAAS,eAAK,QAAA;AACxB,SAAO,WACH;AACJ,SAAO,OACH,4BAAuB,KAAA,KAAA,KAAA;OAG3B,OAAM,IAAI,MAAM,sCAAQ,WAAA,iBAAA,CAAA,gBAAA,IAAA,MAAA,QAAA,KAAA,wDAAA,cAAA,KAAA,CACnB,MAAM,CACN,WAAW,OAAO,QAAQ,CAAA,GAAI;UAGlC,KAAK,SAAS,eAAY,OAAA;AAC/B,SAAO,OAAO,KAAK,MAAM,MAAM,cAAO,MAAA,EAAA,SAAA,eAAA,UACjC,EAAE,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2BAAA,MAAA,QAAA,MAAA,OAAA,QAAA,MAAA,QAAA,KAAA,qCAAA;CAEV,MAAC,aAAA,IAAA,mBAAA,KAAA;AACH,KAAA,OAAA,gBAAA,IAAA,MAAA,QAAA,8CAEM,KAAK;CACb,MAAA,aAAA,WAAA,eAAA;;AAEQ,MAAI,WAAW,GAAG,KAAK,SAAA,eAAA,iBACnB,WAAU,GAAA,KAAA,SAAA,eAAA,OAAA;GACV,MAAG,oBAAA,gBAAA,KAAA,WAAA,GAAA,KAAA;AACH,QAAK,MAAM,sBAAS,kBAAA,eAAA,CAChB,KAAG,OAAA,QAAA,mBAAA,iBAAA,IACC,qBAAe,KAAA,mBAAA;aAGlB,CAAC,IAAI,QAAQ;AAGtB,MAAI,OAAO,OAAC,WACP,MAAM,EAAE,CACR,IAAI,cAAc,KAAK,UAAK,uBAAA,KAAA,OAAA,IAAA,EAAA;GAAA;GAAA;GAAA;GAAA;GAAA,CAAA,CAAA;;;AAGzC,oBAAoB,SAAS;CAAC;CAAY;CAAA;CAAA;CAAA"}
1
+ {"version":3,"file":"deepkit.mjs","names":[],"sources":["../../src/resolver/deepkit.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type {\n ReflectionParameter,\n ReflectionProperty,\n Type,\n TypeArray\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n reflect,\n ReflectionClass,\n ReflectionFunction,\n ReflectionKind,\n stringifyType\n} from \"@powerlines/deepkit/vendor/type\";\nimport { isBigInt } from \"@stryke/type-checks/is-bigint\";\nimport { isNumber } from \"@stryke/type-checks/is-number\";\nimport { isRegExp } from \"@stryke/type-checks/is-regexp\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport type {\n CommandArgument,\n CommandOption,\n CommandParameterKind,\n Context,\n NumberCommandParameter,\n StringCommandParameter\n} from \"../types\";\nimport { CommandParameterKinds } from \"../types\";\nimport { mergeCommandParameter } from \"./helpers\";\nimport type { ResolverContext } from \"./types\";\n\nfunction extractCommandParameterKind(\n type: Type | ReflectionKind\n): CommandParameterKind {\n const isKind = !(isSetObject(type) && \"kind\" in type);\n const kind = !isKind ? type.kind : type;\n if (kind === ReflectionKind.string) {\n return CommandParameterKinds.string;\n } else if (\n kind === ReflectionKind.number ||\n kind === ReflectionKind.bigint ||\n (!isKind &&\n type.kind === ReflectionKind.literal &&\n (isNumber(type.literal) || isBigInt(type.literal)))\n ) {\n return CommandParameterKinds.number;\n } else if (kind === ReflectionKind.boolean) {\n return CommandParameterKinds.boolean;\n } else {\n return CommandParameterKinds.string;\n }\n}\n\nfunction resolveCommandOption(\n ctx: ResolverContext,\n reflection: ReflectionProperty\n): CommandOption {\n const type = reflection.getType();\n const existing = (ctx.output.options[reflection.getNameAsString()] ??\n {}) as Partial<CommandOption>;\n\n const option = {\n name: reflection.getNameAsString(),\n alias: reflection.getTags().alias ?? [],\n title: reflection.getTags().title?.trim(),\n description: reflection.getDescription(),\n kind: extractCommandParameterKind(type),\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n variadic: reflection.isArray()\n };\n\n if (reflection.isArray()) {\n if (\n (type as TypeArray).type.kind === ReflectionKind.string ||\n (type as TypeArray).type.kind === ReflectionKind.number\n ) {\n (option as StringCommandParameter | NumberCommandParameter).variadic =\n true;\n (option as StringCommandParameter | NumberCommandParameter).kind =\n extractCommandParameterKind((type as TypeArray).type.kind) as\n | \"string\"\n | \"number\";\n } else {\n throw new Error(\n `Unsupported array type for option \"${reflection.getNameAsString()}\" in command \"${\n ctx.input.command.name\n }\". Only string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (type.kind === ReflectionKind.union) {\n option.kind = type.types.every(\n t =>\n t.kind === ReflectionKind.number ||\n (t.kind === ReflectionKind.literal &&\n (isNumber(t.literal) || isBigInt(t.literal)))\n )\n ? CommandParameterKinds.number\n : CommandParameterKinds.string;\n\n (option as StringCommandParameter | NumberCommandParameter).choices =\n type.types\n .map(t =>\n t.kind === ReflectionKind.literal\n ? isNumber(t.literal)\n ? t.literal\n : isBigInt(t.literal)\n ? Number(t.literal)\n : isRegExp(t.literal)\n ? t.literal.source\n : String(t.literal)\n : null\n )\n .filter(Boolean) as string[] | number[];\n } else if (type.kind === ReflectionKind.literal) {\n (option as StringCommandParameter | NumberCommandParameter).choices = [\n isNumber(type.literal)\n ? type.literal\n : isBigInt(type.literal)\n ? Number(type.literal)\n : isRegExp(type.literal)\n ? type.literal.source\n : String(type.literal)\n ].filter(Boolean) as string[] | number[];\n } else if (\n !existing.kind &&\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for option \"${reflection.getNameAsString()}\" in command \"${\n ctx.input.command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return mergeCommandParameter(existing, option) as CommandOption;\n}\n\nfunction resolveCommandArgument(\n ctx: ResolverContext,\n index: number,\n reflection: ReflectionParameter\n): CommandArgument {\n const type = reflection.getType();\n const existing = (\n ctx.output.args.length > index ? ctx.output.args[index] : {}\n ) as Partial<CommandArgument>;\n\n if (\n !existing.kind &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number &&\n type.kind !== ReflectionKind.boolean &&\n !(\n type.kind === ReflectionKind.array &&\n (type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number)\n )\n ) {\n throw new Error(\n `Unsupported type for argument \"${reflection.getName()}\" in command \"${\n ctx.input.command.name\n }\". Only string types (or an array of strings) are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n const argument = {\n name: reflection.getName() || reflection.parameter.name,\n alias: reflection.getAlias(),\n kind: extractCommandParameterKind(type.kind),\n title: reflection.getTitle() || reflection.parameter.tags?.title,\n description: reflection.parameter.description,\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue()\n };\n\n if (type.kind === ReflectionKind.array) {\n if (\n type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number\n ) {\n (argument as StringCommandParameter | NumberCommandParameter).variadic =\n true;\n (argument as StringCommandParameter | NumberCommandParameter).kind =\n extractCommandParameterKind(type.type.kind) as \"string\" | \"number\";\n } else if (!existing.kind) {\n throw new Error(\n `Unsupported array type for argument \"${reflection.getName()}\" in command \"${\n ctx.input.command.name\n }\". Only string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (\n !existing.kind &&\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for argument \"${reflection.getName()}\" in command \"${\n ctx.input.command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return mergeCommandParameter(existing, argument, {\n name: `arg${index}`\n }) as CommandArgument;\n}\n\nexport function resolveFromBytecode<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n) {\n const { input, module } = ctx;\n\n const type = reflect(module);\n if (type.kind !== ReflectionKind.function) {\n throw new Error(\n `The command entry file \"${\n input.command.entry.input?.file || input.command.path\n }\" does not export a valid function.`\n );\n }\n\n const reflection = new ReflectionFunction(type);\n\n ctx.output.description ??= (ctx.input.command.description ||\n reflection.getDescription() ||\n type.description)!;\n\n const parameters = reflection.getParameters();\n if (parameters.length > 0 && parameters[0]) {\n if (\n parameters[0].type.kind === ReflectionKind.objectLiteral ||\n parameters[0].type.kind === ReflectionKind.class\n ) {\n const optionsReflection = ReflectionClass.from(parameters[0].type);\n for (const propertyReflection of optionsReflection.getProperties()) {\n ctx.output.options[propertyReflection.getNameAsString()] =\n resolveCommandOption(ctx, propertyReflection);\n }\n } else if (!ctx.module?.options) {\n throw new Error(\n `The first parameter of the command handler function in \"${\n ctx.input.command.entry.input?.file || ctx.input.command.path\n }\" must be an object literal or class type representing the command options.`\n );\n }\n\n ctx.output.args = parameters\n .slice(1)\n .map((arg, index) => resolveCommandArgument(ctx, index, arg));\n }\n}\n"],"mappings":";;;;;;;;;AAEA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;;CAUP,MAAM,SAAS,EAAE,YAAY,KAAG,IAAA,UAAA;;AAEhC,KAAI,SAAS,eAAe;UAGnB,SAAQ,eAAA,UACb,SAAS,eAAG,UACd,CAAA,UACI,KAAA,SAAA,eAAA,YACG,SAAS,KAAK,QAAQ,IAAI,SAAC,KAAA,QAAA,EACjC,QAAA,sBAAA;UAEM,SAAI,eAAA,QACT,QAAO,sBAAK;KAGZ,QAAO,sBAAsB;;AAGrC,4BAA4B,SAAS;CAAC;OAAc;CAAI;CAAA;CAAA;CAAA;CAAA;AACxD,SAAS,qBAAqB,KAAK,YAAY;CAC3C,MAAM,OAAE,WAAA,SAAA;CACR,MAAM,WAAO,IAAA,OAAA,QAAA,WAAA,iBAAA,KACT,EAAG;CACP,MAAM,SAAS;EACX,MAAC,WAAA,iBAAA;EACD,OAAO,WAAS,SAAA,CAAA,SAAA,EAAA;EAChB,OAAO,WAAQ,SAAA,CAAA,OAAA,MAAA;EACf,aAAS,WAAA,gBAAA;EACT,MAAM,4BAA4B,KAAK;EACvC,UAAU,WAAW,YAAY;EACjC,SAAS,WAAW,iBAAiB;;EAExC;AACD,KAAI,WAAW,SAAS,CAC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AAA,SAAA,CAAA,gBAAA,IAAA,MAAA,QAAA,KAAA,iFAAA,cAAA,KAAA,CACC,MAAM,CACN,WAAW,OAAO,QAAQ,CAAA,GAAG;AAEtC,QAAO,sBAAsB,UAAK,UAAA,EAClC,MAAA,MAAA,SACC,CAAC;;AAEN,uBAAuB,SAAM;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;AAC7B,SAAgB,oBAAoB,KAAK;CACrC,MAAM,EAAC,OAAA,WAAA;CACP,MAAE,OAAA,QAAA,OAAA;AACF,KAAI,KAAK,SAAC,eAAA,SACN,OAAM,IAAI,MAAM,2BAAa,MAAA,QAAA,MAAA,OAAA,QAAA,MAAA,QAAA,KAAA,qCAAA;CAEnC,MAAA,aAAA,IAAA,mBAAA,KAAA;6DAEM,WAAW,gBAAgB,IACnC,KAAA;;AAEI,KAAI,WAAW,SAAS,KAAG,WAAA,IAAA;AACvB,MAAI,WAAU,GAAA,KAAA,SAAA,eAAA,iBACV,WAAG,GAAA,KAAA,SAAA,eAAA,OAAA;GACH,MAAM,oBAAc,gBAAA,KAAA,WAAA,GAAA,KAAA;AACpB,QAAK,MAAE,sBAAA,kBAAA,eAAA,CACH,KAAI,OAAO,QAAQ,mBAAA,iBAAA,IAChB,qBAAA,KAAA,mBAAA;kCAId,OAAA,IAAA,MAAA,2DAAA,IAAA,MAAA,QAAA,MAAA,OAAA,QAAA,IAAA,MAAA,QAAA,KAAA,6EAAA;AAEG,MAAI,OAAO,OAAO,WACb,MAAM,EAAE,CACR,IAAI,cAAc,KAAK,UAAM,uBAAA,KAAA,OAAA,IAAA,EAAA;GAAA;GAAA;GAAA;GAAA;GAAA,CAAA,CAAA;;;AAG1C,oBAAoB,SAAS;CAAC;CAAmB;CAAA;CAAA;CAAA"}
@@ -9,12 +9,6 @@ let __stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
9
9
  let __stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
10
10
 
11
11
  //#region src/resolver/helpers.ts
12
- const __ΩRecord = [
13
- "K",
14
- "T",
15
- "Record",
16
- "l'e#\"Rb!b\"Pde\"!N#!w#y"
17
- ];
18
12
  function __assignType(fn, args) {
19
13
  fn.__type = args;
20
14
  return fn;
@@ -69,8 +63,8 @@ resolveCommandArgumentDescription.__type = [
69
63
  "resolveCommandArgumentDescription",
70
64
  "P&2!\"w\"2#\"2$\"2%&2&8\"2'8&/("
71
65
  ];
72
- function applyOptionsDefaults(options) {
73
- return Object.fromEntries(Object.entries(options).map(__assignType(([key, option]) => {
66
+ function applyOptionsDefaults(ctx) {
67
+ return Object.fromEntries(Object.entries(ctx.output.options).map(__assignType(([key, option]) => {
74
68
  const name = option.name || key;
75
69
  const title = option.title || (0, __stryke_string_format_title_case.titleCase)(name);
76
70
  return [key, {
@@ -78,7 +72,7 @@ function applyOptionsDefaults(options) {
78
72
  name,
79
73
  title,
80
74
  description: option.description || resolveCommandOptionDescription(name, option.kind, option.optional, option.kind !== require_types_command.CommandParameterKinds.boolean && option.variadic, title, option.default),
81
- env: option.env || (0, __stryke_string_format_constant_case.constantCase)(key)
75
+ env: option.env || option.env === false ? option.env : ctx.input.context.config.autoAssignEnv ? (0, __stryke_string_format_constant_case.constantCase)(name) : false
82
76
  }];
83
77
  }, [
84
78
  "param0",
@@ -87,14 +81,13 @@ function applyOptionsDefaults(options) {
87
81
  ])));
88
82
  }
89
83
  applyOptionsDefaults.__type = [
90
- () => __ΩRecord,
91
- "CommandOption",
92
- "options",
84
+ "ResolverContext",
85
+ "ctx",
93
86
  "applyOptionsDefaults",
94
- "P&\"w\"o!#2#\"/$"
87
+ "P\"w!2\"\"/#"
95
88
  ];
96
- function applyArgsDefaults(args) {
97
- return args.map(__assignType((arg, i) => {
89
+ function applyArgsDefaults(ctx) {
90
+ return ctx.output.args.map(__assignType((arg, i) => {
98
91
  const name = arg.name || `arg${i + 1}`;
99
92
  const title = arg.title || (0, __stryke_string_format_title_case.titleCase)(name);
100
93
  return {
@@ -102,7 +95,7 @@ function applyArgsDefaults(args) {
102
95
  name,
103
96
  title,
104
97
  description: arg.description || resolveCommandArgumentDescription(name, arg.kind, arg.optional, arg.kind !== require_types_command.CommandParameterKinds.boolean && arg.variadic, title, arg.default),
105
- env: arg.name ? arg.env || arg.env === false ? arg.env : (0, __stryke_string_format_constant_case.constantCase)(name) : false
98
+ env: arg.name ? arg.env || arg.env === false ? arg.env : ctx.input.context.config.autoAssignEnv ? (0, __stryke_string_format_constant_case.constantCase)(name) : false : false
106
99
  };
107
100
  }, [
108
101
  "arg",
@@ -112,23 +105,24 @@ function applyArgsDefaults(args) {
112
105
  ]));
113
106
  }
114
107
  applyArgsDefaults.__type = [
108
+ "ResolverContext",
109
+ "ctx",
115
110
  "CommandArgument",
116
- "args",
117
111
  "applyArgsDefaults",
118
- "P\"w!F2\"\"w!F/#"
112
+ "P\"w!2\"\"w#F/$"
119
113
  ];
120
- function applyDefaults(context) {
121
- context.output.description ??= `The ${context.output.title.replace(/(?:c|C)ommands?$/, "").trim()} executable command-line interface.`;
114
+ function applyDefaults(ctx) {
115
+ ctx.output.description ??= `The ${ctx.output.title.replace(/(?:c|C)ommands?$/, "").trim()} executable command-line interface.`;
122
116
  }
123
117
  applyDefaults.__type = [
124
118
  "ResolverContext",
125
- "context",
119
+ "ctx",
126
120
  "applyDefaults",
127
121
  "P\"w!2\"\"/#"
128
122
  ];
129
123
  function resolveVirtualCommand(ctx) {
130
124
  ctx.output.title ??= (0, __stryke_string_format_title_case.titleCase)(ctx.input.command.name);
131
- ctx.output.description ??= `A collection of available ${ctx.output.title.replace(/(?:c|C)ommands?$/, "").trim() || (0, __stryke_string_format_title_case.titleCase)(ctx.input.command.name)} commands that are included in the ${require_context_helpers.getAppTitle(ctx.input.context)} command-line application.`;
125
+ ctx.output.description ??= `A collection of available ${ctx.output.title.replace(/(?:c|C)ommands?$/, "").trim() || (0, __stryke_string_format_title_case.titleCase)(ctx.input.command.name)} commands that are included in the ${require_context_helpers.getAppTitle(ctx.input.context, true)} command-line application.`;
132
126
  }
133
127
  resolveVirtualCommand.__type = [
134
128
  "ResolverContext",
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.cjs","names":[],"sources":["../../src/resolver/helpers.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { getUniqueBy } from \"@stryke/helpers/get-unique\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport { createDefu } from \"defu\";\nimport { getAppTitle } from \"../plugin-utils/context-helpers\";\nimport type {\n CommandArgument,\n CommandOption,\n CommandParameterKind\n} from \"../types/command\";\nimport { CommandParameterKinds } from \"../types/command\";\nimport type { Context } from \"../types/context\";\nimport type { ResolverContext } from \"./types\";\n\n/**\n * Resolves the description for a command option based on its reflection.\n *\n * @param name - The name of the command option.\n * @param kind - The reflection kind of the command option.\n * @param optional - Whether the command option is optional.\n * @param variadic - Whether the command option is variadic (i.e., an array).\n * @param title - The title of the command option, if any.\n * @param defaultValue - The default value of the command option, if any.\n * @returns The resolved description for the command option.\n */\nexport function resolveCommandOptionDescription(\n name: string,\n kind: CommandParameterKind,\n optional = false,\n variadic = false,\n title?: string,\n defaultValue?: any\n): string {\n return `A${optional && !defaultValue ? \"n optional\" : \"\"} command-line ${\n kind === CommandParameterKinds.boolean ? \"flag\" : \"option\"\n } that allows the user to ${\n kind === CommandParameterKinds.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === CommandParameterKinds.boolean\n ? \"indicator\"\n : `${kind === CommandParameterKinds.number ? \"numeric\" : \"string\"} value${\n variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\n/**\n * Resolves the description for a command argument based on its reflection.\n *\n * @param name - The name of the command argument.\n * @param kind - The reflection kind of the command argument.\n * @param optional - Whether the command argument is optional.\n * @param variadic - Whether the command argument is variadic (i.e., an array).\n * @param title - The title of the command argument, if any.\n * @param defaultValue - The default value of the command argument, if any.\n * @returns The resolved description for the command argument.\n */\nexport function resolveCommandArgumentDescription(\n name: string,\n kind: CommandParameterKind,\n optional = false,\n variadic = false,\n title?: string,\n defaultValue?: any\n): string {\n return `An${\n optional && !defaultValue ? \" optional\" : \"\"\n } argument that allows the user to ${\n kind === CommandParameterKinds.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === CommandParameterKinds.boolean\n ? \"indicator\"\n : `${kind === CommandParameterKinds.number ? \"numeric\" : \"string\"} value${\n variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\nexport function applyOptionsDefaults(options: Record<string, CommandOption>) {\n return Object.fromEntries(\n Object.entries(options).map(([key, option]) => {\n const name = option.name || key;\n const title = option.title || titleCase(name);\n\n return [\n key,\n {\n ...option,\n name,\n title,\n description:\n option.description ||\n resolveCommandOptionDescription(\n name,\n option.kind,\n option.optional,\n option.kind !== CommandParameterKinds.boolean && option.variadic,\n title,\n option.default\n ),\n env: option.env || constantCase(key)\n }\n ];\n })\n );\n}\n\nexport function applyArgsDefaults(args: CommandArgument[]): CommandArgument[] {\n return args.map((arg, i) => {\n const name = arg.name || `arg${i + 1}`;\n const title = arg.title || titleCase(name);\n\n return {\n ...arg,\n name,\n title,\n description:\n arg.description ||\n resolveCommandArgumentDescription(\n name,\n arg.kind,\n arg.optional,\n arg.kind !== CommandParameterKinds.boolean && arg.variadic,\n title,\n arg.default\n ),\n env: arg.name\n ? arg.env || arg.env === false\n ? arg.env\n : constantCase(name)\n : false\n };\n });\n}\n\nexport function applyDefaults(context: ResolverContext) {\n context.output.description ??= `The ${context.output.title.replace(/(?:c|C)ommands?$/, \"\").trim()} executable command-line interface.`;\n}\n\nexport function resolveVirtualCommand<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n) {\n ctx.output.title ??= titleCase(ctx.input.command.name);\n ctx.output.description ??= `A collection of available ${\n ctx.output.title.replace(/(?:c|C)ommands?$/, \"\").trim() ||\n titleCase(ctx.input.command.name)\n } commands that are included in the ${getAppTitle(\n ctx.input.context\n )} command-line application.`;\n}\n\n/**\n * Merges two command parameters, giving precedence to string values in the second configuration.\n *\n * @param objA - The first command parameter object.\n * @param objB - The second command parameter object.\n * @returns The merged command parameter object.\n */\nexport const mergeCommandParameter = createDefu((obj, key, value) => {\n if (isString(obj[key]) && isString(value)) {\n if (isSetString(value)) {\n obj[key] = value;\n }\n\n return true;\n } else if (Array.isArray(obj[key]) && Array.isArray(value)) {\n if (value.length > 0) {\n obj[key] = getUniqueBy((obj[key] as unknown[]).concat(value), item =>\n isString(item) ? item : JSON.stringify(item)\n ) as (typeof obj)[typeof key];\n }\n\n return true;\n }\n\n return false;\n});\n"],"mappings":";;;;;;;;;;;AAAA,MAAM,YAAY;CAAC;CAAK;CAAK;CAAU;CAAyB;;AAE5D,IAAG,SAAS;;;;;;;;;;;;;;AAuChB,SAAgB,gCAAgC,MAAM,MAAG,WAAA,OAAA,WAAA,OAAA,OAAA,cAAA;AACrD,QAAO,IAAI,YAAY,CAAC,eAAe,eAAe,GAAE,gBAAY,SAAA,4CAAA,UAAA,SAAA,SAAA,2BAAA,SAAA,4CAAA,UAC9D,YACR,WACY,mBACA,mBAAA,GAAA,OAAA,MAAA,qDAAA,KAAA,CAAA,GAAA,SAAA,4CAAA,UACJ,cACA,GAAG,SAAK,4CAAA,SAAA,YAAA,S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I,OACH,IAAI,OAAM,IAAA,QAAA,QACnB,IAAA,6DACJ,KAAA,GACL;;IAEO;EAAC;EAAO;EAAK;EAAI;EAAa,CAAC,CAAC;;AAEvC,kBAAkB,SAAS;CAAC;CAAmB;CAAI;CAAA;CAAA;AACnD,SAAgB,cAAc,SAAO;AACjC,SAAQ,OAAO,gBAAgB,OAAO,QAAQ,OAAC,MAAA,QAAA,oBAAA,GAAA,CAAA,MAAA,CAAA;;AAEnD,cAAa,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;AACb,SAAW,sBAAA,KAAA;AACP,KAAI,OAAA,2DAAA,IAAA,MAAA,QAAA,KAAA;AACJ,KAAI,OAAO,gBAAI,6BAAA,IAAA,OAAA,MAAA,QAAA,oBAAA,GAAA,CAAA,MAAA,qDACL,IAAA,MAAA,QAAA,KAAA,CAAA,qCAAA,oCAAA,IAAA,MAAA,QAAA,CAAA;;AAEd,sBAAqB,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;AAQrB,MAAa,6CAAc,cAAA,KAAA,KAAA,UAAA;AACvB,kDAAS,IAAA,KAAA,iDAAA,MAAA,EAAA;AACL,0DAAgB,MAAM,CACtB,KAAA,OAAA;AAEH,SAAA;YAEL,MAAA,QAAA,IAAA,KAAA,IAAA,MAAA,QAAA,MAAA,EAAA;uBAEY,KAAI,oDAAmB,IAAI,KAAK,OAAO,MAAM,EAAE,cAAa,sDAAM,KAAA,GAAA,OAAA,KAAA,UAAA,KAAA,EAAA;GAAA;GAAA;GAAA;GAAA,CAAA,CAAA;AAEtE,SAAO;;;GAGZ;CAAC;CAAO;CAAA;CAAA;CAAA;CAAA,CAAA,CAAA"}
1
+ {"version":3,"file":"helpers.cjs","names":[],"sources":["../../src/resolver/helpers.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { getUniqueBy } from \"@stryke/helpers/get-unique\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport { createDefu } from \"defu\";\nimport { getAppTitle } from \"../plugin-utils/context-helpers\";\nimport type { CommandArgument, CommandParameterKind } from \"../types/command\";\nimport { CommandParameterKinds } from \"../types/command\";\nimport type { Context } from \"../types/context\";\nimport type { ResolverContext } from \"./types\";\n\n/**\n * Resolves the description for a command option based on its reflection.\n *\n * @param name - The name of the command option.\n * @param kind - The reflection kind of the command option.\n * @param optional - Whether the command option is optional.\n * @param variadic - Whether the command option is variadic (i.e., an array).\n * @param title - The title of the command option, if any.\n * @param defaultValue - The default value of the command option, if any.\n * @returns The resolved description for the command option.\n */\nexport function resolveCommandOptionDescription(\n name: string,\n kind: CommandParameterKind,\n optional = false,\n variadic = false,\n title?: string,\n defaultValue?: any\n): string {\n return `A${optional && !defaultValue ? \"n optional\" : \"\"} command-line ${\n kind === CommandParameterKinds.boolean ? \"flag\" : \"option\"\n } that allows the user to ${\n kind === CommandParameterKinds.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === CommandParameterKinds.boolean\n ? \"indicator\"\n : `${kind === CommandParameterKinds.number ? \"numeric\" : \"string\"} value${\n variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\n/**\n * Resolves the description for a command argument based on its reflection.\n *\n * @param name - The name of the command argument.\n * @param kind - The reflection kind of the command argument.\n * @param optional - Whether the command argument is optional.\n * @param variadic - Whether the command argument is variadic (i.e., an array).\n * @param title - The title of the command argument, if any.\n * @param defaultValue - The default value of the command argument, if any.\n * @returns The resolved description for the command argument.\n */\nexport function resolveCommandArgumentDescription(\n name: string,\n kind: CommandParameterKind,\n optional = false,\n variadic = false,\n title?: string,\n defaultValue?: any\n): string {\n return `An${\n optional && !defaultValue ? \" optional\" : \"\"\n } argument that allows the user to ${\n kind === CommandParameterKinds.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === CommandParameterKinds.boolean\n ? \"indicator\"\n : `${kind === CommandParameterKinds.number ? \"numeric\" : \"string\"} value${\n variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\nexport function applyOptionsDefaults(ctx: ResolverContext) {\n return Object.fromEntries(\n Object.entries(ctx.output.options).map(([key, option]) => {\n const name = option.name || key;\n const title = option.title || titleCase(name);\n\n return [\n key,\n {\n ...option,\n name,\n title,\n description:\n option.description ||\n resolveCommandOptionDescription(\n name,\n option.kind,\n option.optional,\n option.kind !== CommandParameterKinds.boolean && option.variadic,\n title,\n option.default\n ),\n env:\n option.env || option.env === false\n ? option.env\n : ctx.input.context.config.autoAssignEnv\n ? constantCase(name)\n : false\n }\n ];\n })\n );\n}\n\nexport function applyArgsDefaults(ctx: ResolverContext): CommandArgument[] {\n return ctx.output.args.map((arg, i) => {\n const name = arg.name || `arg${i + 1}`;\n const title = arg.title || titleCase(name);\n\n return {\n ...arg,\n name,\n title,\n description:\n arg.description ||\n resolveCommandArgumentDescription(\n name,\n arg.kind,\n arg.optional,\n arg.kind !== CommandParameterKinds.boolean && arg.variadic,\n title,\n arg.default\n ),\n env: arg.name\n ? arg.env || arg.env === false\n ? arg.env\n : ctx.input.context.config.autoAssignEnv\n ? constantCase(name)\n : false\n : false\n };\n });\n}\n\nexport function applyDefaults(ctx: ResolverContext) {\n ctx.output.description ??= `The ${ctx.output.title.replace(/(?:c|C)ommands?$/, \"\").trim()} executable command-line interface.`;\n}\n\nexport function resolveVirtualCommand<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n) {\n ctx.output.title ??= titleCase(ctx.input.command.name);\n ctx.output.description ??= `A collection of available ${\n ctx.output.title.replace(/(?:c|C)ommands?$/, \"\").trim() ||\n titleCase(ctx.input.command.name)\n } commands that are included in the ${getAppTitle(\n ctx.input.context,\n true\n )} command-line application.`;\n}\n\n/**\n * Merges two command parameters, giving precedence to string values in the second configuration.\n *\n * @param objA - The first command parameter object.\n * @param objB - The second command parameter object.\n * @returns The merged command parameter object.\n */\nexport const mergeCommandParameter = createDefu((obj, key, value) => {\n if (isString(obj[key]) && isString(value)) {\n if (isSetString(value)) {\n obj[key] = value;\n }\n\n return true;\n } else if (Array.isArray(obj[key]) && Array.isArray(value)) {\n if (value.length > 0) {\n obj[key] = getUniqueBy((obj[key] as unknown[]).concat(value), item =>\n isString(item) ? item : JSON.stringify(item)\n ) as (typeof obj)[typeof key];\n }\n\n return true;\n }\n\n return false;\n});\n"],"mappings":";;;;;;;;;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;;;;;;;;;;;;AAsCX,SAAE,gCAAA,MAAA,MAAA,WAAA,OAAA,WAAA,OAAA,OAAA,cAAA;AACE,QAAO,IAAI,YAAY,CAAC,eAAe,eAAI,GAAA,gBAAA,SAAA,4CAAA,UAAA,SAAA,SAAA,2BAAA,SAAA,4CAAA,UACrC,YACA,WACI,mBACA,mBAAI,GAAA,OAAA,MAAA,qDAAA,KAAA,CAAA,GAAA,SAAA,4CAAA,UACR,cACA,GAAG,SAAM,4CAAA,SAAA,YAAA,SAAA,QAAA,WAAA,MAAA,KAAA;;AAEnB,gCAAgC,SAAS;CAAC;CAAQ;CAAwB;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;;;;;AAY1E,SAAgB,kCAAY,MAAA,MAAA,WAAA,OAAA,WAAA,OAAA,OAAA,cAAA;AACxB,QAAK,KAAA,YAAA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+EAElC,QACF;GACH;IACD;EAAC;EAAO;EAAI;EAAA;EAAA,CAAA,CAAA;;AAEnB,kBAAe,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;AACf,SAAgB,cAAK,KAAA;AACjB,KAAI,OAAO,gBAAgB,OAAC,IAAA,OAAA,MAAA,QAAA,oBAAA,GAAA,CAAA,MAAA,CAAA;;AAEhC,cAAc,SAAI;CAAA;CAAA;CAAA;CAAA;CAAA;AAClB,SAAgB,sBAAS,KAAA;AACrB,KAAI,OAAO,2DAAc,IAAA,MAAA,QAAA,KAAA;AACzB,KAAI,OAAO,gBAAgB,6BAA6B,IAAI,OAAO,MAAM,QAAC,oBAAA,GAAA,CAAA,MAAA,qDAC5D,IAAC,MAAA,QAAA,KAAA,CAAA,qCAAA,oCAAA,IAAA,MAAA,SAAA,KAAA,CAAA;;AAEnB,sBAAa,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;AAQb,MAAO,6CAAA,cAAA,KAAA,KAAA,UAAA;AACH,kDAAC,IAAA,KAAA,iDAAA,MAAA,EAAA;AACF,0DAAA,MAAA,CACH,KAAA,OAAA;AAEQ,SAAO;YAEF,MAAM,QAAQ,IAAI,KAAK,IAAI,MAAE,QAAA,MAAA,EAAA;AAClC,MAAI,MAAM,SAAS;;;;;AAGnB,SAAI;;AAER,QAAO;GACR;CAAC;CAAO;CAAM;CAAA;CAAA;CAAA,CAAA,CAAA"}
@@ -8,12 +8,6 @@ import { getUniqueBy } from "@stryke/helpers/get-unique";
8
8
  import { isString } from "@stryke/type-checks/is-string";
9
9
 
10
10
  //#region src/resolver/helpers.ts
11
- const __ΩRecord = [
12
- "K",
13
- "T",
14
- "Record",
15
- "l'e#\"Rb!b\"Pde\"!N#!w#y"
16
- ];
17
11
  function __assignType(fn, args) {
18
12
  fn.__type = args;
19
13
  return fn;
@@ -68,8 +62,8 @@ resolveCommandArgumentDescription.__type = [
68
62
  "resolveCommandArgumentDescription",
69
63
  "P&2!\"w\"2#\"2$\"2%&2&8\"2'8&/("
70
64
  ];
71
- function applyOptionsDefaults(options) {
72
- return Object.fromEntries(Object.entries(options).map(__assignType(([key, option]) => {
65
+ function applyOptionsDefaults(ctx) {
66
+ return Object.fromEntries(Object.entries(ctx.output.options).map(__assignType(([key, option]) => {
73
67
  const name = option.name || key;
74
68
  const title = option.title || titleCase(name);
75
69
  return [key, {
@@ -77,7 +71,7 @@ function applyOptionsDefaults(options) {
77
71
  name,
78
72
  title,
79
73
  description: option.description || resolveCommandOptionDescription(name, option.kind, option.optional, option.kind !== CommandParameterKinds.boolean && option.variadic, title, option.default),
80
- env: option.env || constantCase(key)
74
+ env: option.env || option.env === false ? option.env : ctx.input.context.config.autoAssignEnv ? constantCase(name) : false
81
75
  }];
82
76
  }, [
83
77
  "param0",
@@ -86,14 +80,13 @@ function applyOptionsDefaults(options) {
86
80
  ])));
87
81
  }
88
82
  applyOptionsDefaults.__type = [
89
- () => __ΩRecord,
90
- "CommandOption",
91
- "options",
83
+ "ResolverContext",
84
+ "ctx",
92
85
  "applyOptionsDefaults",
93
- "P&\"w\"o!#2#\"/$"
86
+ "P\"w!2\"\"/#"
94
87
  ];
95
- function applyArgsDefaults(args) {
96
- return args.map(__assignType((arg, i) => {
88
+ function applyArgsDefaults(ctx) {
89
+ return ctx.output.args.map(__assignType((arg, i) => {
97
90
  const name = arg.name || `arg${i + 1}`;
98
91
  const title = arg.title || titleCase(name);
99
92
  return {
@@ -101,7 +94,7 @@ function applyArgsDefaults(args) {
101
94
  name,
102
95
  title,
103
96
  description: arg.description || resolveCommandArgumentDescription(name, arg.kind, arg.optional, arg.kind !== CommandParameterKinds.boolean && arg.variadic, title, arg.default),
104
- env: arg.name ? arg.env || arg.env === false ? arg.env : constantCase(name) : false
97
+ env: arg.name ? arg.env || arg.env === false ? arg.env : ctx.input.context.config.autoAssignEnv ? constantCase(name) : false : false
105
98
  };
106
99
  }, [
107
100
  "arg",
@@ -111,23 +104,24 @@ function applyArgsDefaults(args) {
111
104
  ]));
112
105
  }
113
106
  applyArgsDefaults.__type = [
107
+ "ResolverContext",
108
+ "ctx",
114
109
  "CommandArgument",
115
- "args",
116
110
  "applyArgsDefaults",
117
- "P\"w!F2\"\"w!F/#"
111
+ "P\"w!2\"\"w#F/$"
118
112
  ];
119
- function applyDefaults(context) {
120
- context.output.description ??= `The ${context.output.title.replace(/(?:c|C)ommands?$/, "").trim()} executable command-line interface.`;
113
+ function applyDefaults(ctx) {
114
+ ctx.output.description ??= `The ${ctx.output.title.replace(/(?:c|C)ommands?$/, "").trim()} executable command-line interface.`;
121
115
  }
122
116
  applyDefaults.__type = [
123
117
  "ResolverContext",
124
- "context",
118
+ "ctx",
125
119
  "applyDefaults",
126
120
  "P\"w!2\"\"/#"
127
121
  ];
128
122
  function resolveVirtualCommand(ctx) {
129
123
  ctx.output.title ??= titleCase(ctx.input.command.name);
130
- ctx.output.description ??= `A collection of available ${ctx.output.title.replace(/(?:c|C)ommands?$/, "").trim() || titleCase(ctx.input.command.name)} commands that are included in the ${getAppTitle(ctx.input.context)} command-line application.`;
124
+ ctx.output.description ??= `A collection of available ${ctx.output.title.replace(/(?:c|C)ommands?$/, "").trim() || titleCase(ctx.input.command.name)} commands that are included in the ${getAppTitle(ctx.input.context, true)} command-line application.`;
131
125
  }
132
126
  resolveVirtualCommand.__type = [
133
127
  "ResolverContext",
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.mjs","names":[],"sources":["../../src/resolver/helpers.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { getUniqueBy } from \"@stryke/helpers/get-unique\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport { createDefu } from \"defu\";\nimport { getAppTitle } from \"../plugin-utils/context-helpers\";\nimport type {\n CommandArgument,\n CommandOption,\n CommandParameterKind\n} from \"../types/command\";\nimport { CommandParameterKinds } from \"../types/command\";\nimport type { Context } from \"../types/context\";\nimport type { ResolverContext } from \"./types\";\n\n/**\n * Resolves the description for a command option based on its reflection.\n *\n * @param name - The name of the command option.\n * @param kind - The reflection kind of the command option.\n * @param optional - Whether the command option is optional.\n * @param variadic - Whether the command option is variadic (i.e., an array).\n * @param title - The title of the command option, if any.\n * @param defaultValue - The default value of the command option, if any.\n * @returns The resolved description for the command option.\n */\nexport function resolveCommandOptionDescription(\n name: string,\n kind: CommandParameterKind,\n optional = false,\n variadic = false,\n title?: string,\n defaultValue?: any\n): string {\n return `A${optional && !defaultValue ? \"n optional\" : \"\"} command-line ${\n kind === CommandParameterKinds.boolean ? \"flag\" : \"option\"\n } that allows the user to ${\n kind === CommandParameterKinds.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === CommandParameterKinds.boolean\n ? \"indicator\"\n : `${kind === CommandParameterKinds.number ? \"numeric\" : \"string\"} value${\n variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\n/**\n * Resolves the description for a command argument based on its reflection.\n *\n * @param name - The name of the command argument.\n * @param kind - The reflection kind of the command argument.\n * @param optional - Whether the command argument is optional.\n * @param variadic - Whether the command argument is variadic (i.e., an array).\n * @param title - The title of the command argument, if any.\n * @param defaultValue - The default value of the command argument, if any.\n * @returns The resolved description for the command argument.\n */\nexport function resolveCommandArgumentDescription(\n name: string,\n kind: CommandParameterKind,\n optional = false,\n variadic = false,\n title?: string,\n defaultValue?: any\n): string {\n return `An${\n optional && !defaultValue ? \" optional\" : \"\"\n } argument that allows the user to ${\n kind === CommandParameterKinds.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === CommandParameterKinds.boolean\n ? \"indicator\"\n : `${kind === CommandParameterKinds.number ? \"numeric\" : \"string\"} value${\n variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\nexport function applyOptionsDefaults(options: Record<string, CommandOption>) {\n return Object.fromEntries(\n Object.entries(options).map(([key, option]) => {\n const name = option.name || key;\n const title = option.title || titleCase(name);\n\n return [\n key,\n {\n ...option,\n name,\n title,\n description:\n option.description ||\n resolveCommandOptionDescription(\n name,\n option.kind,\n option.optional,\n option.kind !== CommandParameterKinds.boolean && option.variadic,\n title,\n option.default\n ),\n env: option.env || constantCase(key)\n }\n ];\n })\n );\n}\n\nexport function applyArgsDefaults(args: CommandArgument[]): CommandArgument[] {\n return args.map((arg, i) => {\n const name = arg.name || `arg${i + 1}`;\n const title = arg.title || titleCase(name);\n\n return {\n ...arg,\n name,\n title,\n description:\n arg.description ||\n resolveCommandArgumentDescription(\n name,\n arg.kind,\n arg.optional,\n arg.kind !== CommandParameterKinds.boolean && arg.variadic,\n title,\n arg.default\n ),\n env: arg.name\n ? arg.env || arg.env === false\n ? arg.env\n : constantCase(name)\n : false\n };\n });\n}\n\nexport function applyDefaults(context: ResolverContext) {\n context.output.description ??= `The ${context.output.title.replace(/(?:c|C)ommands?$/, \"\").trim()} executable command-line interface.`;\n}\n\nexport function resolveVirtualCommand<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n) {\n ctx.output.title ??= titleCase(ctx.input.command.name);\n ctx.output.description ??= `A collection of available ${\n ctx.output.title.replace(/(?:c|C)ommands?$/, \"\").trim() ||\n titleCase(ctx.input.command.name)\n } commands that are included in the ${getAppTitle(\n ctx.input.context\n )} command-line application.`;\n}\n\n/**\n * Merges two command parameters, giving precedence to string values in the second configuration.\n *\n * @param objA - The first command parameter object.\n * @param objB - The second command parameter object.\n * @returns The merged command parameter object.\n */\nexport const mergeCommandParameter = createDefu((obj, key, value) => {\n if (isString(obj[key]) && isString(value)) {\n if (isSetString(value)) {\n obj[key] = value;\n }\n\n return true;\n } else if (Array.isArray(obj[key]) && Array.isArray(value)) {\n if (value.length > 0) {\n obj[key] = getUniqueBy((obj[key] as unknown[]).concat(value), item =>\n isString(item) ? item : JSON.stringify(item)\n ) as (typeof obj)[typeof key];\n }\n\n return true;\n }\n\n return false;\n});\n"],"mappings":";;;;;;;;;;AAAA,MAAM,YAAY;CAAC;CAAK;CAAK;CAAU;CAAyB;;AAE5D,IAAG,SAAS;;;;;;;;;;;;;;AAuChB,SAAgB,gCAAgC,MAAM,MAAG,WAAA,OAAA,WAAA,OAAA,OAAA,cAAA;AACrD,QAAO,IAAI,YAAY,CAAC,eAAe,eAAe,GAAE,gBAAY,SAAA,sBAAA,UAAA,SAAA,SAAA,2BAAA,SAAA,sBAAA,UAC9D,YACR,WACY,mBACA,mBAAA,GAAA,OAAA,MAAA,IAAA,UAAA,KAAA,CAAA,GAAA,SAAA,sBAAA,UACJ,cACA,GAAG,SAAK,sBAAA,SAAA,YAAA,SAAA,QAAA,WAAA,MAAA,KAAA;;AAElB,gCAAgB,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;;;;;AAYhB,SAAgB,kCAAyB,MAAA,MAAA,WAAA,OAAA,WAAA,OAAA,OAAA,cAAA;AACrC,QAAO,KAAK,YAAE,CAAA,eAAA,cAAA,GAAA,oCAAA,SAAA,sBAAA,UACR,YACA,WACD,mBACJ,mBAAA,GAAA,OAAA,MAAA,IAAA,UAAA,KAAA,CAAA,GAAA,SAAA,sBAAA,UACL;;AAGA,kCAAkC,SAAS;CAAC;CAAQ;CAAsB;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;AAC1E,S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AAI,6BAAA,IAAA,OAAA,MAAA,QAAA,oBAAA,GAAA,CAAA,MAAA,IACX,UAAM,IAAA,MAAA,QAAA,KAAA,CAAA,qCAAA,YAAA,IAAA,MAAA,QAAA,CAAA;;AAEd,sBAAqB,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;AAQrB,MAAa,wBAAc,WAAA,cAAA,KAAA,KAAA,UAAA;AACvB,KAAI,SAAK,IAAA,KAAA,IAAA,SAAA,MAAA,EAAA;AACL,MAAI,YAAY,MAAM,CACtB,KAAA,OAAA;AAEH,SAAA;YAEL,MAAA,QAAA,IAAA,KAAA,IAAA,MAAA,QAAA,MAAA,EAAA;uBAEY,KAAI,OAAO,YAAY,IAAI,KAAK,OAAO,MAAM,EAAE,cAAa,SAAM,SAAA,KAAA,GAAA,OAAA,KAAA,UAAA,KAAA,EAAA;GAAA;GAAA;GAAA;GAAA,CAAA,CAAA;AAEtE,SAAO;;;GAGZ;CAAC;CAAO;CAAA;CAAA;CAAA;CAAA,CAAA,CAAA"}
1
+ {"version":3,"file":"helpers.mjs","names":[],"sources":["../../src/resolver/helpers.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { getUniqueBy } from \"@stryke/helpers/get-unique\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport { createDefu } from \"defu\";\nimport { getAppTitle } from \"../plugin-utils/context-helpers\";\nimport type { CommandArgument, CommandParameterKind } from \"../types/command\";\nimport { CommandParameterKinds } from \"../types/command\";\nimport type { Context } from \"../types/context\";\nimport type { ResolverContext } from \"./types\";\n\n/**\n * Resolves the description for a command option based on its reflection.\n *\n * @param name - The name of the command option.\n * @param kind - The reflection kind of the command option.\n * @param optional - Whether the command option is optional.\n * @param variadic - Whether the command option is variadic (i.e., an array).\n * @param title - The title of the command option, if any.\n * @param defaultValue - The default value of the command option, if any.\n * @returns The resolved description for the command option.\n */\nexport function resolveCommandOptionDescription(\n name: string,\n kind: CommandParameterKind,\n optional = false,\n variadic = false,\n title?: string,\n defaultValue?: any\n): string {\n return `A${optional && !defaultValue ? \"n optional\" : \"\"} command-line ${\n kind === CommandParameterKinds.boolean ? \"flag\" : \"option\"\n } that allows the user to ${\n kind === CommandParameterKinds.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === CommandParameterKinds.boolean\n ? \"indicator\"\n : `${kind === CommandParameterKinds.number ? \"numeric\" : \"string\"} value${\n variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\n/**\n * Resolves the description for a command argument based on its reflection.\n *\n * @param name - The name of the command argument.\n * @param kind - The reflection kind of the command argument.\n * @param optional - Whether the command argument is optional.\n * @param variadic - Whether the command argument is variadic (i.e., an array).\n * @param title - The title of the command argument, if any.\n * @param defaultValue - The default value of the command argument, if any.\n * @returns The resolved description for the command argument.\n */\nexport function resolveCommandArgumentDescription(\n name: string,\n kind: CommandParameterKind,\n optional = false,\n variadic = false,\n title?: string,\n defaultValue?: any\n): string {\n return `An${\n optional && !defaultValue ? \" optional\" : \"\"\n } argument that allows the user to ${\n kind === CommandParameterKinds.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === CommandParameterKinds.boolean\n ? \"indicator\"\n : `${kind === CommandParameterKinds.number ? \"numeric\" : \"string\"} value${\n variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\nexport function applyOptionsDefaults(ctx: ResolverContext) {\n return Object.fromEntries(\n Object.entries(ctx.output.options).map(([key, option]) => {\n const name = option.name || key;\n const title = option.title || titleCase(name);\n\n return [\n key,\n {\n ...option,\n name,\n title,\n description:\n option.description ||\n resolveCommandOptionDescription(\n name,\n option.kind,\n option.optional,\n option.kind !== CommandParameterKinds.boolean && option.variadic,\n title,\n option.default\n ),\n env:\n option.env || option.env === false\n ? option.env\n : ctx.input.context.config.autoAssignEnv\n ? constantCase(name)\n : false\n }\n ];\n })\n );\n}\n\nexport function applyArgsDefaults(ctx: ResolverContext): CommandArgument[] {\n return ctx.output.args.map((arg, i) => {\n const name = arg.name || `arg${i + 1}`;\n const title = arg.title || titleCase(name);\n\n return {\n ...arg,\n name,\n title,\n description:\n arg.description ||\n resolveCommandArgumentDescription(\n name,\n arg.kind,\n arg.optional,\n arg.kind !== CommandParameterKinds.boolean && arg.variadic,\n title,\n arg.default\n ),\n env: arg.name\n ? arg.env || arg.env === false\n ? arg.env\n : ctx.input.context.config.autoAssignEnv\n ? constantCase(name)\n : false\n : false\n };\n });\n}\n\nexport function applyDefaults(ctx: ResolverContext) {\n ctx.output.description ??= `The ${ctx.output.title.replace(/(?:c|C)ommands?$/, \"\").trim()} executable command-line interface.`;\n}\n\nexport function resolveVirtualCommand<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n) {\n ctx.output.title ??= titleCase(ctx.input.command.name);\n ctx.output.description ??= `A collection of available ${\n ctx.output.title.replace(/(?:c|C)ommands?$/, \"\").trim() ||\n titleCase(ctx.input.command.name)\n } commands that are included in the ${getAppTitle(\n ctx.input.context,\n true\n )} command-line application.`;\n}\n\n/**\n * Merges two command parameters, giving precedence to string values in the second configuration.\n *\n * @param objA - The first command parameter object.\n * @param objB - The second command parameter object.\n * @returns The merged command parameter object.\n */\nexport const mergeCommandParameter = createDefu((obj, key, value) => {\n if (isString(obj[key]) && isString(value)) {\n if (isSetString(value)) {\n obj[key] = value;\n }\n\n return true;\n } else if (Array.isArray(obj[key]) && Array.isArray(value)) {\n if (value.length > 0) {\n obj[key] = getUniqueBy((obj[key] as unknown[]).concat(value), item =>\n isString(item) ? item : JSON.stringify(item)\n ) as (typeof obj)[typeof key];\n }\n\n return true;\n }\n\n return false;\n});\n"],"mappings":";;;;;;;;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;;;;;;;;;;;;AAsCX,SAAE,gCAAA,MAAA,MAAA,WAAA,OAAA,WAAA,OAAA,OAAA,cAAA;AACE,QAAO,IAAI,YAAY,CAAC,eAAe,eAAI,GAAA,gBAAA,SAAA,sBAAA,UAAA,SAAA,SAAA,2BAAA,SAAA,sBAAA,UACrC,YACA,WACI,mBACA,mBAAI,GAAA,OAAA,MAAA,IAAA,UAAA,KAAA,CAAA,GAAA,SAAA,sBAAA,UACR,cACA,GAAG,SAAM,sBAAA,SAAA,YAAA,SAAA,QAAA,WAAA,MAAA,KAAA;;AAEnB,gCAAgC,SAAS;CAAC;CAAQ;CAAwB;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;;;;;AAY1E,SAAgB,kCAAY,MAAA,MAAA,WAAA,OAAA,WAAA,OAAA,OAAA,cAAA;AACxB,QAAK,KAAA,YAAA,CAAA,eAAA,cAAA,GAAA,oCAAA,SAAA,sBAAA,UACJ,YACL,8BAEE,mBAAA,GAAA,OAAA,MAAA,IAAA,UAAA,KAAA,CAAA,GAAA,SAAA,sBAAA,UACQ,cACT,GAAA,SAAA,sBAAA,SAAA,YAAA,SAAA,QAAA,WAAA,MAAA,KAAA;;AAED,kCAAkC,SAAS;CAAC;CAAQ;CAAQ;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;AAC5D,SAAgB,qBAAqB,KAAK;AACtC,QAAO,OAAO,YAAY,OAAO,QAAQ,IAAI,OAAO,QAAQ,CAAC,IAAI,cAA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AI,OAAO,gBAAgB,6BAA6B,IAAI,OAAO,MAAM,QAAC,oBAAA,GAAA,CAAA,MAAA,IACtE,UAAU,IAAC,MAAA,QAAA,KAAA,CAAA,qCAAA,YAAA,IAAA,MAAA,SAAA,KAAA,CAAA;;AAEnB,sBAAa,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;AAQb,MAAO,wBAAA,WAAA,cAAA,KAAA,KAAA,UAAA;AACH,KAAC,SAAA,IAAA,KAAA,IAAA,SAAA,MAAA,EAAA;AACF,MAAA,YAAA,MAAA,CACH,KAAA,OAAA;AAEQ,SAAO;YAEF,MAAM,QAAQ,IAAI,KAAK,IAAI,MAAE,QAAA,MAAA,EAAA;AAClC,MAAI,MAAM,SAAS;;;;;AAGnB,SAAI;;AAER,QAAO;GACR;CAAC;CAAO;CAAM;CAAA;CAAA;CAAA,CAAA,CAAA"}
@@ -89,7 +89,7 @@ async function resolveFromExports(ctx) {
89
89
  "param0",
90
90
  "",
91
91
  "P\"2!\"/\""
92
- ])));
92
+ ])).concat(Object.entries(ctx.output.options)));
93
93
  } else if (Object.values(ctx.module.options).every(require_type_checks.isCommandParameterConfig)) ctx.output.options = Object.fromEntries(Object.entries(ctx.module.options).map(__assignType(([name, option]) => [name, {
94
94
  name,
95
95
  ...option,
@@ -98,7 +98,7 @@ async function resolveFromExports(ctx) {
98
98
  "param0",
99
99
  "",
100
100
  "P\"2!\"/\""
101
- ])));
101
+ ])).concat(Object.entries(ctx.output.options)));
102
102
  else throw new TypeError(`Command options for command at path "${ctx.input.command.path}" must be defined as a record of valid CommandOption objects, a Zod object schema, or a standard JSON Schema object.`);
103
103
  if ((0, __stryke_type_checks_is_set_object.isSetObject)(ctx.module?.args)) if ((0, __stryke_zod.isZod3Type)(ctx.module.args) || (0, __stryke_json.isStandardJsonSchema)(ctx.module.args) || (0, __stryke_json.isJsonSchema7TupleType)(ctx.module.args)) {
104
104
  let jsonSchema;
@@ -1 +1 @@
1
- {"version":3,"file":"module.cjs","names":[],"sources":["../../src/resolver/module.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { toArray } from \"@stryke/convert/to-array\";\nimport type {\n JsonSchema7EnumType,\n JsonSchema7ObjectType,\n JsonSchema7Type\n} from \"@stryke/json\";\nimport {\n isJsonSchema7ArrayType,\n isJsonSchema7BooleanType,\n isJsonSchema7NumberType,\n isJsonSchema7ObjectType,\n isJsonSchema7StringType,\n isJsonSchema7TupleType,\n isStandardJsonSchema\n} from \"@stryke/json\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { extractJsonSchema7, isZod3Type } from \"@stryke/zod\";\nimport { isCommandParameterConfig } from \"../plugin-utils\";\nimport type {\n CommandArgument,\n CommandOption,\n CommandParameterConfig,\n Context,\n StringCommandParameter\n} from \"../types\";\nimport { CommandParameterKinds } from \"../types\";\nimport type { ResolverContext } from \"./types\";\n\nfunction resolveCommandOption(\n name: string,\n parent: JsonSchema7ObjectType,\n schema: JsonSchema7Type\n): Partial<CommandOption> {\n const result = {\n name,\n kind:\n isJsonSchema7ArrayType(schema) && schema.items\n ? isJsonSchema7NumberType(schema.items)\n ? CommandParameterKinds.number\n : CommandParameterKinds.string\n : isJsonSchema7BooleanType(schema)\n ? CommandParameterKinds.boolean\n : isJsonSchema7NumberType(schema)\n ? CommandParameterKinds.number\n : CommandParameterKinds.string,\n title: schema.title,\n description: schema.description,\n alias: toArray((schema as { alias?: string | string[] }).alias || []),\n env: (schema as { env?: string }).env,\n optional: !parent.required?.includes(name),\n default: schema.default\n } as Partial<CommandOption>;\n if (\n result.kind === CommandParameterKinds.string ||\n result.kind === CommandParameterKinds.number\n ) {\n result.variadic = isJsonSchema7ArrayType(schema);\n if (result.kind === CommandParameterKinds.string) {\n result.format = (\n schema as { format?: StringCommandParameter[\"format\"] }\n ).format;\n }\n\n if (\n (isJsonSchema7StringType(schema) || isJsonSchema7NumberType(schema)) &&\n (schema as JsonSchema7EnumType).enum\n ) {\n result.choices = (schema as JsonSchema7EnumType).enum;\n }\n } else if (result.kind === CommandParameterKinds.boolean) {\n result.skipAddingNegative = (\n schema as { skipAddingNegative?: boolean }\n ).skipAddingNegative;\n result.isNegativeOf = (schema as { isNegativeOf?: string }).isNegativeOf;\n }\n\n return result;\n}\n\nfunction resolveCommandArgument(\n schema: JsonSchema7Type\n): Partial<CommandArgument> {\n const result = {\n name: (schema as { name?: string }).name,\n kind:\n isJsonSchema7ArrayType(schema) && schema.items\n ? isJsonSchema7NumberType(schema.items)\n ? CommandParameterKinds.number\n : CommandParameterKinds.string\n : isJsonSchema7BooleanType(schema)\n ? CommandParameterKinds.boolean\n : isJsonSchema7NumberType(schema)\n ? CommandParameterKinds.number\n : CommandParameterKinds.string,\n title: schema.title,\n description: schema.description,\n alias: toArray((schema as { alias?: string | string[] }).alias || []),\n env: (schema as { env?: string }).env,\n default: schema.default\n } as Partial<CommandArgument>;\n if (\n result.kind === CommandParameterKinds.string ||\n result.kind === CommandParameterKinds.number\n ) {\n result.variadic = isJsonSchema7ArrayType(schema);\n if (result.kind === CommandParameterKinds.string) {\n result.format = (\n schema as { format?: StringCommandParameter[\"format\"] }\n ).format;\n }\n\n if (\n (isJsonSchema7StringType(schema) || isJsonSchema7NumberType(schema)) &&\n (schema as JsonSchema7EnumType).enum\n ) {\n result.choices = (schema as JsonSchema7EnumType).enum;\n }\n }\n\n return result;\n}\n\nexport async function resolveFromExports<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n) {\n validateExports(ctx);\n\n const metadata = ctx.module?.metadata ?? {};\n if (isSetString(metadata.title)) {\n ctx.output.title = metadata.title;\n }\n if (isSetString(metadata.description)) {\n ctx.output.description = metadata.description;\n }\n if (\n isSetString(metadata.alias) ||\n (Array.isArray(metadata.alias) && metadata.alias.length > 0)\n ) {\n ctx.output.alias = toArray(metadata.alias);\n }\n if (isSetString(metadata.icon)) {\n ctx.output.icon = metadata.icon;\n }\n\n if (isSetObject(ctx.module?.options)) {\n if (\n isZod3Type(ctx.module.options) ||\n isStandardJsonSchema(ctx.module.options) ||\n isJsonSchema7ObjectType(ctx.module.options)\n ) {\n let jsonSchema: JsonSchema7Type;\n if (isZod3Type(ctx.module.options)) {\n jsonSchema = extractJsonSchema7(ctx.module.options);\n } else if (isStandardJsonSchema(ctx.module.options)) {\n jsonSchema = ctx.module.options[\"~standard\"].jsonSchema.input({\n target: \"draft-07\"\n });\n } else {\n jsonSchema = ctx.module.options as JsonSchema7ObjectType;\n }\n\n if (!isJsonSchema7ObjectType(jsonSchema)) {\n throw new TypeError(\n `Command options for command at path \"${\n ctx.input.command.path\n }\" must be defined as a Zod object schema, a standard JSON Schema object, or a JSON Schema object.`\n );\n }\n\n ctx.output.options = Object.fromEntries(\n Object.entries((jsonSchema as JsonSchema7ObjectType).properties).map(\n ([name, property]) => [\n name,\n resolveCommandOption(name, jsonSchema, property)\n ]\n )\n ) as Record<string, CommandOption>;\n } else if (\n Object.values(ctx.module.options).every(isCommandParameterConfig)\n ) {\n ctx.output.options = Object.fromEntries(\n Object.entries(\n ctx.module.options as Record<string, CommandParameterConfig>\n ).map(([name, option]) => [\n name,\n { name, ...option, alias: toArray(option.alias) }\n ])\n ) as Record<string, CommandOption>;\n } else {\n throw new TypeError(\n `Command options for command at path \"${\n ctx.input.command.path\n }\" must be defined as a record of valid CommandOption objects, a Zod object schema, or a standard JSON Schema object.`\n );\n }\n }\n\n if (isSetObject(ctx.module?.args)) {\n if (\n isZod3Type(ctx.module.args) ||\n isStandardJsonSchema(ctx.module.args) ||\n isJsonSchema7TupleType(ctx.module.args)\n ) {\n let jsonSchema: JsonSchema7Type;\n if (isZod3Type(ctx.module.args)) {\n jsonSchema = extractJsonSchema7(ctx.module.args);\n } else if (isStandardJsonSchema(ctx.module.args)) {\n jsonSchema = ctx.module.args[\"~standard\"].jsonSchema.input({\n target: \"draft-07\"\n });\n } else {\n jsonSchema = ctx.module.args;\n }\n\n if (!isJsonSchema7TupleType(jsonSchema)) {\n throw new TypeError(\n `Command arguments for command at path \"${\n ctx.input.command.path\n }\" must be defined as a Zod tuple schema, a standard JSON Schema tuple object, or a JSON Schema tuple object.`\n );\n }\n\n ctx.output.args = jsonSchema.items.map(item =>\n resolveCommandArgument(item)\n ) as CommandArgument[];\n } else if (Object.values(ctx.module.args).every(isCommandParameterConfig)) {\n ctx.output.args = ctx.module.args.map(arg => ({\n ...arg,\n alias: toArray(arg.alias)\n })) as CommandArgument[];\n } else {\n throw new TypeError(\n `Command arguments for command at path \"${\n ctx.input.command.path\n }\" must be defined as a record of valid CommandArgument objects, a Zod tuple schema, or a standard JSON Schema tuple object.`\n );\n }\n }\n}\n\nfunction validateExports<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n) {\n if (!ctx.module) {\n throw new Error(\n `Command module at path \"${\n ctx.input.command.path\n }\" is undefined or null. Please ensure the module exports a valid command.`\n );\n } else if (!isSetObject(ctx.module)) {\n throw new TypeError(\n `Command module at path \"${\n ctx.input.command.path\n }\" is not an object. Please ensure the module exports a valid command.`\n );\n } else if (!(\"default\" in ctx.module)) {\n throw new Error(\n `Command module at path \"${\n ctx.input.command.path\n }\" does not appear to be valid. Please ensure the module's default export is a valid command handler function.`\n );\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA,MAAM,aAAa;CAAC;CAAK;CAAW;CAA2B;;AAE3D,IAAG,SAAS;;;AA2BhB,SAAS,qBAAgB,MAAA,QAAA,QAAA;CACrB,MAAM,SAAS;EACX;EACA,gDAAa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kCAAA,IAAA,OAAA,KAAA,4CAC+B,IAAI,OAAI,KAAA,8CACN,IAAI,OAAO,KAAG,EAAA;EAC/C,IAAA;AACG,mCAAA,IAAA,OAAA,KAAA,CACW,mDAAiB,IAAA,OAAA,KAAA;mDAE7B,IAAA,OAAA,KAAA,CACY,cAAa,IAAI,OAAO,KAAK,aAAC,WAAA,MAAA,EAC5C,QAAA,YACe,CAAC;;AAKX,MAAA,2CAAA,WAAA,CACS,OAAM,IAAI,UAAU,0CAAE,IAAA,MAAA,QAAA,KAAA,8GAAA;AAE1B,MAAI,OAAO,OAAO,WAAW,MAAM,IAAC,cAAA,SAAA,uBAAA,KAAA,EAAA;GAAA;GAAA;GAAA;GAAA,CAAA,CAAA;YAE/B,OAAO,OAAO,IAAI,OAAE,KAAA,CAAA,MAAA,6CAAA,CACzB,KAAI,OAAO,OAAO,IAAI,OAAO,KAAC,IAAA,cAAA,SAAA;EAC1B,GAAG;EACH,8CAAe,IAAI,MAAK;EAC3B,GAAG;EAAC;EAAO;EAAI;EAAU,CAAC,CAAC;KAG5B,OAAC,IAAA,UAAA,0CAAA,IAAA,MAAA,QAAA,KAAA,6HAAA;;AAIb,mBAAmB,SAAS;CAAC;CAAmB;CAAA;CAAA;CAAA;AAChD,SAAS,gBAAgB,KAAE;AACvB,KAAI,CAAC,IAAI,OACL,OAAM,IAAI,MAAM,2BAAS,IAAA,MAAA,QAAA,KAAA,2EAAA;UAExB,qDAAA,IAAA,OAAA,CACH,OAAA,IAAA,UAAA,2BAAA,IAAA,MAAA,QAAA,KAAA,uEAAA;UAEO,EAAE,aAAa,IAAI,QACxB,OAAM,IAAI,MAAM,2BAA2B,IAAI,MAAM,QAAQ,KAAI,+GAAG;;AAG5E,gBAAgB,SAAS;CAAC;CAAmB;CAAO;CAAO;CAAA"}
1
+ {"version":3,"file":"module.cjs","names":[],"sources":["../../src/resolver/module.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { toArray } from \"@stryke/convert/to-array\";\nimport type {\n JsonSchema7EnumType,\n JsonSchema7ObjectType,\n JsonSchema7Type\n} from \"@stryke/json\";\nimport {\n isJsonSchema7ArrayType,\n isJsonSchema7BooleanType,\n isJsonSchema7NumberType,\n isJsonSchema7ObjectType,\n isJsonSchema7StringType,\n isJsonSchema7TupleType,\n isStandardJsonSchema\n} from \"@stryke/json\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { extractJsonSchema7, isZod3Type } from \"@stryke/zod\";\nimport { isCommandParameterConfig } from \"../plugin-utils\";\nimport type {\n CommandArgument,\n CommandOption,\n CommandParameterConfig,\n Context,\n StringCommandParameter\n} from \"../types\";\nimport { CommandParameterKinds } from \"../types\";\nimport type { ResolverContext } from \"./types\";\n\nfunction resolveCommandOption(\n name: string,\n parent: JsonSchema7ObjectType,\n schema: JsonSchema7Type\n): Partial<CommandOption> {\n const result = {\n name,\n kind:\n isJsonSchema7ArrayType(schema) && schema.items\n ? isJsonSchema7NumberType(schema.items)\n ? CommandParameterKinds.number\n : CommandParameterKinds.string\n : isJsonSchema7BooleanType(schema)\n ? CommandParameterKinds.boolean\n : isJsonSchema7NumberType(schema)\n ? CommandParameterKinds.number\n : CommandParameterKinds.string,\n title: schema.title,\n description: schema.description,\n alias: toArray((schema as { alias?: string | string[] }).alias || []),\n env: (schema as { env?: string }).env,\n optional: !parent.required?.includes(name),\n default: schema.default\n } as Partial<CommandOption>;\n if (\n result.kind === CommandParameterKinds.string ||\n result.kind === CommandParameterKinds.number\n ) {\n result.variadic = isJsonSchema7ArrayType(schema);\n if (result.kind === CommandParameterKinds.string) {\n result.format = (\n schema as { format?: StringCommandParameter[\"format\"] }\n ).format;\n }\n\n if (\n (isJsonSchema7StringType(schema) || isJsonSchema7NumberType(schema)) &&\n (schema as JsonSchema7EnumType).enum\n ) {\n result.choices = (schema as JsonSchema7EnumType).enum;\n }\n } else if (result.kind === CommandParameterKinds.boolean) {\n result.skipAddingNegative = (\n schema as { skipAddingNegative?: boolean }\n ).skipAddingNegative;\n result.isNegativeOf = (schema as { isNegativeOf?: string }).isNegativeOf;\n }\n\n return result;\n}\n\nfunction resolveCommandArgument(\n schema: JsonSchema7Type\n): Partial<CommandArgument> {\n const result = {\n name: (schema as { name?: string }).name,\n kind:\n isJsonSchema7ArrayType(schema) && schema.items\n ? isJsonSchema7NumberType(schema.items)\n ? CommandParameterKinds.number\n : CommandParameterKinds.string\n : isJsonSchema7BooleanType(schema)\n ? CommandParameterKinds.boolean\n : isJsonSchema7NumberType(schema)\n ? CommandParameterKinds.number\n : CommandParameterKinds.string,\n title: schema.title,\n description: schema.description,\n alias: toArray((schema as { alias?: string | string[] }).alias || []),\n env: (schema as { env?: string }).env,\n default: schema.default\n } as Partial<CommandArgument>;\n if (\n result.kind === CommandParameterKinds.string ||\n result.kind === CommandParameterKinds.number\n ) {\n result.variadic = isJsonSchema7ArrayType(schema);\n if (result.kind === CommandParameterKinds.string) {\n result.format = (\n schema as { format?: StringCommandParameter[\"format\"] }\n ).format;\n }\n\n if (\n (isJsonSchema7StringType(schema) || isJsonSchema7NumberType(schema)) &&\n (schema as JsonSchema7EnumType).enum\n ) {\n result.choices = (schema as JsonSchema7EnumType).enum;\n }\n }\n\n return result;\n}\n\nexport async function resolveFromExports<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n) {\n validateExports(ctx);\n\n const metadata = ctx.module?.metadata ?? {};\n if (isSetString(metadata.title)) {\n ctx.output.title = metadata.title;\n }\n if (isSetString(metadata.description)) {\n ctx.output.description = metadata.description;\n }\n if (\n isSetString(metadata.alias) ||\n (Array.isArray(metadata.alias) && metadata.alias.length > 0)\n ) {\n ctx.output.alias = toArray(metadata.alias);\n }\n if (isSetString(metadata.icon)) {\n ctx.output.icon = metadata.icon;\n }\n\n if (isSetObject(ctx.module?.options)) {\n if (\n isZod3Type(ctx.module.options) ||\n isStandardJsonSchema(ctx.module.options) ||\n isJsonSchema7ObjectType(ctx.module.options)\n ) {\n let jsonSchema: JsonSchema7Type;\n if (isZod3Type(ctx.module.options)) {\n jsonSchema = extractJsonSchema7(ctx.module.options);\n } else if (isStandardJsonSchema(ctx.module.options)) {\n jsonSchema = ctx.module.options[\"~standard\"].jsonSchema.input({\n target: \"draft-07\"\n });\n } else {\n jsonSchema = ctx.module.options as JsonSchema7ObjectType;\n }\n\n if (!isJsonSchema7ObjectType(jsonSchema)) {\n throw new TypeError(\n `Command options for command at path \"${\n ctx.input.command.path\n }\" must be defined as a Zod object schema, a standard JSON Schema object, or a JSON Schema object.`\n );\n }\n\n ctx.output.options = Object.fromEntries(\n Object.entries((jsonSchema as JsonSchema7ObjectType).properties)\n .map(([name, property]) => [\n name,\n resolveCommandOption(name, jsonSchema, property)\n ])\n .concat(Object.entries(ctx.output.options))\n ) as Record<string, CommandOption>;\n } else if (\n Object.values(ctx.module.options).every(isCommandParameterConfig)\n ) {\n ctx.output.options = Object.fromEntries(\n Object.entries(\n ctx.module.options as Record<string, CommandParameterConfig>\n )\n .map(([name, option]) => [\n name,\n { name, ...option, alias: toArray(option.alias) }\n ])\n .concat(Object.entries(ctx.output.options))\n ) as Record<string, CommandOption>;\n } else {\n throw new TypeError(\n `Command options for command at path \"${\n ctx.input.command.path\n }\" must be defined as a record of valid CommandOption objects, a Zod object schema, or a standard JSON Schema object.`\n );\n }\n }\n\n if (isSetObject(ctx.module?.args)) {\n if (\n isZod3Type(ctx.module.args) ||\n isStandardJsonSchema(ctx.module.args) ||\n isJsonSchema7TupleType(ctx.module.args)\n ) {\n let jsonSchema: JsonSchema7Type;\n if (isZod3Type(ctx.module.args)) {\n jsonSchema = extractJsonSchema7(ctx.module.args);\n } else if (isStandardJsonSchema(ctx.module.args)) {\n jsonSchema = ctx.module.args[\"~standard\"].jsonSchema.input({\n target: \"draft-07\"\n });\n } else {\n jsonSchema = ctx.module.args;\n }\n\n if (!isJsonSchema7TupleType(jsonSchema)) {\n throw new TypeError(\n `Command arguments for command at path \"${\n ctx.input.command.path\n }\" must be defined as a Zod tuple schema, a standard JSON Schema tuple object, or a JSON Schema tuple object.`\n );\n }\n\n ctx.output.args = jsonSchema.items.map(item =>\n resolveCommandArgument(item)\n ) as CommandArgument[];\n } else if (Object.values(ctx.module.args).every(isCommandParameterConfig)) {\n ctx.output.args = ctx.module.args.map(arg => ({\n ...arg,\n alias: toArray(arg.alias)\n })) as CommandArgument[];\n } else {\n throw new TypeError(\n `Command arguments for command at path \"${\n ctx.input.command.path\n }\" must be defined as a record of valid CommandArgument objects, a Zod tuple schema, or a standard JSON Schema tuple object.`\n );\n }\n }\n}\n\nfunction validateExports<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n) {\n if (!ctx.module) {\n throw new Error(\n `Command module at path \"${\n ctx.input.command.path\n }\" is undefined or null. Please ensure the module exports a valid command.`\n );\n } else if (!isSetObject(ctx.module)) {\n throw new TypeError(\n `Command module at path \"${\n ctx.input.command.path\n }\" is not an object. Please ensure the module exports a valid command.`\n );\n } else if (!(\"default\" in ctx.module)) {\n throw new Error(\n `Command module at path \"${\n ctx.input.command.path\n }\" does not appear to be valid. Please ensure the module's default export is a valid command handler function.`\n );\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA,MAAM,aAAa;CAAC;CAAK;CAAW;CAA2B;;AAE3D,IAAG,SAAS;;;AA2BhB,SAAS,qBAAgB,MAAA,QAAA,QAAA;CACrB,MAAM,SAAS;EACX;EACA,gDAAa,OAAA,IAAA,OAAA,mDACiB,OAAO,MAAM,GACjC,4C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AC4B,IAAA,OAAA,KAAA,8CACE,IAAI,OAAO,KAAK,EAAE;EACjD,IAAA;AACQ,mCAAe,IAAI,OAAO,KAAK,CACzC,mDAAA,IAAA,OAAA,KAAA;mDAEiC,IAAA,OAAA,KAAA,CACjC,cAAA,IAAA,OAAA,KAAA,aAAA,WAAA,MAAA,sBAEe,CAAC;MAGF,cAAa,IAAI,OAAO;AAElC,MAAA,2CAAA,WAAA,CACU,OAAM,IAAI,UAAU,0CAAC,IAAA,MAAA,QAAA,KAAA,8GAAA;AAEzB,MAAI,OAAO,OAAO,WAAW,MAAM,IAAI,cAAQ,SAAA,uBAAA,KAAA,EAAA;GAAA;GAAA;GAAA;GAAA,CAAA,CAAA;YAE1C,OAAO,OAAO,IAAI,OAAO,KAAK,CAAC,MAAM,6CAAgB,CAC1D,KAAI,OAAO,OAAI,IAAA,OAAA,KAAA,IAAA,cAAA,SAAA;EACjB,GAAA;EACG,8CAAA,IAAA,MAAA;EACA,GAAG;EAAC;EAAO;EAAI;EAAU,CAAC,CAAC;KAG5B,OAAM,IAAI,UAAU,0CAAgB,IAAA,MAAA,QAAA,KAAA,6HAAA;;AAIhD,mBAAmB,SAAS;CAAC;CAAmB;CAAO;CAAsB;CAAY;AACzF,SAAS,gBAAA,KAAA;AACL,KAAE,CAAA,IAAA;UAGO,qDAAa,IAAI,OAAO,CAC7B,OAAM,IAAI,UAAU,2BAAS,IAAA,MAAA,QAAA,KAAA,uEAAA;UAExB,EAAE,aAAa,IAAI,QACxB,OAAG,IAAA,MAAA,2BAAA,IAAA,MAAA,QAAA,KAAA,+GAAA;;AAGX,gBAAc,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA"}
@@ -88,7 +88,7 @@ async function resolveFromExports(ctx) {
88
88
  "param0",
89
89
  "",
90
90
  "P\"2!\"/\""
91
- ])));
91
+ ])).concat(Object.entries(ctx.output.options)));
92
92
  } else if (Object.values(ctx.module.options).every(isCommandParameterConfig)) ctx.output.options = Object.fromEntries(Object.entries(ctx.module.options).map(__assignType(([name, option]) => [name, {
93
93
  name,
94
94
  ...option,
@@ -97,7 +97,7 @@ async function resolveFromExports(ctx) {
97
97
  "param0",
98
98
  "",
99
99
  "P\"2!\"/\""
100
- ])));
100
+ ])).concat(Object.entries(ctx.output.options)));
101
101
  else throw new TypeError(`Command options for command at path "${ctx.input.command.path}" must be defined as a record of valid CommandOption objects, a Zod object schema, or a standard JSON Schema object.`);
102
102
  if (isSetObject(ctx.module?.args)) if (isZod3Type(ctx.module.args) || isStandardJsonSchema(ctx.module.args) || isJsonSchema7TupleType(ctx.module.args)) {
103
103
  let jsonSchema;
@@ -1 +1 @@
1
- {"version":3,"file":"module.mjs","names":[],"sources":["../../src/resolver/module.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { toArray } from \"@stryke/convert/to-array\";\nimport type {\n JsonSchema7EnumType,\n JsonSchema7ObjectType,\n JsonSchema7Type\n} from \"@stryke/json\";\nimport {\n isJsonSchema7ArrayType,\n isJsonSchema7BooleanType,\n isJsonSchema7NumberType,\n isJsonSchema7ObjectType,\n isJsonSchema7StringType,\n isJsonSchema7TupleType,\n isStandardJsonSchema\n} from \"@stryke/json\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { extractJsonSchema7, isZod3Type } from \"@stryke/zod\";\nimport { isCommandParameterConfig } from \"../plugin-utils\";\nimport type {\n CommandArgument,\n CommandOption,\n CommandParameterConfig,\n Context,\n StringCommandParameter\n} from \"../types\";\nimport { CommandParameterKinds } from \"../types\";\nimport type { ResolverContext } from \"./types\";\n\nfunction resolveCommandOption(\n name: string,\n parent: JsonSchema7ObjectType,\n schema: JsonSchema7Type\n): Partial<CommandOption> {\n const result = {\n name,\n kind:\n isJsonSchema7ArrayType(schema) && schema.items\n ? isJsonSchema7NumberType(schema.items)\n ? CommandParameterKinds.number\n : CommandParameterKinds.string\n : isJsonSchema7BooleanType(schema)\n ? CommandParameterKinds.boolean\n : isJsonSchema7NumberType(schema)\n ? CommandParameterKinds.number\n : CommandParameterKinds.string,\n title: schema.title,\n description: schema.description,\n alias: toArray((schema as { alias?: string | string[] }).alias || []),\n env: (schema as { env?: string }).env,\n optional: !parent.required?.includes(name),\n default: schema.default\n } as Partial<CommandOption>;\n if (\n result.kind === CommandParameterKinds.string ||\n result.kind === CommandParameterKinds.number\n ) {\n result.variadic = isJsonSchema7ArrayType(schema);\n if (result.kind === CommandParameterKinds.string) {\n result.format = (\n schema as { format?: StringCommandParameter[\"format\"] }\n ).format;\n }\n\n if (\n (isJsonSchema7StringType(schema) || isJsonSchema7NumberType(schema)) &&\n (schema as JsonSchema7EnumType).enum\n ) {\n result.choices = (schema as JsonSchema7EnumType).enum;\n }\n } else if (result.kind === CommandParameterKinds.boolean) {\n result.skipAddingNegative = (\n schema as { skipAddingNegative?: boolean }\n ).skipAddingNegative;\n result.isNegativeOf = (schema as { isNegativeOf?: string }).isNegativeOf;\n }\n\n return result;\n}\n\nfunction resolveCommandArgument(\n schema: JsonSchema7Type\n): Partial<CommandArgument> {\n const result = {\n name: (schema as { name?: string }).name,\n kind:\n isJsonSchema7ArrayType(schema) && schema.items\n ? isJsonSchema7NumberType(schema.items)\n ? CommandParameterKinds.number\n : CommandParameterKinds.string\n : isJsonSchema7BooleanType(schema)\n ? CommandParameterKinds.boolean\n : isJsonSchema7NumberType(schema)\n ? CommandParameterKinds.number\n : CommandParameterKinds.string,\n title: schema.title,\n description: schema.description,\n alias: toArray((schema as { alias?: string | string[] }).alias || []),\n env: (schema as { env?: string }).env,\n default: schema.default\n } as Partial<CommandArgument>;\n if (\n result.kind === CommandParameterKinds.string ||\n result.kind === CommandParameterKinds.number\n ) {\n result.variadic = isJsonSchema7ArrayType(schema);\n if (result.kind === CommandParameterKinds.string) {\n result.format = (\n schema as { format?: StringCommandParameter[\"format\"] }\n ).format;\n }\n\n if (\n (isJsonSchema7StringType(schema) || isJsonSchema7NumberType(schema)) &&\n (schema as JsonSchema7EnumType).enum\n ) {\n result.choices = (schema as JsonSchema7EnumType).enum;\n }\n }\n\n return result;\n}\n\nexport async function resolveFromExports<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n) {\n validateExports(ctx);\n\n const metadata = ctx.module?.metadata ?? {};\n if (isSetString(metadata.title)) {\n ctx.output.title = metadata.title;\n }\n if (isSetString(metadata.description)) {\n ctx.output.description = metadata.description;\n }\n if (\n isSetString(metadata.alias) ||\n (Array.isArray(metadata.alias) && metadata.alias.length > 0)\n ) {\n ctx.output.alias = toArray(metadata.alias);\n }\n if (isSetString(metadata.icon)) {\n ctx.output.icon = metadata.icon;\n }\n\n if (isSetObject(ctx.module?.options)) {\n if (\n isZod3Type(ctx.module.options) ||\n isStandardJsonSchema(ctx.module.options) ||\n isJsonSchema7ObjectType(ctx.module.options)\n ) {\n let jsonSchema: JsonSchema7Type;\n if (isZod3Type(ctx.module.options)) {\n jsonSchema = extractJsonSchema7(ctx.module.options);\n } else if (isStandardJsonSchema(ctx.module.options)) {\n jsonSchema = ctx.module.options[\"~standard\"].jsonSchema.input({\n target: \"draft-07\"\n });\n } else {\n jsonSchema = ctx.module.options as JsonSchema7ObjectType;\n }\n\n if (!isJsonSchema7ObjectType(jsonSchema)) {\n throw new TypeError(\n `Command options for command at path \"${\n ctx.input.command.path\n }\" must be defined as a Zod object schema, a standard JSON Schema object, or a JSON Schema object.`\n );\n }\n\n ctx.output.options = Object.fromEntries(\n Object.entries((jsonSchema as JsonSchema7ObjectType).properties).map(\n ([name, property]) => [\n name,\n resolveCommandOption(name, jsonSchema, property)\n ]\n )\n ) as Record<string, CommandOption>;\n } else if (\n Object.values(ctx.module.options).every(isCommandParameterConfig)\n ) {\n ctx.output.options = Object.fromEntries(\n Object.entries(\n ctx.module.options as Record<string, CommandParameterConfig>\n ).map(([name, option]) => [\n name,\n { name, ...option, alias: toArray(option.alias) }\n ])\n ) as Record<string, CommandOption>;\n } else {\n throw new TypeError(\n `Command options for command at path \"${\n ctx.input.command.path\n }\" must be defined as a record of valid CommandOption objects, a Zod object schema, or a standard JSON Schema object.`\n );\n }\n }\n\n if (isSetObject(ctx.module?.args)) {\n if (\n isZod3Type(ctx.module.args) ||\n isStandardJsonSchema(ctx.module.args) ||\n isJsonSchema7TupleType(ctx.module.args)\n ) {\n let jsonSchema: JsonSchema7Type;\n if (isZod3Type(ctx.module.args)) {\n jsonSchema = extractJsonSchema7(ctx.module.args);\n } else if (isStandardJsonSchema(ctx.module.args)) {\n jsonSchema = ctx.module.args[\"~standard\"].jsonSchema.input({\n target: \"draft-07\"\n });\n } else {\n jsonSchema = ctx.module.args;\n }\n\n if (!isJsonSchema7TupleType(jsonSchema)) {\n throw new TypeError(\n `Command arguments for command at path \"${\n ctx.input.command.path\n }\" must be defined as a Zod tuple schema, a standard JSON Schema tuple object, or a JSON Schema tuple object.`\n );\n }\n\n ctx.output.args = jsonSchema.items.map(item =>\n resolveCommandArgument(item)\n ) as CommandArgument[];\n } else if (Object.values(ctx.module.args).every(isCommandParameterConfig)) {\n ctx.output.args = ctx.module.args.map(arg => ({\n ...arg,\n alias: toArray(arg.alias)\n })) as CommandArgument[];\n } else {\n throw new TypeError(\n `Command arguments for command at path \"${\n ctx.input.command.path\n }\" must be defined as a record of valid CommandArgument objects, a Zod tuple schema, or a standard JSON Schema tuple object.`\n );\n }\n }\n}\n\nfunction validateExports<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n) {\n if (!ctx.module) {\n throw new Error(\n `Command module at path \"${\n ctx.input.command.path\n }\" is undefined or null. Please ensure the module exports a valid command.`\n );\n } else if (!isSetObject(ctx.module)) {\n throw new TypeError(\n `Command module at path \"${\n ctx.input.command.path\n }\" is not an object. Please ensure the module exports a valid command.`\n );\n } else if (!(\"default\" in ctx.module)) {\n throw new Error(\n `Command module at path \"${\n ctx.input.command.path\n }\" does not appear to be valid. Please ensure the module's default export is a valid command handler function.`\n );\n }\n}\n"],"mappings":";;;;;;;;;;AAAA,MAAM,aAAa;CAAC;CAAK;CAAW;CAA2B;;AAE3D,IAAG,SAAS;;;AA2BhB,SAAS,qBAAgB,MAAA,QAAA,QAAA;CACrB,MAAM,SAAS;EACX;EACA,MAAM,uBAAO,OAAA,IAAA,OAAA,QACP,wBAAwB,OAAO,MAAM,GACjC,sBAAsB,SACtB,sBAAsB,SAC1B,yBAAyB,OAAO,GAClC,sBAAA,UACK,wBAAA,OAAA,GACF,sBAAA,SACO,sBAAE;EAChB,OAAC,OAAA;EACD,aAAa,OAAE;EACf,OAAO,QAAE,OAAA,SAAA,EAAA,CAAA;EACT,KAAK,OAAO;EACZ,UAAU,CAAC,OAAO,UAAU,SAAS,KAAC;;EAEzC;AACD,KAAI,OAAM,SAAA,sBAAA,UACN,OAAO,SAAS,sBAAO,QAAA;AACvB,SAAO,WAAS,uBAAA,OAAA;AAChB,MAAI,OAAO,SAAO,sBAAA,OACd,QAAK,SAAA,OAAA;AAET,OAAA,wBAAA,OAAA,IAAA,wBAAA,OAAA,KACI,OAAO,KACP,QAAO,UAAU,OAAO;YAGvB,OAAO,SAAS,sBAAY,SAAA;AACjC,SAAO,qBAAqB,OAAI;AAChC,SAAO,eAAe,OAAO;;AAEjC,QAAO;;AAEX,qBAAqB,SAAS;CAAC;CAAI;CAAA;OAAA;CAAA;CAAA;CAAA;CAAA;AACnC,SAAS,uBAAuB,QAAQ;CACpC,MAAM,SAAS;EACX,MAAM,OAAO;EACb,MAAM,uBAAY,OAAA,IAAA,OAAA,QACZ,wBAAe,OAAA,MAAA,GAC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QAAQ,IAAI,MAAK;EAC3B,GAAG;EAAC;EAAO;EAAI;EAAU,CAAC,CAAC;KAG5B,OAAC,IAAA,UAAA,0CAAA,IAAA,MAAA,QAAA,KAAA,6HAAA;;AAIb,mBAAmB,SAAS;CAAC;CAAmB;CAAA;CAAA;CAAA;AAChD,SAAS,gBAAgB,KAAE;AACvB,KAAI,CAAC,IAAI,OACL,OAAM,IAAI,MAAM,2BAAS,IAAA,MAAA,QAAA,KAAA,2EAAA;UAExB,CAAA,YAAA,IAAA,OAAA,CACH,OAAA,IAAA,UAAA,2BAAA,IAAA,MAAA,QAAA,KAAA,uEAAA;UAEO,EAAE,aAAa,IAAI,QACxB,OAAM,IAAI,MAAM,2BAA2B,IAAI,MAAM,QAAQ,KAAI,+GAAG;;AAG5E,gBAAgB,SAAS;CAAC;CAAmB;CAAO;CAAO;CAAA"}
1
+ {"version":3,"file":"module.mjs","names":[],"sources":["../../src/resolver/module.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { toArray } from \"@stryke/convert/to-array\";\nimport type {\n JsonSchema7EnumType,\n JsonSchema7ObjectType,\n JsonSchema7Type\n} from \"@stryke/json\";\nimport {\n isJsonSchema7ArrayType,\n isJsonSchema7BooleanType,\n isJsonSchema7NumberType,\n isJsonSchema7ObjectType,\n isJsonSchema7StringType,\n isJsonSchema7TupleType,\n isStandardJsonSchema\n} from \"@stryke/json\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { extractJsonSchema7, isZod3Type } from \"@stryke/zod\";\nimport { isCommandParameterConfig } from \"../plugin-utils\";\nimport type {\n CommandArgument,\n CommandOption,\n CommandParameterConfig,\n Context,\n StringCommandParameter\n} from \"../types\";\nimport { CommandParameterKinds } from \"../types\";\nimport type { ResolverContext } from \"./types\";\n\nfunction resolveCommandOption(\n name: string,\n parent: JsonSchema7ObjectType,\n schema: JsonSchema7Type\n): Partial<CommandOption> {\n const result = {\n name,\n kind:\n isJsonSchema7ArrayType(schema) && schema.items\n ? isJsonSchema7NumberType(schema.items)\n ? CommandParameterKinds.number\n : CommandParameterKinds.string\n : isJsonSchema7BooleanType(schema)\n ? CommandParameterKinds.boolean\n : isJsonSchema7NumberType(schema)\n ? CommandParameterKinds.number\n : CommandParameterKinds.string,\n title: schema.title,\n description: schema.description,\n alias: toArray((schema as { alias?: string | string[] }).alias || []),\n env: (schema as { env?: string }).env,\n optional: !parent.required?.includes(name),\n default: schema.default\n } as Partial<CommandOption>;\n if (\n result.kind === CommandParameterKinds.string ||\n result.kind === CommandParameterKinds.number\n ) {\n result.variadic = isJsonSchema7ArrayType(schema);\n if (result.kind === CommandParameterKinds.string) {\n result.format = (\n schema as { format?: StringCommandParameter[\"format\"] }\n ).format;\n }\n\n if (\n (isJsonSchema7StringType(schema) || isJsonSchema7NumberType(schema)) &&\n (schema as JsonSchema7EnumType).enum\n ) {\n result.choices = (schema as JsonSchema7EnumType).enum;\n }\n } else if (result.kind === CommandParameterKinds.boolean) {\n result.skipAddingNegative = (\n schema as { skipAddingNegative?: boolean }\n ).skipAddingNegative;\n result.isNegativeOf = (schema as { isNegativeOf?: string }).isNegativeOf;\n }\n\n return result;\n}\n\nfunction resolveCommandArgument(\n schema: JsonSchema7Type\n): Partial<CommandArgument> {\n const result = {\n name: (schema as { name?: string }).name,\n kind:\n isJsonSchema7ArrayType(schema) && schema.items\n ? isJsonSchema7NumberType(schema.items)\n ? CommandParameterKinds.number\n : CommandParameterKinds.string\n : isJsonSchema7BooleanType(schema)\n ? CommandParameterKinds.boolean\n : isJsonSchema7NumberType(schema)\n ? CommandParameterKinds.number\n : CommandParameterKinds.string,\n title: schema.title,\n description: schema.description,\n alias: toArray((schema as { alias?: string | string[] }).alias || []),\n env: (schema as { env?: string }).env,\n default: schema.default\n } as Partial<CommandArgument>;\n if (\n result.kind === CommandParameterKinds.string ||\n result.kind === CommandParameterKinds.number\n ) {\n result.variadic = isJsonSchema7ArrayType(schema);\n if (result.kind === CommandParameterKinds.string) {\n result.format = (\n schema as { format?: StringCommandParameter[\"format\"] }\n ).format;\n }\n\n if (\n (isJsonSchema7StringType(schema) || isJsonSchema7NumberType(schema)) &&\n (schema as JsonSchema7EnumType).enum\n ) {\n result.choices = (schema as JsonSchema7EnumType).enum;\n }\n }\n\n return result;\n}\n\nexport async function resolveFromExports<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n) {\n validateExports(ctx);\n\n const metadata = ctx.module?.metadata ?? {};\n if (isSetString(metadata.title)) {\n ctx.output.title = metadata.title;\n }\n if (isSetString(metadata.description)) {\n ctx.output.description = metadata.description;\n }\n if (\n isSetString(metadata.alias) ||\n (Array.isArray(metadata.alias) && metadata.alias.length > 0)\n ) {\n ctx.output.alias = toArray(metadata.alias);\n }\n if (isSetString(metadata.icon)) {\n ctx.output.icon = metadata.icon;\n }\n\n if (isSetObject(ctx.module?.options)) {\n if (\n isZod3Type(ctx.module.options) ||\n isStandardJsonSchema(ctx.module.options) ||\n isJsonSchema7ObjectType(ctx.module.options)\n ) {\n let jsonSchema: JsonSchema7Type;\n if (isZod3Type(ctx.module.options)) {\n jsonSchema = extractJsonSchema7(ctx.module.options);\n } else if (isStandardJsonSchema(ctx.module.options)) {\n jsonSchema = ctx.module.options[\"~standard\"].jsonSchema.input({\n target: \"draft-07\"\n });\n } else {\n jsonSchema = ctx.module.options as JsonSchema7ObjectType;\n }\n\n if (!isJsonSchema7ObjectType(jsonSchema)) {\n throw new TypeError(\n `Command options for command at path \"${\n ctx.input.command.path\n }\" must be defined as a Zod object schema, a standard JSON Schema object, or a JSON Schema object.`\n );\n }\n\n ctx.output.options = Object.fromEntries(\n Object.entries((jsonSchema as JsonSchema7ObjectType).properties)\n .map(([name, property]) => [\n name,\n resolveCommandOption(name, jsonSchema, property)\n ])\n .concat(Object.entries(ctx.output.options))\n ) as Record<string, CommandOption>;\n } else if (\n Object.values(ctx.module.options).every(isCommandParameterConfig)\n ) {\n ctx.output.options = Object.fromEntries(\n Object.entries(\n ctx.module.options as Record<string, CommandParameterConfig>\n )\n .map(([name, option]) => [\n name,\n { name, ...option, alias: toArray(option.alias) }\n ])\n .concat(Object.entries(ctx.output.options))\n ) as Record<string, CommandOption>;\n } else {\n throw new TypeError(\n `Command options for command at path \"${\n ctx.input.command.path\n }\" must be defined as a record of valid CommandOption objects, a Zod object schema, or a standard JSON Schema object.`\n );\n }\n }\n\n if (isSetObject(ctx.module?.args)) {\n if (\n isZod3Type(ctx.module.args) ||\n isStandardJsonSchema(ctx.module.args) ||\n isJsonSchema7TupleType(ctx.module.args)\n ) {\n let jsonSchema: JsonSchema7Type;\n if (isZod3Type(ctx.module.args)) {\n jsonSchema = extractJsonSchema7(ctx.module.args);\n } else if (isStandardJsonSchema(ctx.module.args)) {\n jsonSchema = ctx.module.args[\"~standard\"].jsonSchema.input({\n target: \"draft-07\"\n });\n } else {\n jsonSchema = ctx.module.args;\n }\n\n if (!isJsonSchema7TupleType(jsonSchema)) {\n throw new TypeError(\n `Command arguments for command at path \"${\n ctx.input.command.path\n }\" must be defined as a Zod tuple schema, a standard JSON Schema tuple object, or a JSON Schema tuple object.`\n );\n }\n\n ctx.output.args = jsonSchema.items.map(item =>\n resolveCommandArgument(item)\n ) as CommandArgument[];\n } else if (Object.values(ctx.module.args).every(isCommandParameterConfig)) {\n ctx.output.args = ctx.module.args.map(arg => ({\n ...arg,\n alias: toArray(arg.alias)\n })) as CommandArgument[];\n } else {\n throw new TypeError(\n `Command arguments for command at path \"${\n ctx.input.command.path\n }\" must be defined as a record of valid CommandArgument objects, a Zod tuple schema, or a standard JSON Schema tuple object.`\n );\n }\n }\n}\n\nfunction validateExports<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n) {\n if (!ctx.module) {\n throw new Error(\n `Command module at path \"${\n ctx.input.command.path\n }\" is undefined or null. Please ensure the module exports a valid command.`\n );\n } else if (!isSetObject(ctx.module)) {\n throw new TypeError(\n `Command module at path \"${\n ctx.input.command.path\n }\" is not an object. Please ensure the module exports a valid command.`\n );\n } else if (!(\"default\" in ctx.module)) {\n throw new Error(\n `Command module at path \"${\n ctx.input.command.path\n }\" does not appear to be valid. Please ensure the module's default export is a valid command handler function.`\n );\n }\n}\n"],"mappings":";;;;;;;;;;AAAA,MAAM,aAAa;CAAC;CAAK;CAAW;CAA2B;;AAE3D,IAAG,SAAS;;;AA2BhB,SAAS,qBAAgB,MAAA,QAAA,QAAA;CACrB,MAAM,SAAS;EACX;EACA,MAAM,uBAAO,OAAA,IAAA,OAAA,QACP,wBAAwB,OAAO,MAAM,GACjC,sBAAsB,SACtB,sBAAsB,SAC1B,yBAAyB,OAAO,GAClC,sBAAA,UACK,wBAAA,OAAA,GACF,sBAAA,SACO,sBAAE;EAChB,OAAC,OAAA;EACD,aAAa,OAAE;EACf,OAAO,QAAE,OAAA,SAAA,EAAA,CAAA;EACT,KAAK,OAAO;EACZ,UAAU,CAAC,OAAO,UAAU,SAAS,KAAC;;EAEzC;AACD,KAAI,OAAM,SAAA,sBAAA,UACN,OAAO,SAAS,sBAAO,QAAA;AACvB,SAAO,WAAS,uBAAA,OAAA;AAChB,MAAI,OAAO,SAAO,sBAAA,OACd,QAAK,SAAA,OAAA;AAET,OAAA,wBAAA,OAAA,IAAA,wBAAA,OAAA,KACI,OAAO,KACP,QAAO,UAAU,OAAO;YAGvB,OAAO,SAAS,sBAAY,SAAA;AACjC,SAAO,qBAAqB,OAAI;AAChC,SAAO,eAAe,OAAO;;AAEjC,QAAO;;AAEX,qBA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AM,IAAI,cAAQ,SAAA,uBAAA,KAAA,EAAA;GAAA;GAAA;GAAA;GAAA,CAAA,CAAA;YAE1C,OAAO,OAAO,IAAI,OAAO,KAAK,CAAC,MAAM,yBAAgB,CAC1D,KAAI,OAAO,OAAI,IAAA,OAAA,KAAA,IAAA,cAAA,SAAA;EACjB,GAAA;EACG,OAAA,QAAA,IAAA,MAAA;EACA,GAAG;EAAC;EAAO;EAAI;EAAU,CAAC,CAAC;KAG5B,OAAM,IAAI,UAAU,0CAAgB,IAAA,MAAA,QAAA,KAAA,6HAAA;;AAIhD,mBAAmB,SAAS;CAAC;CAAmB;CAAO;CAAsB;CAAY;AACzF,SAAS,gBAAA,KAAA;AACL,KAAE,CAAA,IAAA;UAGO,CAAC,YAAY,IAAI,OAAO,CAC7B,OAAM,IAAI,UAAU,2BAAS,IAAA,MAAA,QAAA,KAAA,uEAAA;UAExB,EAAE,aAAa,IAAI,QACxB,OAAG,IAAA,MAAA,2BAAA,IAAA,MAAA,QAAA,KAAA,+GAAA;;AAGX,gBAAc,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA"}
@@ -51,39 +51,39 @@ initialize.__type = [
51
51
  "P\"w!2\"\"w#`/$"
52
52
  ];
53
53
  async function postprocess(ctx) {
54
- ctx.output.options = require_helpers.applyOptionsDefaults(ctx.output.options);
55
- ctx.output.args = require_helpers.applyArgsDefaults(ctx.output.args);
56
- ctx.output.args.forEach(__assignType((argument, index) => {
57
- const found = ctx.output.args.findIndex(__assignType((arg) => arg.name === argument.name, [
58
- "arg",
54
+ ctx.output.options = require_helpers.applyOptionsDefaults(ctx);
55
+ ctx.output.args = require_helpers.applyArgsDefaults(ctx);
56
+ ctx.output.args.forEach(__assignType((arg, index) => {
57
+ const found = ctx.output.args.findIndex(__assignType((a) => a.name === arg.name, [
58
+ "a",
59
59
  "",
60
60
  "P\"2!\"/\""
61
61
  ]));
62
- if (found !== -1 && found !== index || ctx.output.segments.some(__assignType((segment) => require_context_helpers.isDynamicPathSegment(segment) && require_context_helpers.getDynamicPathSegmentName(segment) === argument.name, [
62
+ if (found !== -1 && found !== index || ctx.output.segments.some(__assignType((segment) => require_context_helpers.isDynamicPathSegment(segment) && require_context_helpers.getDynamicPathSegmentName(segment) === arg.name, [
63
63
  "segment",
64
64
  "",
65
65
  "P\"2!\"/\""
66
66
  ]))) {
67
- argument.name += `_${ctx.output.segments.filter(__assignType((segment) => require_context_helpers.isDynamicPathSegment(segment) && require_context_helpers.getDynamicPathSegmentName(segment).replace(/_\d+$/, "") === argument.name, [
67
+ arg.name += `_${ctx.output.segments.filter(__assignType((segment) => require_context_helpers.isDynamicPathSegment(segment) && require_context_helpers.getDynamicPathSegmentName(segment).replace(/_\d+$/, "") === arg.name, [
68
68
  "segment",
69
69
  "",
70
70
  "P\"2!\"/\""
71
- ])).length + ctx.output.args.filter(__assignType((arg) => arg.name.replace(/_\d+$/, "") === argument.name, [
72
- "arg",
71
+ ])).length + ctx.output.args.filter(__assignType((a) => a.name.replace(/_\d+$/, "") === arg.name, [
72
+ "a",
73
73
  "",
74
74
  "P\"2!\"/\""
75
75
  ])).length}`;
76
- argument.env = (0, __stryke_string_format_constant_case.constantCase)(argument.name);
76
+ arg.env = arg.name ? arg.env || arg.env === false ? arg.env : ctx.input.context.config.autoAssignEnv ? (0, __stryke_string_format_constant_case.constantCase)(arg.name) : false : false;
77
77
  }
78
78
  }, [
79
- "argument",
79
+ "arg",
80
80
  "index",
81
81
  "",
82
82
  "P\"2!\"2\"\"/#"
83
83
  ]));
84
84
  require_helpers.applyDefaults(ctx);
85
85
  if (ctx.input.context.env) {
86
- if ((0, __stryke_type_checks_is_set_object.isSetObject)(ctx.output.options)) Object.values(ctx.output.options).filter(__assignType((option) => option.env !== false, [
86
+ if ((0, __stryke_type_checks_is_set_object.isSetObject)(ctx.output.options)) Object.values(ctx.output.options).filter(__assignType((option) => Boolean(option.env), [
87
87
  "option",
88
88
  "",
89
89
  "P\"2!\"/\""
@@ -114,7 +114,7 @@ async function postprocess(ctx) {
114
114
  "",
115
115
  "P\"2!\"/\""
116
116
  ]));
117
- ctx.output.args.filter(__assignType((arg) => arg.env !== false, [
117
+ ctx.output.args.filter(__assignType((arg) => Boolean(arg.env), [
118
118
  "arg",
119
119
  "",
120
120
  "P\"2!\"/\""