zod-args-parser 2.0.0-beta.0 → 2.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -0
- package/README.md +230 -289
- package/lib/esm/autocomplete-scripts/bash-autocomplete-script.js +74 -2
- package/lib/esm/autocomplete-scripts/bash-autocomplete-script.js.map +7 -1
- package/lib/esm/autocomplete-scripts/powershell-autocomplete-script.js +90 -2
- package/lib/esm/autocomplete-scripts/powershell-autocomplete-script.js.map +7 -1
- package/lib/esm/autocomplete-scripts/zsh-autocomplete-script.js +39 -13
- package/lib/esm/autocomplete-scripts/zsh-autocomplete-script.js.map +7 -1
- package/lib/esm/cli-error/cli-error.js +38 -0
- package/lib/esm/cli-error/cli-error.js.map +7 -0
- package/lib/esm/cli-error/error-cause.js +12 -0
- package/lib/esm/cli-error/error-cause.js.map +7 -0
- package/lib/esm/cli-error/error-code/definition-error-code.js +23 -0
- package/lib/esm/cli-error/error-code/definition-error-code.js.map +7 -0
- package/lib/esm/cli-error/error-code/internal-error-code.js +10 -0
- package/lib/esm/cli-error/error-code/internal-error-code.js.map +7 -0
- package/lib/esm/cli-error/error-code/parse-error-code.js +18 -0
- package/lib/esm/cli-error/error-code/parse-error-code.js.map +7 -0
- package/lib/esm/cli-error/error-code/validation-error-code.js +17 -0
- package/lib/esm/cli-error/error-code/validation-error-code.js.map +7 -0
- package/lib/esm/cli-error/error-message/definition-error-message.js +70 -0
- package/lib/esm/cli-error/error-message/definition-error-message.js.map +7 -0
- package/lib/esm/cli-error/error-message/internal-error-message.js +16 -0
- package/lib/esm/cli-error/error-message/internal-error-message.js.map +7 -0
- package/lib/esm/cli-error/error-message/parse-error-message.js +40 -0
- package/lib/esm/cli-error/error-message/parse-error-message.js.map +7 -0
- package/lib/esm/cli-error/error-message/validation-error-message.js +60 -0
- package/lib/esm/cli-error/error-message/validation-error-message.js.map +7 -0
- package/lib/esm/coerce/coerce-methods.js +197 -2
- package/lib/esm/coerce/coerce-methods.js.map +7 -1
- package/lib/esm/coerce/string-to-array.js +17 -2
- package/lib/esm/coerce/string-to-array.js.map +7 -1
- package/lib/esm/coerce/string-to-primitive.js +73 -2
- package/lib/esm/coerce/string-to-primitive.js.map +7 -1
- package/lib/esm/coerce/string-to-set.js +17 -2
- package/lib/esm/coerce/string-to-set.js.map +7 -1
- package/lib/esm/definitions/define-arguments.js +10 -2
- package/lib/esm/definitions/define-arguments.js.map +7 -1
- package/lib/esm/definitions/define-cli.js +89 -2
- package/lib/esm/definitions/define-cli.js.map +7 -1
- package/lib/esm/definitions/define-options.js +10 -2
- package/lib/esm/definitions/define-options.js.map +7 -1
- package/lib/esm/definitions/define-subcommand.js +56 -2
- package/lib/esm/definitions/define-subcommand.js.map +7 -1
- package/lib/esm/definitions/validate-cli-definition.js +360 -2
- package/lib/esm/definitions/validate-cli-definition.js.map +7 -1
- package/lib/esm/help-message/format-arguments.js +48 -2
- package/lib/esm/help-message/format-arguments.js.map +7 -1
- package/lib/esm/help-message/format-options.js +50 -2
- package/lib/esm/help-message/format-options.js.map +7 -1
- package/lib/esm/help-message/format-subcommands.js +37 -2
- package/lib/esm/help-message/format-subcommands.js.map +7 -1
- package/lib/esm/help-message/generate-for-cli.js +71 -2
- package/lib/esm/help-message/generate-for-cli.js.map +7 -1
- package/lib/esm/help-message/generate-for-subcommand.js +23 -2
- package/lib/esm/help-message/generate-for-subcommand.js.map +7 -1
- package/lib/esm/help-message/print-help.js +14 -2
- package/lib/esm/help-message/print-help.js.map +7 -1
- package/lib/esm/help-message/set-defaults.js +29 -2
- package/lib/esm/help-message/set-defaults.js.map +7 -1
- package/lib/esm/help-message/styles.js +154 -2
- package/lib/esm/help-message/styles.js.map +7 -1
- package/lib/esm/help-message/terminal-markdown.js +121 -2
- package/lib/esm/help-message/terminal-markdown.js.map +7 -1
- package/lib/esm/index.js +52 -2
- package/lib/esm/index.js.map +7 -1
- package/lib/esm/markdown/generate-markdown.js +153 -2
- package/lib/esm/markdown/generate-markdown.js.map +7 -1
- package/lib/esm/metadata/arguments-metadata.js +26 -2
- package/lib/esm/metadata/arguments-metadata.js.map +7 -1
- package/lib/esm/metadata/cli-metadata.js +24 -2
- package/lib/esm/metadata/cli-metadata.js.map +7 -1
- package/lib/esm/metadata/options-metadata.js +35 -2
- package/lib/esm/metadata/options-metadata.js.map +7 -1
- package/lib/esm/metadata/subcommands-metadata.js +32 -2
- package/lib/esm/metadata/subcommands-metadata.js.map +7 -1
- package/lib/esm/parse/context/cli-context-builder.js +283 -2
- package/lib/esm/parse/context/cli-context-builder.js.map +7 -1
- package/lib/esm/parse/context/object-context-builder.js +62 -2
- package/lib/esm/parse/context/object-context-builder.js.map +7 -1
- package/lib/esm/parse/parser-utilities.js +108 -2
- package/lib/esm/parse/parser-utilities.js.map +7 -1
- package/lib/esm/parse/safe-parse.js +57 -2
- package/lib/esm/parse/safe-parse.js.map +7 -1
- package/lib/esm/parse/validation/validate-context.js +17 -2
- package/lib/esm/parse/validation/validate-context.js.map +7 -1
- package/lib/esm/parse/validation/validators/arguments.js +67 -2
- package/lib/esm/parse/validation/validators/arguments.js.map +7 -1
- package/lib/esm/parse/validation/validators/conflict.js +38 -2
- package/lib/esm/parse/validation/validators/conflict.js.map +7 -1
- package/lib/esm/parse/validation/validators/exclusive.js +39 -2
- package/lib/esm/parse/validation/validators/exclusive.js.map +7 -1
- package/lib/esm/parse/validation/validators/explicitly-passed.js +18 -2
- package/lib/esm/parse/validation/validators/explicitly-passed.js.map +7 -1
- package/lib/esm/parse/validation/validators/options.js +67 -2
- package/lib/esm/parse/validation/validators/options.js.map +7 -1
- package/lib/esm/parse/validation/validators/requires.js +43 -2
- package/lib/esm/parse/validation/validators/requires.js.map +7 -1
- package/lib/esm/utilities/parse-argv.js +61 -0
- package/lib/esm/utilities/parse-argv.js.map +7 -0
- package/lib/esm/utilities/schema-utilities.js +57 -0
- package/lib/esm/utilities/schema-utilities.js.map +7 -0
- package/lib/esm/utilities/utilities.js +122 -0
- package/lib/esm/utilities/utilities.js.map +7 -0
- package/lib/iife/index.js +1 -1
- package/lib/iife/index.js.map +1 -1
- package/lib/mjs/autocomplete-scripts/bash-autocomplete-script.mjs +74 -2
- package/lib/mjs/autocomplete-scripts/bash-autocomplete-script.mjs.map +7 -1
- package/lib/mjs/autocomplete-scripts/powershell-autocomplete-script.mjs +90 -2
- package/lib/mjs/autocomplete-scripts/powershell-autocomplete-script.mjs.map +7 -1
- package/lib/mjs/autocomplete-scripts/zsh-autocomplete-script.mjs +39 -13
- package/lib/mjs/autocomplete-scripts/zsh-autocomplete-script.mjs.map +7 -1
- package/lib/mjs/cli-error/cli-error.mjs +38 -0
- package/lib/mjs/cli-error/cli-error.mjs.map +7 -0
- package/lib/mjs/cli-error/error-cause.mjs +12 -0
- package/lib/mjs/cli-error/error-cause.mjs.map +7 -0
- package/lib/mjs/cli-error/error-code/definition-error-code.mjs +23 -0
- package/lib/mjs/cli-error/error-code/definition-error-code.mjs.map +7 -0
- package/lib/mjs/cli-error/error-code/internal-error-code.mjs +10 -0
- package/lib/mjs/cli-error/error-code/internal-error-code.mjs.map +7 -0
- package/lib/mjs/cli-error/error-code/parse-error-code.mjs +18 -0
- package/lib/mjs/cli-error/error-code/parse-error-code.mjs.map +7 -0
- package/lib/mjs/cli-error/error-code/validation-error-code.mjs +17 -0
- package/lib/mjs/cli-error/error-code/validation-error-code.mjs.map +7 -0
- package/lib/mjs/cli-error/error-message/definition-error-message.mjs +70 -0
- package/lib/mjs/cli-error/error-message/definition-error-message.mjs.map +7 -0
- package/lib/mjs/cli-error/error-message/internal-error-message.mjs +16 -0
- package/lib/mjs/cli-error/error-message/internal-error-message.mjs.map +7 -0
- package/lib/mjs/cli-error/error-message/parse-error-message.mjs +40 -0
- package/lib/mjs/cli-error/error-message/parse-error-message.mjs.map +7 -0
- package/lib/mjs/cli-error/error-message/validation-error-message.mjs +60 -0
- package/lib/mjs/cli-error/error-message/validation-error-message.mjs.map +7 -0
- package/lib/mjs/coerce/coerce-methods.mjs +197 -2
- package/lib/mjs/coerce/coerce-methods.mjs.map +7 -1
- package/lib/mjs/coerce/string-to-array.mjs +17 -2
- package/lib/mjs/coerce/string-to-array.mjs.map +7 -1
- package/lib/mjs/coerce/string-to-primitive.mjs +73 -2
- package/lib/mjs/coerce/string-to-primitive.mjs.map +7 -1
- package/lib/mjs/coerce/string-to-set.mjs +17 -2
- package/lib/mjs/coerce/string-to-set.mjs.map +7 -1
- package/lib/mjs/definitions/define-arguments.mjs +10 -2
- package/lib/mjs/definitions/define-arguments.mjs.map +7 -1
- package/lib/mjs/definitions/define-cli.mjs +89 -2
- package/lib/mjs/definitions/define-cli.mjs.map +7 -1
- package/lib/mjs/definitions/define-options.mjs +10 -2
- package/lib/mjs/definitions/define-options.mjs.map +7 -1
- package/lib/mjs/definitions/define-subcommand.mjs +56 -2
- package/lib/mjs/definitions/define-subcommand.mjs.map +7 -1
- package/lib/mjs/definitions/validate-cli-definition.mjs +360 -2
- package/lib/mjs/definitions/validate-cli-definition.mjs.map +7 -1
- package/lib/mjs/help-message/format-arguments.mjs +48 -2
- package/lib/mjs/help-message/format-arguments.mjs.map +7 -1
- package/lib/mjs/help-message/format-options.mjs +50 -2
- package/lib/mjs/help-message/format-options.mjs.map +7 -1
- package/lib/mjs/help-message/format-subcommands.mjs +37 -2
- package/lib/mjs/help-message/format-subcommands.mjs.map +7 -1
- package/lib/mjs/help-message/generate-for-cli.mjs +71 -2
- package/lib/mjs/help-message/generate-for-cli.mjs.map +7 -1
- package/lib/mjs/help-message/generate-for-subcommand.mjs +23 -2
- package/lib/mjs/help-message/generate-for-subcommand.mjs.map +7 -1
- package/lib/mjs/help-message/print-help.mjs +14 -2
- package/lib/mjs/help-message/print-help.mjs.map +7 -1
- package/lib/mjs/help-message/set-defaults.mjs +29 -2
- package/lib/mjs/help-message/set-defaults.mjs.map +7 -1
- package/lib/mjs/help-message/styles.mjs +154 -2
- package/lib/mjs/help-message/styles.mjs.map +7 -1
- package/lib/mjs/help-message/terminal-markdown.mjs +121 -2
- package/lib/mjs/help-message/terminal-markdown.mjs.map +7 -1
- package/lib/mjs/index.mjs +52 -2
- package/lib/mjs/index.mjs.map +7 -1
- package/lib/mjs/markdown/generate-markdown.mjs +153 -2
- package/lib/mjs/markdown/generate-markdown.mjs.map +7 -1
- package/lib/mjs/metadata/arguments-metadata.mjs +26 -2
- package/lib/mjs/metadata/arguments-metadata.mjs.map +7 -1
- package/lib/mjs/metadata/cli-metadata.mjs +24 -2
- package/lib/mjs/metadata/cli-metadata.mjs.map +7 -1
- package/lib/mjs/metadata/options-metadata.mjs +35 -2
- package/lib/mjs/metadata/options-metadata.mjs.map +7 -1
- package/lib/mjs/metadata/subcommands-metadata.mjs +32 -2
- package/lib/mjs/metadata/subcommands-metadata.mjs.map +7 -1
- package/lib/mjs/parse/context/cli-context-builder.mjs +283 -2
- package/lib/mjs/parse/context/cli-context-builder.mjs.map +7 -1
- package/lib/mjs/parse/context/object-context-builder.mjs +62 -2
- package/lib/mjs/parse/context/object-context-builder.mjs.map +7 -1
- package/lib/mjs/parse/parser-utilities.mjs +108 -2
- package/lib/mjs/parse/parser-utilities.mjs.map +7 -1
- package/lib/mjs/parse/safe-parse.mjs +57 -2
- package/lib/mjs/parse/safe-parse.mjs.map +7 -1
- package/lib/mjs/parse/validation/validate-context.mjs +17 -2
- package/lib/mjs/parse/validation/validate-context.mjs.map +7 -1
- package/lib/mjs/parse/validation/validators/arguments.mjs +67 -2
- package/lib/mjs/parse/validation/validators/arguments.mjs.map +7 -1
- package/lib/mjs/parse/validation/validators/conflict.mjs +38 -2
- package/lib/mjs/parse/validation/validators/conflict.mjs.map +7 -1
- package/lib/mjs/parse/validation/validators/exclusive.mjs +39 -2
- package/lib/mjs/parse/validation/validators/exclusive.mjs.map +7 -1
- package/lib/mjs/parse/validation/validators/explicitly-passed.mjs +18 -2
- package/lib/mjs/parse/validation/validators/explicitly-passed.mjs.map +7 -1
- package/lib/mjs/parse/validation/validators/options.mjs +67 -2
- package/lib/mjs/parse/validation/validators/options.mjs.map +7 -1
- package/lib/mjs/parse/validation/validators/requires.mjs +43 -2
- package/lib/mjs/parse/validation/validators/requires.mjs.map +7 -1
- package/lib/mjs/utilities/parse-argv.mjs +61 -0
- package/lib/mjs/utilities/parse-argv.mjs.map +7 -0
- package/lib/mjs/utilities/schema-utilities.mjs +57 -0
- package/lib/mjs/utilities/schema-utilities.mjs.map +7 -0
- package/lib/mjs/utilities/utilities.mjs +122 -0
- package/lib/mjs/utilities/utilities.mjs.map +7 -0
- package/lib/{typescript → types}/autocomplete-scripts/bash-autocomplete-script.d.ts.map +1 -1
- package/lib/types/autocomplete-scripts/powershell-autocomplete-script.d.ts +15 -0
- package/lib/{typescript → types}/autocomplete-scripts/powershell-autocomplete-script.d.ts.map +1 -1
- package/lib/types/autocomplete-scripts/zsh-autocomplete-script.d.ts +4 -0
- package/lib/{typescript → types}/autocomplete-scripts/zsh-autocomplete-script.d.ts.map +1 -1
- package/lib/types/cli-error/cli-error.d.ts +152 -0
- package/lib/types/cli-error/cli-error.d.ts.map +1 -0
- package/lib/types/cli-error/error-cause.d.ts +5 -0
- package/lib/types/cli-error/error-cause.d.ts.map +1 -0
- package/lib/types/cli-error/error-code/definition-error-code.d.ts +5 -0
- package/lib/types/cli-error/error-code/definition-error-code.d.ts.map +1 -0
- package/lib/types/cli-error/error-code/internal-error-code.d.ts +5 -0
- package/lib/types/cli-error/error-code/internal-error-code.d.ts.map +1 -0
- package/lib/types/cli-error/error-code/parse-error-code.d.ts +5 -0
- package/lib/types/cli-error/error-code/parse-error-code.d.ts.map +1 -0
- package/lib/types/cli-error/error-code/validation-error-code.d.ts +5 -0
- package/lib/types/cli-error/error-code/validation-error-code.d.ts.map +1 -0
- package/lib/types/cli-error/error-message/definition-error-message.d.ts +3 -0
- package/lib/types/cli-error/error-message/definition-error-message.d.ts.map +1 -0
- package/lib/types/cli-error/error-message/internal-error-message.d.ts +3 -0
- package/lib/types/cli-error/error-message/internal-error-message.d.ts.map +1 -0
- package/lib/types/cli-error/error-message/parse-error-message.d.ts +3 -0
- package/lib/types/cli-error/error-message/parse-error-message.d.ts.map +1 -0
- package/lib/types/cli-error/error-message/validation-error-message.d.ts +3 -0
- package/lib/types/cli-error/error-message/validation-error-message.d.ts.map +1 -0
- package/lib/types/coerce/coerce-methods.d.ts +122 -0
- package/lib/types/coerce/coerce-methods.d.ts.map +1 -0
- package/lib/{typescript → types}/coerce/string-to-array.d.ts +2 -2
- package/lib/types/coerce/string-to-array.d.ts.map +1 -0
- package/lib/types/coerce/string-to-primitive.d.ts +21 -0
- package/lib/types/coerce/string-to-primitive.d.ts.map +1 -0
- package/lib/{typescript → types}/coerce/string-to-set.d.ts +2 -2
- package/lib/{typescript → types}/coerce/string-to-set.d.ts.map +1 -1
- package/lib/{typescript → types}/definitions/define-cli.d.ts +2 -6
- package/lib/types/definitions/define-cli.d.ts.map +1 -0
- package/lib/{typescript → types}/definitions/define-subcommand.d.ts +2 -4
- package/lib/types/definitions/define-subcommand.d.ts.map +1 -0
- package/lib/{typescript → types}/definitions/validate-cli-definition.d.ts +1 -1
- package/lib/types/definitions/validate-cli-definition.d.ts.map +1 -0
- package/lib/{typescript → types}/help-message/terminal-markdown.d.ts.map +1 -1
- package/lib/{typescript → types}/index.d.ts +7 -0
- package/lib/{typescript → types}/index.d.ts.map +1 -1
- package/lib/{typescript → types}/metadata/arguments-metadata.d.ts.map +1 -1
- package/lib/{typescript → types}/metadata/options-metadata.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/context/cli-context-builder.d.ts +1 -1
- package/lib/{typescript → types}/parse/context/cli-context-builder.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/context/object-context-builder.d.ts +1 -1
- package/lib/types/parse/context/object-context-builder.d.ts.map +1 -0
- package/lib/{typescript → types}/parse/parser-utilities.d.ts +9 -0
- package/lib/{typescript → types}/parse/parser-utilities.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/safe-parse.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/validation/validate-context.d.ts +1 -1
- package/lib/{typescript → types}/parse/validation/validate-context.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/validation/validators/arguments.d.ts +1 -1
- package/lib/{typescript → types}/parse/validation/validators/arguments.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/validation/validators/conflict.d.ts +3 -3
- package/lib/{typescript → types}/parse/validation/validators/conflict.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/validation/validators/exclusive.d.ts +3 -3
- package/lib/{typescript → types}/parse/validation/validators/exclusive.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/validation/validators/options.d.ts +1 -1
- package/lib/{typescript → types}/parse/validation/validators/options.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/validation/validators/requires.d.ts +3 -3
- package/lib/{typescript → types}/parse/validation/validators/requires.d.ts.map +1 -1
- package/lib/{typescript → types}/types/definitions-types.d.ts +35 -4
- package/lib/types/types/definitions-types.d.ts.map +1 -0
- package/lib/types/types/error-types.d.ts +275 -0
- package/lib/types/types/error-types.d.ts.map +1 -0
- package/lib/{typescript → types}/types/io-types.d.ts +1 -1
- package/lib/types/types/types.d.ts +146 -0
- package/lib/types/types/types.d.ts.map +1 -0
- package/lib/{typescript → types}/types/utilities-types.d.ts +0 -2
- package/lib/{typescript → types}/types/utilities-types.d.ts.map +1 -1
- package/lib/types/utilities/parse-argv.d.ts +3 -0
- package/lib/types/utilities/parse-argv.d.ts.map +1 -0
- package/lib/types/utilities/schema-utilities.d.ts +15 -0
- package/lib/types/utilities/schema-utilities.d.ts.map +1 -0
- package/lib/{typescript → types/utilities}/utilities.d.ts +12 -15
- package/lib/types/utilities/utilities.d.ts.map +1 -0
- package/package.json +7 -7
- package/src/autocomplete-scripts/bash-autocomplete-script.ts +14 -12
- package/src/autocomplete-scripts/powershell-autocomplete-script.ts +67 -33
- package/src/autocomplete-scripts/zsh-autocomplete-script.ts +39 -31
- package/src/cli-error/cli-error.ts +44 -0
- package/src/cli-error/error-cause.ts +10 -0
- package/src/cli-error/error-code/definition-error-code.ts +21 -0
- package/src/cli-error/error-code/internal-error-code.ts +8 -0
- package/src/cli-error/error-code/parse-error-code.ts +16 -0
- package/src/cli-error/error-code/validation-error-code.ts +15 -0
- package/src/cli-error/error-message/definition-error-message.ts +144 -0
- package/src/cli-error/error-message/internal-error-message.ts +19 -0
- package/src/cli-error/error-message/parse-error-message.ts +76 -0
- package/src/cli-error/error-message/validation-error-message.ts +104 -0
- package/src/coerce/coerce-methods.ts +194 -39
- package/src/coerce/string-to-array.ts +2 -2
- package/src/coerce/string-to-primitive.ts +72 -13
- package/src/coerce/string-to-set.ts +2 -2
- package/src/definitions/define-arguments.ts +1 -1
- package/src/definitions/define-cli.ts +65 -30
- package/src/definitions/define-options.ts +1 -1
- package/src/definitions/define-subcommand.ts +47 -17
- package/src/definitions/validate-cli-definition.ts +287 -172
- package/src/help-message/format-arguments.ts +1 -1
- package/src/help-message/format-options.ts +1 -1
- package/src/help-message/format-subcommands.ts +1 -1
- package/src/help-message/generate-for-cli.ts +1 -1
- package/src/help-message/terminal-markdown.ts +3 -4
- package/src/index.ts +16 -0
- package/src/markdown/generate-markdown.ts +5 -4
- package/src/metadata/arguments-metadata.ts +2 -1
- package/src/metadata/options-metadata.ts +2 -1
- package/src/parse/context/cli-context-builder.ts +166 -39
- package/src/parse/context/object-context-builder.ts +37 -11
- package/src/parse/parser-utilities.ts +24 -10
- package/src/parse/safe-parse.ts +3 -6
- package/src/parse/validation/validate-context.ts +1 -1
- package/src/parse/validation/validators/arguments.ts +42 -14
- package/src/parse/validation/validators/conflict.ts +11 -20
- package/src/parse/validation/validators/exclusive.ts +16 -25
- package/src/parse/validation/validators/options.ts +40 -12
- package/src/parse/validation/validators/requires.ts +11 -20
- package/src/types/definitions-types.ts +36 -8
- package/src/types/error-types.ts +326 -0
- package/src/types/io-types.ts +1 -1
- package/src/types/types.ts +100 -7
- package/src/types/utilities-types.ts +0 -10
- package/src/utilities/parse-argv.ts +79 -0
- package/src/utilities/schema-utilities.ts +72 -0
- package/src/{utilities.ts → utilities/utilities.ts} +25 -138
- package/lib/cjs/autocomplete-scripts/bash-autocomplete-script.cjs +0 -2
- package/lib/cjs/autocomplete-scripts/bash-autocomplete-script.cjs.map +0 -1
- package/lib/cjs/autocomplete-scripts/powershell-autocomplete-script.cjs +0 -2
- package/lib/cjs/autocomplete-scripts/powershell-autocomplete-script.cjs.map +0 -1
- package/lib/cjs/autocomplete-scripts/zsh-autocomplete-script.cjs +0 -42
- package/lib/cjs/autocomplete-scripts/zsh-autocomplete-script.cjs.map +0 -1
- package/lib/cjs/coerce/coerce-methods.cjs +0 -2
- package/lib/cjs/coerce/coerce-methods.cjs.map +0 -1
- package/lib/cjs/coerce/string-to-array.cjs +0 -2
- package/lib/cjs/coerce/string-to-array.cjs.map +0 -1
- package/lib/cjs/coerce/string-to-primitive.cjs +0 -2
- package/lib/cjs/coerce/string-to-primitive.cjs.map +0 -1
- package/lib/cjs/coerce/string-to-set.cjs +0 -2
- package/lib/cjs/coerce/string-to-set.cjs.map +0 -1
- package/lib/cjs/definitions/define-arguments.cjs +0 -2
- package/lib/cjs/definitions/define-arguments.cjs.map +0 -1
- package/lib/cjs/definitions/define-cli.cjs +0 -2
- package/lib/cjs/definitions/define-cli.cjs.map +0 -1
- package/lib/cjs/definitions/define-options.cjs +0 -2
- package/lib/cjs/definitions/define-options.cjs.map +0 -1
- package/lib/cjs/definitions/define-subcommand.cjs +0 -2
- package/lib/cjs/definitions/define-subcommand.cjs.map +0 -1
- package/lib/cjs/definitions/validate-cli-definition.cjs +0 -2
- package/lib/cjs/definitions/validate-cli-definition.cjs.map +0 -1
- package/lib/cjs/help-message/format-arguments.cjs +0 -2
- package/lib/cjs/help-message/format-arguments.cjs.map +0 -1
- package/lib/cjs/help-message/format-options.cjs +0 -2
- package/lib/cjs/help-message/format-options.cjs.map +0 -1
- package/lib/cjs/help-message/format-subcommands.cjs +0 -2
- package/lib/cjs/help-message/format-subcommands.cjs.map +0 -1
- package/lib/cjs/help-message/generate-for-cli.cjs +0 -2
- package/lib/cjs/help-message/generate-for-cli.cjs.map +0 -1
- package/lib/cjs/help-message/generate-for-subcommand.cjs +0 -2
- package/lib/cjs/help-message/generate-for-subcommand.cjs.map +0 -1
- package/lib/cjs/help-message/print-help.cjs +0 -2
- package/lib/cjs/help-message/print-help.cjs.map +0 -1
- package/lib/cjs/help-message/set-defaults.cjs +0 -2
- package/lib/cjs/help-message/set-defaults.cjs.map +0 -1
- package/lib/cjs/help-message/styles.cjs +0 -2
- package/lib/cjs/help-message/styles.cjs.map +0 -1
- package/lib/cjs/help-message/terminal-markdown.cjs +0 -2
- package/lib/cjs/help-message/terminal-markdown.cjs.map +0 -1
- package/lib/cjs/index.cjs +0 -2
- package/lib/cjs/index.cjs.map +0 -1
- package/lib/cjs/markdown/generate-markdown.cjs +0 -2
- package/lib/cjs/markdown/generate-markdown.cjs.map +0 -1
- package/lib/cjs/metadata/arguments-metadata.cjs +0 -2
- package/lib/cjs/metadata/arguments-metadata.cjs.map +0 -1
- package/lib/cjs/metadata/cli-metadata.cjs +0 -2
- package/lib/cjs/metadata/cli-metadata.cjs.map +0 -1
- package/lib/cjs/metadata/options-metadata.cjs +0 -2
- package/lib/cjs/metadata/options-metadata.cjs.map +0 -1
- package/lib/cjs/metadata/subcommands-metadata.cjs +0 -2
- package/lib/cjs/metadata/subcommands-metadata.cjs.map +0 -1
- package/lib/cjs/parse/context/cli-context-builder.cjs +0 -2
- package/lib/cjs/parse/context/cli-context-builder.cjs.map +0 -1
- package/lib/cjs/parse/context/object-context-builder.cjs +0 -2
- package/lib/cjs/parse/context/object-context-builder.cjs.map +0 -1
- package/lib/cjs/parse/parser-utilities.cjs +0 -2
- package/lib/cjs/parse/parser-utilities.cjs.map +0 -1
- package/lib/cjs/parse/safe-parse.cjs +0 -2
- package/lib/cjs/parse/safe-parse.cjs.map +0 -1
- package/lib/cjs/parse/validation/validate-context.cjs +0 -2
- package/lib/cjs/parse/validation/validate-context.cjs.map +0 -1
- package/lib/cjs/parse/validation/validators/arguments.cjs +0 -2
- package/lib/cjs/parse/validation/validators/arguments.cjs.map +0 -1
- package/lib/cjs/parse/validation/validators/conflict.cjs +0 -2
- package/lib/cjs/parse/validation/validators/conflict.cjs.map +0 -1
- package/lib/cjs/parse/validation/validators/exclusive.cjs +0 -2
- package/lib/cjs/parse/validation/validators/exclusive.cjs.map +0 -1
- package/lib/cjs/parse/validation/validators/explicitly-passed.cjs +0 -2
- package/lib/cjs/parse/validation/validators/explicitly-passed.cjs.map +0 -1
- package/lib/cjs/parse/validation/validators/options.cjs +0 -2
- package/lib/cjs/parse/validation/validators/options.cjs.map +0 -1
- package/lib/cjs/parse/validation/validators/requires.cjs +0 -2
- package/lib/cjs/parse/validation/validators/requires.cjs.map +0 -1
- package/lib/cjs/utilities.cjs +0 -2
- package/lib/cjs/utilities.cjs.map +0 -1
- package/lib/esm/utilities.js +0 -2
- package/lib/esm/utilities.js.map +0 -1
- package/lib/mjs/utilities.mjs +0 -2
- package/lib/mjs/utilities.mjs.map +0 -1
- package/lib/typescript/autocomplete-scripts/powershell-autocomplete-script.d.ts +0 -14
- package/lib/typescript/autocomplete-scripts/zsh-autocomplete-script.d.ts +0 -11
- package/lib/typescript/coerce/coerce-methods.d.ts +0 -20
- package/lib/typescript/coerce/coerce-methods.d.ts.map +0 -1
- package/lib/typescript/coerce/string-to-array.d.ts.map +0 -1
- package/lib/typescript/coerce/string-to-primitive.d.ts +0 -5
- package/lib/typescript/coerce/string-to-primitive.d.ts.map +0 -1
- package/lib/typescript/definitions/define-cli.d.ts.map +0 -1
- package/lib/typescript/definitions/define-subcommand.d.ts.map +0 -1
- package/lib/typescript/definitions/validate-cli-definition.d.ts.map +0 -1
- package/lib/typescript/parse/context/object-context-builder.d.ts.map +0 -1
- package/lib/typescript/types/definitions-types.d.ts.map +0 -1
- package/lib/typescript/types/types.d.ts +0 -61
- package/lib/typescript/types/types.d.ts.map +0 -1
- package/lib/typescript/utilities.d.ts.map +0 -1
- /package/lib/{typescript → types}/autocomplete-scripts/bash-autocomplete-script.d.ts +0 -0
- /package/lib/{typescript → types}/definitions/define-arguments.d.ts +0 -0
- /package/lib/{typescript → types}/definitions/define-arguments.d.ts.map +0 -0
- /package/lib/{typescript → types}/definitions/define-options.d.ts +0 -0
- /package/lib/{typescript → types}/definitions/define-options.d.ts.map +0 -0
- /package/lib/{typescript → types}/help-message/format-arguments.d.ts +0 -0
- /package/lib/{typescript → types}/help-message/format-arguments.d.ts.map +0 -0
- /package/lib/{typescript → types}/help-message/format-options.d.ts +0 -0
- /package/lib/{typescript → types}/help-message/format-options.d.ts.map +0 -0
- /package/lib/{typescript → types}/help-message/format-subcommands.d.ts +0 -0
- /package/lib/{typescript → types}/help-message/format-subcommands.d.ts.map +0 -0
- /package/lib/{typescript → types}/help-message/generate-for-cli.d.ts +0 -0
- /package/lib/{typescript → types}/help-message/generate-for-cli.d.ts.map +0 -0
- /package/lib/{typescript → types}/help-message/generate-for-subcommand.d.ts +0 -0
- /package/lib/{typescript → types}/help-message/generate-for-subcommand.d.ts.map +0 -0
- /package/lib/{typescript → types}/help-message/print-help.d.ts +0 -0
- /package/lib/{typescript → types}/help-message/print-help.d.ts.map +0 -0
- /package/lib/{typescript → types}/help-message/set-defaults.d.ts +0 -0
- /package/lib/{typescript → types}/help-message/set-defaults.d.ts.map +0 -0
- /package/lib/{typescript → types}/help-message/styles.d.ts +0 -0
- /package/lib/{typescript → types}/help-message/styles.d.ts.map +0 -0
- /package/lib/{typescript → types}/help-message/terminal-markdown.d.ts +0 -0
- /package/lib/{typescript → types}/markdown/generate-markdown.d.ts +0 -0
- /package/lib/{typescript → types}/markdown/generate-markdown.d.ts.map +0 -0
- /package/lib/{typescript → types}/metadata/arguments-metadata.d.ts +0 -0
- /package/lib/{typescript → types}/metadata/cli-metadata.d.ts +0 -0
- /package/lib/{typescript → types}/metadata/cli-metadata.d.ts.map +0 -0
- /package/lib/{typescript → types}/metadata/options-metadata.d.ts +0 -0
- /package/lib/{typescript → types}/metadata/subcommands-metadata.d.ts +0 -0
- /package/lib/{typescript → types}/metadata/subcommands-metadata.d.ts.map +0 -0
- /package/lib/{typescript → types}/parse/safe-parse.d.ts +0 -0
- /package/lib/{typescript → types}/parse/validation/validators/explicitly-passed.d.ts +0 -0
- /package/lib/{typescript → types}/parse/validation/validators/explicitly-passed.d.ts.map +0 -0
- /package/lib/{typescript → types}/types/context-types.d.ts +0 -0
- /package/lib/{typescript → types}/types/context-types.d.ts.map +0 -0
- /package/lib/{typescript → types}/types/help-message-types.d.ts +0 -0
- /package/lib/{typescript → types}/types/help-message-types.d.ts.map +0 -0
- /package/lib/{typescript → types}/types/io-types.d.ts.map +0 -0
- /package/lib/{typescript → types}/types/metadata-types.d.ts +0 -0
- /package/lib/{typescript → types}/types/metadata-types.d.ts.map +0 -0
- /package/lib/{typescript → types}/types/schema-types.d.ts +0 -0
- /package/lib/{typescript → types}/types/schema-types.d.ts.map +0 -0
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/markdown/generate-markdown.ts"],
|
|
4
|
+
"sourcesContent": ["import { getCliMetadata } from \"../metadata/cli-metadata.ts\";\nimport { escapeHtmlTags, stripAnsi } from \"../utilities/utilities.ts\";\n\nimport type { Cli } from \"../types/definitions-types.ts\";\nimport type { ArgumentMetadata, OptionMetadata, SubcommandMetadata } from \"../types/metadata-types.ts\";\n\nexport function generateMarkdown(cliDefinition: Cli): string {\n const metadata = getCliMetadata(cliDefinition);\n\n let md = \"<!-- Auto-generated by zod-args-parser -->\\n\\n\";\n\n // Title\n md += `# ${metadata.name}\\n\\n`;\n\n // Description\n if (metadata.description && !metadata.descriptionMarkdown) {\n md += `${forceLineBreak(metadata.description)}\\n`;\n }\n\n // Description Markdown\n if (metadata.descriptionMarkdown) {\n md += `${forceLineBreak(metadata.descriptionMarkdown)}\\n`;\n }\n\n // Examples\n if (metadata.example) {\n md += renderExamples(metadata.example);\n }\n\n // Options\n if (metadata.options.length > 0) {\n md += \"\\n## Options:\\n\\n\";\n md += renderOptions(metadata.options, 3);\n }\n\n // Arguments\n if (metadata.arguments.length > 0) {\n md += \"\\n## Arguments:\\n\\n\";\n md += renderArguments(metadata.arguments, 3);\n }\n\n // Subcommands\n if (metadata.subcommands.length > 0) {\n md += \"\\n## Subcommands:\\n\\n\";\n md += renderSubcommands(metadata.subcommands);\n }\n\n md = stripAnsi(md);\n md = escapeHtmlTags(md);\n\n return md;\n}\n\nfunction renderExamples(examples: string) {\n let outString = \"\\n**Example:**\\n\";\n\n const lang = \"bash\";\n\n outString += \"\\n\";\n outString += \"```\" + lang + \"\\n\";\n outString += examples;\n outString += \"\\n```\\n\";\n\n return outString;\n}\n\nfunction renderOptions(optionsMetadata: OptionMetadata[] = [], h: number) {\n let outString = \"\";\n\n for (let index = 0; index < optionsMetadata.length; index++) {\n const metadata = optionsMetadata[index];\n if (metadata.hidden) continue;\n\n const aliases = [metadata.nameAsArg].concat(metadata.aliasesAsArgs).join(\", \");\n const placeholder = metadata.placeholder && ` ${metadata.placeholder}`;\n\n outString += `${\"#\".repeat(h)} \\`${aliases + placeholder}\\``;\n\n if (metadata.optional) {\n outString += \" _optional_\";\n }\n\n outString += \"\\n\\n\";\n\n if (metadata.description && !metadata.descriptionMarkdown) {\n outString += `${forceLineBreak(metadata.description)}\\n`;\n }\n\n if (metadata.descriptionMarkdown) {\n outString += `${forceLineBreak(metadata.descriptionMarkdown)}\\n`;\n }\n\n if (metadata.defaultValue !== undefined) {\n const nl = outString.endsWith(\"\\n\\n\") ? \"\" : \"\\n\";\n outString += `${nl}**default:** \\`${metadata.defaultValueAsString}\\`\\n`;\n }\n\n if (metadata.example) {\n outString += renderExamples(metadata.example);\n }\n\n if (index < optionsMetadata.length - 1) {\n outString += \"\\n\";\n }\n }\n\n return outString;\n}\n\nfunction renderArguments(argumentsMetadata: ArgumentMetadata[] = [], h: number) {\n let outString = \"\";\n\n for (let index = 0; index < argumentsMetadata.length; index++) {\n const metadata = argumentsMetadata[index];\n if (metadata.hidden) continue;\n\n outString += `${\"#\".repeat(h)} \\`${metadata.name}\\``;\n\n if (metadata.optional) {\n outString += \" _optional_\";\n }\n\n outString += \"\\n\\n\";\n\n if (metadata.description && !metadata.descriptionMarkdown) {\n outString += `${forceLineBreak(metadata.description)}\\n`;\n }\n\n if (metadata.descriptionMarkdown) {\n outString += `${forceLineBreak(metadata.descriptionMarkdown)}\\n`;\n }\n\n if (metadata.defaultValue !== undefined) {\n const nl = outString.endsWith(\"\\n\\n\") ? \"\" : \"\\n\";\n outString += `${nl}**default:** \\`${metadata.defaultValueAsString}\\`\\n`;\n }\n\n if (metadata.example) {\n outString += renderExamples(metadata.example);\n }\n\n if (index < argumentsMetadata.length - 1) {\n outString += \"\\n\";\n }\n }\n\n return outString;\n}\n\nfunction renderSubcommands(subcommandsMetadata: SubcommandMetadata[]) {\n let outString = \"\";\n\n for (let index = 0; index < subcommandsMetadata.length; index++) {\n const metadata = subcommandsMetadata[index];\n if (metadata.hidden) continue;\n\n const aliases = [metadata.name].concat(metadata.aliases).join(\", \");\n\n const placeholder = metadata.placeholder && ` ${metadata.placeholder}`;\n\n outString += `### ${aliases + placeholder}\\n\\n`;\n\n if (metadata.description && !metadata.descriptionMarkdown) {\n outString += `${forceLineBreak(metadata.description)}\\n`;\n }\n\n if (metadata.descriptionMarkdown) {\n outString += `${forceLineBreak(metadata.descriptionMarkdown)}\\n`;\n }\n\n if (metadata.example) {\n outString += renderExamples(metadata.example);\n }\n\n if (metadata.options.length > 0) {\n outString += \"\\n#### Options:\\n\\n\";\n outString += renderOptions(metadata.options, 4);\n }\n\n if (metadata.arguments.length > 0) {\n outString += \"\\n#### Arguments:\\n\\n\";\n outString += renderArguments(metadata.arguments, 4);\n }\n\n if (index < subcommandsMetadata.length - 1) {\n outString += \"\\n---\\n\\n\";\n }\n }\n\n return outString;\n}\n\n/** Inserts two trailing spaces before newline. In Markdown, a newline that ends with two spaces forces a line break. */\nfunction forceLineBreak(string: string): string {\n return string.replace(/(\\n+)/g, \" $1\");\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB,iBAAiB;AAKnC,SAAS,iBAAiB,eAA4B;AAC3D,QAAM,WAAW,eAAe,aAAa;AAE7C,MAAI,KAAK;AAGT,QAAM,KAAK,SAAS,IAAI;AAAA;AAAA;AAGxB,MAAI,SAAS,eAAe,CAAC,SAAS,qBAAqB;AACzD,UAAM,GAAG,eAAe,SAAS,WAAW,CAAC;AAAA;AAAA,EAC/C;AAGA,MAAI,SAAS,qBAAqB;AAChC,UAAM,GAAG,eAAe,SAAS,mBAAmB,CAAC;AAAA;AAAA,EACvD;AAGA,MAAI,SAAS,SAAS;AACpB,UAAM,eAAe,SAAS,OAAO;AAAA,EACvC;AAGA,MAAI,SAAS,QAAQ,SAAS,GAAG;AAC/B,UAAM;AACN,UAAM,cAAc,SAAS,SAAS,CAAC;AAAA,EACzC;AAGA,MAAI,SAAS,UAAU,SAAS,GAAG;AACjC,UAAM;AACN,UAAM,gBAAgB,SAAS,WAAW,CAAC;AAAA,EAC7C;AAGA,MAAI,SAAS,YAAY,SAAS,GAAG;AACnC,UAAM;AACN,UAAM,kBAAkB,SAAS,WAAW;AAAA,EAC9C;AAEA,OAAK,UAAU,EAAE;AACjB,OAAK,eAAe,EAAE;AAEtB,SAAO;AACT;AAEA,SAAS,eAAe,UAAkB;AACxC,MAAI,YAAY;AAEhB,QAAM,OAAO;AAEb,eAAa;AACb,eAAa,QAAQ,OAAO;AAC5B,eAAa;AACb,eAAa;AAEb,SAAO;AACT;AAEA,SAAS,cAAc,kBAAoC,CAAC,GAAG,GAAW;AACxE,MAAI,YAAY;AAEhB,WAAS,QAAQ,GAAG,QAAQ,gBAAgB,QAAQ,SAAS;AAC3D,UAAM,WAAW,gBAAgB,KAAK;AACtC,QAAI,SAAS,OAAQ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GA,SAAS,eAAe,QAAwB;AAC9C,SAAO,OAAO,QAAQ,UAAU,MAAM;AACxC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,2 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/metadata/arguments-metadata.ts
|
|
2
|
+
import { defaultValueAndIsOptional } from "../utilities/schema-utilities.js";
|
|
3
|
+
import { stringifyValue } from "../utilities/utilities.js";
|
|
4
|
+
function getArgumentsMetadata(argumentsDefinition) {
|
|
5
|
+
const outputMetadata = [];
|
|
6
|
+
for (const [name, argument] of Object.entries(argumentsDefinition)) {
|
|
7
|
+
const meta = argument.meta ?? {};
|
|
8
|
+
const { optional, defaultValue } = argument._preparedType ?? defaultValueAndIsOptional(argument.schema);
|
|
9
|
+
outputMetadata.push({
|
|
10
|
+
name: meta.name ?? name,
|
|
11
|
+
description: meta.description ?? "",
|
|
12
|
+
descriptionMarkdown: meta.descriptionMarkdown ?? "",
|
|
13
|
+
defaultValue,
|
|
14
|
+
defaultValueAsString: meta.default ?? stringifyValue(defaultValue) ?? "",
|
|
15
|
+
optional: meta.optional ?? optional,
|
|
16
|
+
example: meta.example ?? "",
|
|
17
|
+
schema: argument.schema,
|
|
18
|
+
hidden: meta.hidden ?? false
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return outputMetadata;
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
getArgumentsMetadata
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=arguments-metadata.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/metadata/arguments-metadata.ts"],
|
|
4
|
+
"sourcesContent": ["import { defaultValueAndIsOptional } from \"../utilities/schema-utilities.ts\";\nimport { stringifyValue } from \"../utilities/utilities.ts\";\n\nimport type { Argument } from \"../types/definitions-types.ts\";\nimport type { ArgumentMetadata } from \"../types/metadata-types.ts\";\n\nexport function getArgumentsMetadata(argumentsDefinition: Record<string, Argument>): ArgumentMetadata[] {\n const outputMetadata: ArgumentMetadata[] = [];\n\n for (const [name, argument] of Object.entries(argumentsDefinition)) {\n const meta = argument.meta ?? {};\n\n const { optional, defaultValue } = argument._preparedType ?? defaultValueAndIsOptional(argument.schema);\n\n outputMetadata.push({\n name: meta.name ?? name,\n description: meta.description ?? \"\",\n descriptionMarkdown: meta.descriptionMarkdown ?? \"\",\n defaultValue,\n defaultValueAsString: meta.default ?? stringifyValue(defaultValue) ?? \"\",\n optional: meta.optional ?? optional,\n example: meta.example ?? \"\",\n schema: argument.schema,\n hidden: meta.hidden ?? false,\n });\n }\n\n return outputMetadata;\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,iCAAiC;AAC1C,SAAS,sBAAsB;AAKxB,SAAS,qBAAqB,qBAAmE;AACtG,QAAM,iBAAqC,CAAC;AAE5C,aAAW,CAAC,MAAM,QAAQ,KAAK,OAAO,QAAQ,mBAAmB,GAAG;AAClE,UAAM,OAAO,SAAS,QAAQ,CAAC;AAE/B,UAAM,EAAE,UAAU,aAAa,IAAI,SAAS,iBAAiB,0BAA0B,SAAS,MAAM;AAEtG,mBAAe,KAAK;AAAA,MAClB,MAAM,KAAK,QAAQ;AAAA,MACnB,aAAa,KAAK,eAAe;AAAA,MACjC,qBAAqB,KAAK,uBAAuB;AAAA,MACjD;AAAA,MACA,sBAAsB,KAAK,WAAW,eAAe,YAAY,KAAK;AAAA,MACtE,UAAU,KAAK,YAAY;AAAA,MAC3B,SAAS,KAAK,WAAW;AAAA,MACzB,QAAQ,SAAS;AAAA,MACjB,QAAQ,KAAK,UAAU;AAAA,IACzB,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,2 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/metadata/cli-metadata.ts
|
|
2
|
+
import { getArgumentsMetadata } from "./arguments-metadata.js";
|
|
3
|
+
import { getOptionsMetadata } from "./options-metadata.js";
|
|
4
|
+
import { getSubcommandsMetadata } from "./subcommands-metadata.js";
|
|
5
|
+
function getCliMetadata(cliDefinition) {
|
|
6
|
+
const subcommands = cliDefinition.subcommands ?? [];
|
|
7
|
+
const meta = cliDefinition.meta ?? {};
|
|
8
|
+
const outputMetadata = {
|
|
9
|
+
name: cliDefinition.cliName,
|
|
10
|
+
description: meta.description ?? "",
|
|
11
|
+
descriptionMarkdown: meta.descriptionMarkdown ?? "",
|
|
12
|
+
usage: meta.usage ?? "",
|
|
13
|
+
example: meta.example ?? "",
|
|
14
|
+
allowPositionals: cliDefinition.allowPositionals ?? false,
|
|
15
|
+
options: cliDefinition.options ? getOptionsMetadata(cliDefinition.options) : [],
|
|
16
|
+
arguments: cliDefinition.arguments ? getArgumentsMetadata(cliDefinition.arguments) : [],
|
|
17
|
+
subcommands: subcommands ? getSubcommandsMetadata(subcommands) : []
|
|
18
|
+
};
|
|
19
|
+
return outputMetadata;
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
getCliMetadata
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=cli-metadata.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/metadata/cli-metadata.ts"],
|
|
4
|
+
"sourcesContent": ["import { getArgumentsMetadata } from \"./arguments-metadata.ts\";\nimport { getOptionsMetadata } from \"./options-metadata.ts\";\nimport { getSubcommandsMetadata } from \"./subcommands-metadata.ts\";\n\nimport type { Cli } from \"../types/definitions-types.ts\";\nimport type { CliMetadata } from \"../types/metadata-types.ts\";\n\nexport function getCliMetadata(cliDefinition: Cli): CliMetadata {\n const subcommands = cliDefinition.subcommands ?? [];\n\n const meta = cliDefinition.meta ?? {};\n\n const outputMetadata: CliMetadata = {\n name: cliDefinition.cliName,\n description: meta.description ?? \"\",\n descriptionMarkdown: meta.descriptionMarkdown ?? \"\",\n usage: meta.usage ?? \"\",\n example: meta.example ?? \"\",\n allowPositionals: cliDefinition.allowPositionals ?? false,\n options: cliDefinition.options ? getOptionsMetadata(cliDefinition.options) : [],\n arguments: cliDefinition.arguments ? getArgumentsMetadata(cliDefinition.arguments) : [],\n subcommands: subcommands ? getSubcommandsMetadata(subcommands) : [],\n };\n\n return outputMetadata;\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,4BAA4B;AACrC,SAAS,0BAA0B;AACnC,SAAS,8BAA8B;AAKhC,SAAS,eAAe,eAAiC;AAC9D,QAAM,cAAc,cAAc,eAAe,CAAC;AAElD,QAAM,OAAO,cAAc,QAAQ,CAAC;AAEpC,QAAM,iBAA8B;AAAA,IAClC,MAAM,cAAc;AAAA,IACpB,aAAa,KAAK,eAAe;AAAA,IACjC,qBAAqB,KAAK,uBAAuB;AAAA,IACjD,OAAO,KAAK,SAAS;AAAA,IACrB,SAAS,KAAK,WAAW;AAAA,IACzB,kBAAkB,cAAc,oBAAoB;AAAA,IACpD,SAAS,cAAc,UAAU,mBAAmB,cAAc,OAAO,IAAI,CAAC;AAAA,IAC9E,WAAW,cAAc,YAAY,qBAAqB,cAAc,SAAS,IAAI,CAAC;AAAA,IACtF,aAAa,cAAc,uBAAuB,WAAW,IAAI,CAAC;AAAA,EACpE;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,2 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/metadata/options-metadata.ts
|
|
2
|
+
import { transformOptionToArgument } from "../parse/parser-utilities.js";
|
|
3
|
+
import { defaultValueAndIsOptional } from "../utilities/schema-utilities.js";
|
|
4
|
+
import { stringifyValue } from "../utilities/utilities.js";
|
|
5
|
+
function getOptionsMetadata(optionsDefinition) {
|
|
6
|
+
const outputMetadata = [];
|
|
7
|
+
if (!optionsDefinition) {
|
|
8
|
+
return outputMetadata;
|
|
9
|
+
}
|
|
10
|
+
for (const [optionName, option] of Object.entries(optionsDefinition)) {
|
|
11
|
+
const aliases = option.aliases ?? [];
|
|
12
|
+
const meta = option.meta ?? {};
|
|
13
|
+
const { optional, defaultValue } = option._preparedType ?? defaultValueAndIsOptional(option.schema);
|
|
14
|
+
outputMetadata.push({
|
|
15
|
+
name: optionName,
|
|
16
|
+
nameAsArg: transformOptionToArgument(optionName),
|
|
17
|
+
aliases,
|
|
18
|
+
aliasesAsArgs: aliases.map((alias) => transformOptionToArgument(alias)),
|
|
19
|
+
placeholder: meta.placeholder ?? "",
|
|
20
|
+
description: meta.description ?? "",
|
|
21
|
+
descriptionMarkdown: meta.descriptionMarkdown ?? "",
|
|
22
|
+
optional: meta.optional ?? optional,
|
|
23
|
+
example: meta.example ?? "",
|
|
24
|
+
defaultValue,
|
|
25
|
+
defaultValueAsString: meta.default ?? stringifyValue(defaultValue) ?? "",
|
|
26
|
+
schema: option.schema,
|
|
27
|
+
hidden: meta.hidden ?? false
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return outputMetadata;
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
getOptionsMetadata
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=options-metadata.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/metadata/options-metadata.ts"],
|
|
4
|
+
"sourcesContent": ["import { transformOptionToArgument } from \"../parse/parser-utilities.ts\";\nimport { defaultValueAndIsOptional } from \"../utilities/schema-utilities.ts\";\nimport { stringifyValue } from \"../utilities/utilities.ts\";\n\nimport type { Option } from \"../types/definitions-types.ts\";\nimport type { OptionMetadata } from \"../types/metadata-types.ts\";\n\nexport function getOptionsMetadata(optionsDefinition: Record<string, Option>): OptionMetadata[] {\n const outputMetadata: OptionMetadata[] = [];\n\n if (!optionsDefinition) {\n return outputMetadata;\n }\n\n for (const [optionName, option] of Object.entries(optionsDefinition)) {\n const aliases = option.aliases ?? [];\n const meta = option.meta ?? {};\n\n const { optional, defaultValue } = option._preparedType ?? defaultValueAndIsOptional(option.schema);\n\n outputMetadata.push({\n name: optionName,\n nameAsArg: transformOptionToArgument(optionName),\n aliases,\n aliasesAsArgs: aliases.map(alias => transformOptionToArgument(alias)),\n placeholder: meta.placeholder ?? \"\",\n description: meta.description ?? \"\",\n descriptionMarkdown: meta.descriptionMarkdown ?? \"\",\n optional: meta.optional ?? optional,\n example: meta.example ?? \"\",\n defaultValue,\n defaultValueAsString: meta.default ?? stringifyValue(defaultValue) ?? \"\",\n schema: option.schema,\n hidden: meta.hidden ?? false,\n });\n }\n\n return outputMetadata;\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,iCAAiC;AAC1C,SAAS,iCAAiC;AAC1C,SAAS,sBAAsB;AAKxB,SAAS,mBAAmB,mBAA6D;AAC9F,QAAM,iBAAmC,CAAC;AAE1C,MAAI,CAAC,mBAAmB;AACtB,WAAO;AAAA,EACT;AAEA,aAAW,CAAC,YAAY,MAAM,KAAK,OAAO,QAAQ,iBAAiB,GAAG;AACpE,UAAM,UAAU,OAAO,WAAW,CAAC;AACnC,UAAM,OAAO,OAAO,QAAQ,CAAC;AAE7B,UAAM,EAAE,UAAU,aAAa,IAAI,OAAO,iBAAiB,0BAA0B,OAAO,MAAM;AAElG,mBAAe,KAAK;AAAA,MAClB,MAAM;AAAA,MACN,WAAW,0BAA0B,UAAU;AAAA,MAC/C;AAAA,MACA,eAAe,QAAQ,IAAI,WAAS,0BAA0B,KAAK,CAAC;AAAA,MACpE,aAAa,KAAK,eAAe;AAAA,MACjC,aAAa,KAAK,eAAe;AAAA,MACjC,qBAAqB,KAAK,uBAAuB;AAAA,MACjD,UAAU,KAAK,YAAY;AAAA,MAC3B,SAAS,KAAK,WAAW;AAAA,MACzB;AAAA,MACA,sBAAsB,KAAK,WAAW,eAAe,YAAY,KAAK;AAAA,MACtE,QAAQ,OAAO;AAAA,MACf,QAAQ,KAAK,UAAU;AAAA,IACzB,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,2 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/metadata/subcommands-metadata.ts
|
|
2
|
+
import { getArgumentsMetadata } from "./arguments-metadata.js";
|
|
3
|
+
import { getOptionsMetadata } from "./options-metadata.js";
|
|
4
|
+
function getSubcommandsMetadata(commandDefinition) {
|
|
5
|
+
const outputMetadata = [];
|
|
6
|
+
if (!commandDefinition || commandDefinition.length === 0) {
|
|
7
|
+
return outputMetadata;
|
|
8
|
+
}
|
|
9
|
+
for (const subcommand of commandDefinition) {
|
|
10
|
+
const optionsMetadata = subcommand.options ? getOptionsMetadata(subcommand.options) : [];
|
|
11
|
+
const argumentsMetadata = subcommand.arguments ? getArgumentsMetadata(subcommand.arguments) : [];
|
|
12
|
+
const meta = subcommand.meta ?? {};
|
|
13
|
+
outputMetadata.push({
|
|
14
|
+
name: subcommand.name,
|
|
15
|
+
aliases: subcommand.aliases ?? [],
|
|
16
|
+
description: meta.description ?? "",
|
|
17
|
+
descriptionMarkdown: meta.descriptionMarkdown ?? "",
|
|
18
|
+
placeholder: meta.placeholder ?? "",
|
|
19
|
+
usage: meta.usage ?? "",
|
|
20
|
+
example: meta.example ?? "",
|
|
21
|
+
allowPositionals: subcommand.allowPositionals ?? false,
|
|
22
|
+
options: optionsMetadata,
|
|
23
|
+
arguments: argumentsMetadata,
|
|
24
|
+
hidden: meta.hidden ?? false
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return outputMetadata;
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
getSubcommandsMetadata
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=subcommands-metadata.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/metadata/subcommands-metadata.ts"],
|
|
4
|
+
"sourcesContent": ["import { getArgumentsMetadata } from \"./arguments-metadata.ts\";\nimport { getOptionsMetadata } from \"./options-metadata.ts\";\n\nimport type { Subcommand } from \"../types/definitions-types.ts\";\nimport type { SubcommandMetadata } from \"../types/metadata-types.ts\";\n\nexport function getSubcommandsMetadata(commandDefinition: readonly Subcommand[]): SubcommandMetadata[] {\n const outputMetadata: SubcommandMetadata[] = [];\n\n if (!commandDefinition || commandDefinition.length === 0) {\n return outputMetadata;\n }\n\n for (const subcommand of commandDefinition) {\n const optionsMetadata = subcommand.options ? getOptionsMetadata(subcommand.options) : [];\n const argumentsMetadata = subcommand.arguments ? getArgumentsMetadata(subcommand.arguments) : [];\n const meta = subcommand.meta ?? {};\n\n outputMetadata.push({\n name: subcommand.name,\n aliases: subcommand.aliases ?? [],\n description: meta.description ?? \"\",\n descriptionMarkdown: meta.descriptionMarkdown ?? \"\",\n placeholder: meta.placeholder ?? \"\",\n usage: meta.usage ?? \"\",\n example: meta.example ?? \"\",\n allowPositionals: subcommand.allowPositionals ?? false,\n options: optionsMetadata,\n arguments: argumentsMetadata,\n hidden: meta.hidden ?? false,\n });\n }\n\n return outputMetadata;\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,4BAA4B;AACrC,SAAS,0BAA0B;AAK5B,SAAS,uBAAuB,mBAAgE;AACrG,QAAM,iBAAuC,CAAC;AAE9C,MAAI,CAAC,qBAAqB,kBAAkB,WAAW,GAAG;AACxD,WAAO;AAAA,EACT;AAEA,aAAW,cAAc,mBAAmB;AAC1C,UAAM,kBAAkB,WAAW,UAAU,mBAAmB,WAAW,OAAO,IAAI,CAAC;AACvF,UAAM,oBAAoB,WAAW,YAAY,qBAAqB,WAAW,SAAS,IAAI,CAAC;AAC/F,UAAM,OAAO,WAAW,QAAQ,CAAC;AAEjC,mBAAe,KAAK;AAAA,MAClB,MAAM,WAAW;AAAA,MACjB,SAAS,WAAW,WAAW,CAAC;AAAA,MAChC,aAAa,KAAK,eAAe;AAAA,MACjC,qBAAqB,KAAK,uBAAuB;AAAA,MACjD,aAAa,KAAK,eAAe;AAAA,MACjC,OAAO,KAAK,SAAS;AAAA,MACrB,SAAS,KAAK,WAAW;AAAA,MACzB,kBAAkB,WAAW,oBAAoB;AAAA,MACjD,SAAS;AAAA,MACT,WAAW;AAAA,MACX,QAAQ,KAAK,UAAU;AAAA,IACzB,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,2 +1,283 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/parse/context/cli-context-builder.ts
|
|
2
|
+
import { CliError } from "../../cli-error/cli-error.js";
|
|
3
|
+
import { ErrorCause } from "../../cli-error/error-cause.js";
|
|
4
|
+
import { InternalErrorCode } from "../../cli-error/error-code/internal-error-code.js";
|
|
5
|
+
import { ParseErrorCode } from "../../cli-error/error-code/parse-error-code.js";
|
|
6
|
+
import {
|
|
7
|
+
decoupleFlags,
|
|
8
|
+
findOption,
|
|
9
|
+
findSubcommandDefinition,
|
|
10
|
+
isFlagArgument,
|
|
11
|
+
isOptionArgument,
|
|
12
|
+
splitAndGetKeys
|
|
13
|
+
} from "../parser-utilities.js";
|
|
14
|
+
function buildCliContext(argv, cliDefinition) {
|
|
15
|
+
const cliName = cliDefinition.cliName;
|
|
16
|
+
const subcommandArray = cliDefinition.subcommands ?? [];
|
|
17
|
+
const allSubcommands = new Set(subcommandArray.flatMap((c) => [c.name, ...c.aliases || []]));
|
|
18
|
+
argv = decoupleFlags(argv);
|
|
19
|
+
const context = {
|
|
20
|
+
subcommand: void 0
|
|
21
|
+
};
|
|
22
|
+
const getCommandDefinition = () => findSubcommandDefinition(context.subcommand, cliDefinition);
|
|
23
|
+
for (let index = 0; index < argv.length; index++) {
|
|
24
|
+
const argvItem = argv[index];
|
|
25
|
+
if (index === 0) {
|
|
26
|
+
context.subcommand = allSubcommands.has(argvItem) ? argvItem : void 0;
|
|
27
|
+
if (context.subcommand) continue;
|
|
28
|
+
}
|
|
29
|
+
const argumentAndValue = argvItem.split("=").filter(Boolean);
|
|
30
|
+
const argumentWithEquals = argvItem.includes("=");
|
|
31
|
+
const [argument, keys] = splitAndGetKeys(argumentAndValue[0]);
|
|
32
|
+
const optionWithKeys = keys.length > 0;
|
|
33
|
+
const argumentValue = argumentAndValue[1];
|
|
34
|
+
const isNegated = argument.startsWith("--no-");
|
|
35
|
+
if (isOptionArgument(argument)) {
|
|
36
|
+
const commandDefinition3 = getCommandDefinition();
|
|
37
|
+
const commandKind = context.subcommand === void 0 ? "command" : "subcommand";
|
|
38
|
+
const commandName = context.subcommand ?? cliName;
|
|
39
|
+
if (isFlagArgument(argument) && argumentWithEquals) {
|
|
40
|
+
throw new CliError({
|
|
41
|
+
cause: ErrorCause.Parse,
|
|
42
|
+
code: ParseErrorCode.FlagAssignedValue,
|
|
43
|
+
context: { commandKind, commandName, flag: argument, value: argumentValue }
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if (!commandDefinition3) {
|
|
47
|
+
if (context.subcommand === void 0) {
|
|
48
|
+
throw new CliError({
|
|
49
|
+
cause: ErrorCause.Internal,
|
|
50
|
+
code: InternalErrorCode.CannotFindCliDefinition,
|
|
51
|
+
context: { cliName }
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
throw new CliError({
|
|
55
|
+
cause: ErrorCause.Parse,
|
|
56
|
+
code: ParseErrorCode.UnknownSubcommand,
|
|
57
|
+
context: { commandName }
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if (!commandDefinition3.options) {
|
|
61
|
+
throw new CliError({
|
|
62
|
+
cause: ErrorCause.Parse,
|
|
63
|
+
code: ParseErrorCode.CommandWithoutOptions,
|
|
64
|
+
context: { commandKind, commandName, optionName: argument }
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
const nameOptionTuple = findOption(argument, commandDefinition3.options);
|
|
68
|
+
if (!nameOptionTuple) {
|
|
69
|
+
throw new CliError({
|
|
70
|
+
cause: ErrorCause.Parse,
|
|
71
|
+
code: ParseErrorCode.UnknownOption,
|
|
72
|
+
context: { commandKind, commandName, optionName: argument }
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
const [optionName, optionDefinition] = nameOptionTuple;
|
|
76
|
+
if (!optionWithKeys && context.options && optionName in context.options) {
|
|
77
|
+
throw new CliError({
|
|
78
|
+
cause: ErrorCause.Parse,
|
|
79
|
+
code: ParseErrorCode.DuplicateOptionProvided,
|
|
80
|
+
context: { commandKind, commandName, optionName }
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (!optionDefinition._preparedType) {
|
|
84
|
+
throw new CliError({
|
|
85
|
+
cause: ErrorCause.Internal,
|
|
86
|
+
code: InternalErrorCode.MissingPreparedTypes,
|
|
87
|
+
context: { commandKind, commandName, kind: "option", name: optionName }
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
const { schema, optional, defaultValue, coerceTo } = optionDefinition._preparedType;
|
|
91
|
+
const nextArgument = argv[index + 1];
|
|
92
|
+
let optionValue = argumentWithEquals ? argumentValue : nextArgument;
|
|
93
|
+
const isBoolean = coerceTo === "boolean";
|
|
94
|
+
if (isNegated && !isBoolean) {
|
|
95
|
+
throw new CliError({
|
|
96
|
+
cause: ErrorCause.Parse,
|
|
97
|
+
code: ParseErrorCode.InvalidNegationForNonBooleanOption,
|
|
98
|
+
context: { commandKind, commandName, optionName }
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if (isBoolean) {
|
|
102
|
+
if (!argumentWithEquals) {
|
|
103
|
+
optionValue = "true";
|
|
104
|
+
}
|
|
105
|
+
if (isNegated && ["true", "false"].includes(optionValue.toLowerCase())) {
|
|
106
|
+
optionValue = optionValue === "true" ? "false" : "true";
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (optionValue === void 0 || !argumentWithEquals && isOptionArgument(optionValue)) {
|
|
110
|
+
throw new CliError({
|
|
111
|
+
cause: ErrorCause.Parse,
|
|
112
|
+
code: ParseErrorCode.OptionMissingValue,
|
|
113
|
+
context: { commandKind, commandName, optionName }
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
context.options ??= {};
|
|
117
|
+
if (optionWithKeys) {
|
|
118
|
+
const previousObject = JSON.parse(context.options[optionName]?.stringValue || "{}");
|
|
119
|
+
let current = previousObject;
|
|
120
|
+
for (let index2 = 0; index2 < keys.length; index2++) {
|
|
121
|
+
const key = keys[index2];
|
|
122
|
+
if (current[key] === void 0) {
|
|
123
|
+
current[key] = {};
|
|
124
|
+
}
|
|
125
|
+
if (index2 === keys.length - 1) {
|
|
126
|
+
current[key] = optionValue;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
current = current[key];
|
|
130
|
+
}
|
|
131
|
+
optionValue = JSON.stringify(previousObject);
|
|
132
|
+
}
|
|
133
|
+
context.options[optionName] = {
|
|
134
|
+
schema,
|
|
135
|
+
optional,
|
|
136
|
+
defaultValue,
|
|
137
|
+
flag: argument,
|
|
138
|
+
stringValue: optionValue,
|
|
139
|
+
source: "terminal"
|
|
140
|
+
};
|
|
141
|
+
if (!argumentWithEquals && !isBoolean) {
|
|
142
|
+
index++;
|
|
143
|
+
}
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const commandDefinition2 = getCommandDefinition();
|
|
147
|
+
if (commandDefinition2?.arguments) {
|
|
148
|
+
context.arguments ??= {};
|
|
149
|
+
const currentArgumentCount = Object.keys(context.arguments).length;
|
|
150
|
+
const argumentDefinitionEntries = Object.entries(commandDefinition2.arguments);
|
|
151
|
+
if (currentArgumentCount < argumentDefinitionEntries.length) {
|
|
152
|
+
const [name, argumentDefinition] = argumentDefinitionEntries[currentArgumentCount];
|
|
153
|
+
if (!argumentDefinition._preparedType) {
|
|
154
|
+
throw new CliError({
|
|
155
|
+
cause: ErrorCause.Internal,
|
|
156
|
+
code: InternalErrorCode.MissingPreparedTypes,
|
|
157
|
+
context: {
|
|
158
|
+
commandKind: context.subcommand ? "subcommand" : "command",
|
|
159
|
+
commandName: context.subcommand ?? cliName,
|
|
160
|
+
kind: "argument",
|
|
161
|
+
name
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
const { schema, optional, defaultValue } = argumentDefinition._preparedType;
|
|
166
|
+
context.arguments[name] = { schema, optional, defaultValue, stringValue: argvItem, source: "terminal" };
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (commandDefinition2?.allowPositionals) {
|
|
171
|
+
context.positionals ??= [];
|
|
172
|
+
context.positionals.push(argvItem);
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
throw new CliError({
|
|
176
|
+
cause: ErrorCause.Parse,
|
|
177
|
+
code: ParseErrorCode.PositionalArgumentNotAllowed,
|
|
178
|
+
context: {
|
|
179
|
+
commandKind: context.subcommand ? "subcommand" : "command",
|
|
180
|
+
commandName: context.subcommand ?? cliName,
|
|
181
|
+
argumentName: argvItem
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
const commandDefinition = getCommandDefinition();
|
|
186
|
+
if (!commandDefinition) {
|
|
187
|
+
if (context.subcommand === void 0) {
|
|
188
|
+
throw new CliError({
|
|
189
|
+
cause: ErrorCause.Internal,
|
|
190
|
+
code: InternalErrorCode.CannotFindCliDefinition,
|
|
191
|
+
context: { cliName }
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
throw new CliError({
|
|
195
|
+
cause: ErrorCause.Parse,
|
|
196
|
+
code: ParseErrorCode.UnknownSubcommand,
|
|
197
|
+
context: { commandName: context.subcommand ?? cliName }
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
if (commandDefinition.options) {
|
|
201
|
+
context.options ??= {};
|
|
202
|
+
for (const [name, optionDefinition] of Object.entries(commandDefinition.options)) {
|
|
203
|
+
if (name in context.options) continue;
|
|
204
|
+
if (!optionDefinition._preparedType) {
|
|
205
|
+
throw new CliError({
|
|
206
|
+
cause: ErrorCause.Internal,
|
|
207
|
+
code: InternalErrorCode.MissingPreparedTypes,
|
|
208
|
+
context: {
|
|
209
|
+
commandKind: context.subcommand ? "subcommand" : "command",
|
|
210
|
+
commandName: context.subcommand ?? cliName,
|
|
211
|
+
kind: "option",
|
|
212
|
+
name
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
const { schema, optional, defaultValue } = optionDefinition._preparedType;
|
|
217
|
+
if (optional) {
|
|
218
|
+
if (defaultValue === void 0) {
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
context.options[name] = { schema, optional, defaultValue, source: "default" };
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
throw new CliError({
|
|
225
|
+
cause: ErrorCause.Parse,
|
|
226
|
+
code: ParseErrorCode.MissingRequiredOption,
|
|
227
|
+
context: {
|
|
228
|
+
commandKind: context.subcommand ? "subcommand" : "command",
|
|
229
|
+
commandName: context.subcommand ?? cliName,
|
|
230
|
+
optionName: name
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (commandDefinition.arguments) {
|
|
236
|
+
context.arguments ??= {};
|
|
237
|
+
const currentArgumentCount = Object.keys(context.arguments).length;
|
|
238
|
+
const argumentDefinitionEntries = Object.entries(commandDefinition.arguments);
|
|
239
|
+
const argumentsDefinitionLength = argumentDefinitionEntries.length;
|
|
240
|
+
if (currentArgumentCount < argumentsDefinitionLength) {
|
|
241
|
+
for (let index = currentArgumentCount; index < argumentsDefinitionLength; index++) {
|
|
242
|
+
const [name, argumentDefinition] = argumentDefinitionEntries[index];
|
|
243
|
+
if (!argumentDefinition._preparedType) {
|
|
244
|
+
throw new CliError({
|
|
245
|
+
cause: ErrorCause.Internal,
|
|
246
|
+
code: InternalErrorCode.MissingPreparedTypes,
|
|
247
|
+
context: {
|
|
248
|
+
commandKind: context.subcommand ? "subcommand" : "command",
|
|
249
|
+
commandName: context.subcommand ?? cliName,
|
|
250
|
+
kind: "argument",
|
|
251
|
+
name
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
const { schema, optional, defaultValue } = argumentDefinition._preparedType;
|
|
256
|
+
if (optional) {
|
|
257
|
+
if (defaultValue === void 0) {
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
context.arguments[name] = { schema, optional, defaultValue, source: "default" };
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
throw new CliError({
|
|
264
|
+
cause: ErrorCause.Parse,
|
|
265
|
+
code: ParseErrorCode.MissingRequiredArgument,
|
|
266
|
+
context: {
|
|
267
|
+
commandKind: context.subcommand ? "subcommand" : "command",
|
|
268
|
+
commandName: context.subcommand ?? cliName,
|
|
269
|
+
argumentName: name
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
if (commandDefinition.allowPositionals) {
|
|
276
|
+
context.positionals ??= [];
|
|
277
|
+
}
|
|
278
|
+
return context;
|
|
279
|
+
}
|
|
280
|
+
export {
|
|
281
|
+
buildCliContext
|
|
282
|
+
};
|
|
283
|
+
//# sourceMappingURL=cli-context-builder.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"names":["decoupleFlags","findOption","findSubcommandDefinition","isFlagArgument","isOptionArgument","transformOptionToArgument","buildCliContext","argv","cliDefinition","subcommandArray","subcommands","allSubcommands","Set","flatMap","c","name","aliases","context","subcommand","getCommandDefinition","index","length","argvItem","has","argumentAndValue","split","filter","Boolean","argumentWithEquals","includes","argument","argumentValue","Error","commandDefinition","options","nameOptionTuple","optionName","optionDefinition","_preparedType","schema","optional","defaultValue","coerceTo","nextArgument","optionValue","startsWith","toLowerCase","flag","stringValue","source","arguments","currentArgumentCount","Object","keys","argumentDefinitionEntries","entries","argumentDefinition","allowPositionals","positionals","push","argumentsDefinitionLength"],"sources":["../../../../src/parse/context/cli-context-builder.ts"],"sourcesContent":["import {\n decoupleFlags,\n findOption,\n findSubcommandDefinition,\n isFlagArgument,\n isOptionArgument,\n transformOptionToArgument,\n} from \"../parser-utilities.ts\";\n\nimport type { ContextWide } from \"../../types/context-types.ts\";\nimport type { Cli } from \"../../types/definitions-types.ts\";\n\n/**\n * Parse argv and create a cli context\n *\n * @throws {Error}\n */\nexport function buildCliContext(argv: string[], cliDefinition: Cli) {\n const subcommandArray = cliDefinition.subcommands ?? [];\n const allSubcommands = new Set<string>(subcommandArray.flatMap(c => [c.name, ...(c.aliases || [])]));\n\n // decouple flags E.g. `-rf` -> `-r, -f`\n argv = decoupleFlags(argv);\n\n const context: ContextWide = {\n subcommand: undefined,\n };\n\n /** Get the current subcommand definition or cli definition if subcommand name is `undefined` object */\n const getCommandDefinition = () => findSubcommandDefinition(context.subcommand, cliDefinition);\n\n for (let index = 0; index < argv.length; index++) {\n const argvItem = argv[index];\n\n // * Subcommand check\n if (index === 0) {\n context.subcommand = allSubcommands.has(argvItem) ? argvItem : undefined;\n\n // First argument is a subcommand. Skip to the next argument\n if (context.subcommand) continue;\n }\n\n // * Option check\n\n const argumentAndValue = argvItem.split(\"=\").filter(Boolean); // E.g --option=value -> [\"--option\", \"value\"]\n const argumentWithEquals = argvItem.includes(\"=\"); // E.g --option=value\n const argument = argumentAndValue[0];\n const argumentValue: string | undefined = argumentAndValue[1];\n\n if (isOptionArgument(argument)) {\n if (isFlagArgument(argument) && argumentWithEquals) {\n throw new Error(`flag arguments cannot be assigned using \"=\": \"${argvItem}\"`);\n }\n\n const commandDefinition = getCommandDefinition();\n if (!commandDefinition) {\n throw new Error(`unknown subcommand: \"${context.subcommand}\"`);\n }\n\n if (!commandDefinition.options) {\n if (!context.subcommand) {\n throw new Error(`options are not allowed here: \"${argument}\"`);\n }\n\n throw new Error(`subcommand \"${context.subcommand}\" does not accept options: \"${argument}\"`);\n }\n\n const nameOptionTuple = findOption(argument, commandDefinition.options);\n if (!nameOptionTuple) {\n throw new Error(`unknown option: \"${argument}\"`);\n }\n\n const [optionName, optionDefinition] = nameOptionTuple;\n\n if (context.options && optionName in context.options) {\n throw new Error(`duplicated option: \"${argument}\"`);\n }\n\n if (!optionDefinition._preparedType) {\n throw new Error(`internal error: missing prepared type for option \"${optionName}\"`);\n }\n\n const { schema, optional, defaultValue, coerceTo } = optionDefinition._preparedType;\n\n const nextArgument = argv[index + 1];\n\n let optionValue: string | boolean = argumentWithEquals ? argumentValue : nextArgument;\n\n // infer value for boolean options\n if (coerceTo === \"boolean\") {\n if (!argumentWithEquals) {\n optionValue = \"true\";\n }\n\n const isNegated = argument.startsWith(\"--no-\");\n\n if (isNegated && [\"true\", \"false\"].includes(optionValue.toLowerCase())) {\n optionValue = optionValue === \"true\" ? \"false\" : \"true\";\n }\n }\n\n if (optionValue === undefined) {\n throw new Error(`expected a value for \"${argument}\" but got nothing`);\n }\n\n if (!argumentWithEquals && isOptionArgument(optionValue)) {\n throw new Error(`expected a value for \"${argument}\" but got an argument \"${nextArgument}\"`);\n }\n\n context.options ??= {};\n context.options[optionName] = {\n schema,\n optional,\n defaultValue,\n flag: argument,\n stringValue: optionValue,\n source: \"terminal\",\n };\n\n // Skip to the next argument if it is the current option's value.\n if (!argumentWithEquals && coerceTo !== \"boolean\") {\n index++;\n }\n\n continue;\n }\n\n const commandDefinition = getCommandDefinition();\n\n // * Arguments check\n if (commandDefinition?.arguments) {\n context.arguments ??= {};\n\n const currentArgumentCount = Object.keys(context.arguments).length;\n const argumentDefinitionEntries = Object.entries(commandDefinition.arguments);\n\n // The current argument is a typed argument and not a positional\n if (currentArgumentCount < argumentDefinitionEntries.length) {\n const [name, argumentDefinition] = argumentDefinitionEntries[currentArgumentCount];\n\n if (!argumentDefinition._preparedType) {\n throw new Error(`internal error: missing prepared type for argument \"${currentArgumentCount}\"`);\n }\n\n const { schema, optional, defaultValue } = argumentDefinition._preparedType;\n\n context.arguments[name] = { schema, optional, defaultValue, stringValue: argvItem, source: \"terminal\" };\n continue;\n }\n }\n\n // The current argument is a positional and not a typed argument (when `allowPositionals` is enabled)\n if (commandDefinition?.allowPositionals) {\n context.positionals ??= [];\n context.positionals.push(argvItem);\n continue;\n }\n\n if (!context.subcommand) {\n throw new Error(`unexpected argument \"${argvItem}\": positionals arguments are not allowed here`);\n }\n\n throw new Error(\n `unexpected argument \"${argvItem}\": positionals arguments are not allowed for subcommand \"${context.subcommand}\"`,\n );\n }\n\n const commandDefinition = getCommandDefinition();\n if (!commandDefinition) {\n throw new Error(`unknown subcommand: \"${context.subcommand}\"`);\n }\n\n // Options\n if (commandDefinition.options) {\n context.options ??= {};\n\n for (const [name, optionDefinition] of Object.entries(commandDefinition.options)) {\n // option already added to the context (found during argument parsing)\n if (name in context.options) continue;\n\n if (!optionDefinition._preparedType) {\n throw new Error(`internal error: missing prepared type for option \"${name}\"`);\n }\n\n const { schema, optional, defaultValue } = optionDefinition._preparedType;\n\n if (optional) {\n // optional without default value\n if (defaultValue === undefined) {\n continue;\n }\n\n // optional with default value\n context.options[name] = { schema, optional, defaultValue, source: \"default\" };\n continue;\n }\n\n // required option\n throw new Error(`missing required option: ${transformOptionToArgument(name)}`);\n }\n }\n\n // Arguments\n if (commandDefinition.arguments) {\n context.arguments ??= {};\n\n const currentArgumentCount = Object.keys(context.arguments).length;\n\n const argumentDefinitionEntries = Object.entries(commandDefinition.arguments);\n const argumentsDefinitionLength = argumentDefinitionEntries.length;\n\n // missing arguments\n if (currentArgumentCount < argumentsDefinitionLength) {\n for (let index = currentArgumentCount; index < argumentsDefinitionLength; index++) {\n const [name, argumentDefinition] = argumentDefinitionEntries[index];\n\n if (!argumentDefinition._preparedType) {\n throw new Error(`internal error: missing prepared type for the argument \"${name}\"`);\n }\n\n const { schema, optional, defaultValue } = argumentDefinition._preparedType;\n\n if (optional) {\n // optional argument without default value\n if (defaultValue === undefined) {\n continue;\n }\n\n // optional argument with default value\n context.arguments[name] = { schema, optional, defaultValue, source: \"default\" };\n continue;\n }\n\n // required argument\n throw new Error(`The argument \"${name}\" is required`);\n }\n }\n }\n\n // make sure `positionals` is defined when `allowPositionals` is enabled\n if (commandDefinition.allowPositionals) {\n context.positionals ??= [];\n }\n\n return context;\n}\n"],"mappings":"OACEA,cACAC,WACAC,yBACAC,eACAC,iBACAC,8BACK,yBAUA,SAASC,gBAAgBC,EAAgBC,GAC9C,MAAMC,EAAkBD,EAAcE,aAAe,GAC/CC,EAAiB,IAAIC,IAAYH,EAAgBI,QAAQC,GAAK,CAACA,EAAEC,QAAUD,EAAEE,SAAW,MAG9FT,EAAOP,cAAcO,GAErB,MAAMU,EAAuB,CAC3BC,gBAAY,GAIRC,EAAuB,IAAMjB,yBAAyBe,EAAQC,WAAYV,GAEhF,QAASY,EAAQ,EAAGA,EAAQb,EAAKc,OAAQD,IAAS,CAChD,MAAME,EAAWf,EAAKa,GAGtB,GAAc,IAAVA,IACFH,EAAQC,WAAaP,EAAeY,IAAID,GAAYA,OAAW,EAG3DL,EAAQC,YAAY,SAK1B,MAAMM,EAAmBF,EAASG,MAAM,KAAKC,OAAOC,SAC9CC,EAAqBN,EAASO,SAAS,KACvCC,EAAWN,EAAiB,GAC5BO,EAAoCP,EAAiB,GAE3D,GAAIpB,iBAAiB0B,GAAW,CAC9B,GAAI3B,eAAe2B,IAAaF,EAC9B,MAAM,IAAII,MAAM,iDAAiDV,MAGnE,MAAMW,EAAoBd,IAC1B,IAAKc,EACH,MAAM,IAAID,MAAM,wBAAwBf,EAAQC,eAGlD,IAAKe,EAAkBC,QAAS,CAC9B,IAAKjB,EAAQC,WACX,MAAM,IAAIc,MAAM,kCAAkCF,MAGpD,MAAM,IAAIE,MAAM,eAAef,EAAQC,yCAAyCY,KAClF,CAEA,MAAMK,EAAkBlC,WAAW6B,EAAUG,EAAkBC,SAC/D,IAAKC,EACH,MAAM,IAAIH,MAAM,oBAAoBF,MAGtC,MAAOM,EAAYC,GAAoBF,EAEvC,GAA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,EAAmBlB,cAE9D,IAAIE,EAYJ,MAAM,IAAIR,MAAM,iBAAiBjB,uBAVV,IAAjB0B,IAKJxB,EAAQiC,UAAUnC,GAAQ,CAAEwB,SAAQC,WAAUC,eAAcQ,OAAQ,WAMxE,CAEJ,CAOA,OAJIhB,EAAkBwB,mBACpBxC,EAAQyC,cAARzC,EAAQyC,YAAgB,KAGnBzC,CACT,Q","ignoreList":[]}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/parse/context/cli-context-builder.ts"],
|
|
4
|
+
"sourcesContent": ["import { CliError } from \"../../cli-error/cli-error.ts\";\nimport { ErrorCause } from \"../../cli-error/error-cause.ts\";\nimport { InternalErrorCode } from \"../../cli-error/error-code/internal-error-code.ts\";\nimport { ParseErrorCode } from \"../../cli-error/error-code/parse-error-code.ts\";\nimport {\n decoupleFlags,\n findOption,\n findSubcommandDefinition,\n isFlagArgument,\n isOptionArgument,\n splitAndGetKeys,\n} from \"../parser-utilities.ts\";\n\nimport type { ContextWide } from \"../../types/context-types.ts\";\nimport type { Cli } from \"../../types/definitions-types.ts\";\n\n/**\n * Parse argv and create a cli context\n *\n * @throws {CliError}\n */\nexport function buildCliContext(argv: string[], cliDefinition: Cli) {\n const cliName = cliDefinition.cliName;\n const subcommandArray = cliDefinition.subcommands ?? [];\n const allSubcommands = new Set<string>(subcommandArray.flatMap(c => [c.name, ...(c.aliases || [])]));\n\n // decouple flags E.g. `-rf` -> `-r, -f`\n argv = decoupleFlags(argv);\n\n const context: ContextWide = {\n subcommand: undefined,\n };\n\n /** Get the current subcommand definition or cli definition if subcommand name is `undefined` object */\n const getCommandDefinition = () => findSubcommandDefinition(context.subcommand, cliDefinition);\n\n for (let index = 0; index < argv.length; index++) {\n const argvItem = argv[index];\n\n // * Subcommand check\n if (index === 0) {\n context.subcommand = allSubcommands.has(argvItem) ? argvItem : undefined;\n\n // First argument is a subcommand. Skip to the next argument\n if (context.subcommand) continue;\n }\n\n // * Option check\n\n const argumentAndValue = argvItem.split(\"=\").filter(Boolean); // E.g --option=value -> [\"--option\", \"value\"]\n const argumentWithEquals = argvItem.includes(\"=\"); // E.g --option=value\n const [argument, keys] = splitAndGetKeys(argumentAndValue[0]); // E.g --option.foo.bar -> [\"--option\", [\"foo\", \"bar\"]]\n const optionWithKeys = keys.length > 0; // E.g --option.foo.bar\n const argumentValue: string | undefined = argumentAndValue[1];\n const isNegated = argument.startsWith(\"--no-\");\n\n if (isOptionArgument(argument)) {\n const commandDefinition = getCommandDefinition();\n const commandKind = context.subcommand === undefined ? \"command\" : \"subcommand\";\n const commandName = context.subcommand ?? cliName;\n\n if (isFlagArgument(argument) && argumentWithEquals) {\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.FlagAssignedValue,\n context: { commandKind, commandName, flag: argument, value: argumentValue },\n });\n }\n\n if (!commandDefinition) {\n if (context.subcommand === undefined) {\n throw new CliError({\n cause: ErrorCause.Internal,\n code: InternalErrorCode.CannotFindCliDefinition,\n context: { cliName },\n });\n }\n\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.UnknownSubcommand,\n context: { commandName },\n });\n }\n\n if (!commandDefinition.options) {\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.CommandWithoutOptions,\n context: { commandKind, commandName, optionName: argument },\n });\n }\n\n const nameOptionTuple = findOption(argument, commandDefinition.options);\n if (!nameOptionTuple) {\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.UnknownOption,\n context: { commandKind, commandName, optionName: argument },\n });\n }\n\n const [optionName, optionDefinition] = nameOptionTuple;\n\n if (!optionWithKeys && context.options && optionName in context.options) {\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.DuplicateOptionProvided,\n context: { commandKind, commandName, optionName },\n });\n }\n\n if (!optionDefinition._preparedType) {\n throw new CliError({\n cause: ErrorCause.Internal,\n code: InternalErrorCode.MissingPreparedTypes,\n context: { commandKind, commandName, kind: \"option\", name: optionName },\n });\n }\n\n const { schema, optional, defaultValue, coerceTo } = optionDefinition._preparedType;\n\n const nextArgument = argv[index + 1];\n\n let optionValue: string | boolean | undefined = argumentWithEquals ? argumentValue : nextArgument;\n\n const isBoolean = coerceTo === \"boolean\";\n\n if (isNegated && !isBoolean) {\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.InvalidNegationForNonBooleanOption,\n context: { commandKind, commandName, optionName },\n });\n }\n\n // infer value for boolean options\n if (isBoolean) {\n if (!argumentWithEquals) {\n optionValue = \"true\";\n }\n\n if (isNegated && [\"true\", \"false\"].includes(optionValue.toLowerCase())) {\n optionValue = optionValue === \"true\" ? \"false\" : \"true\";\n }\n }\n\n if (optionValue === undefined || (!argumentWithEquals && isOptionArgument(optionValue))) {\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.OptionMissingValue,\n context: { commandKind, commandName, optionName },\n });\n }\n\n context.options ??= {};\n\n // Handle options with keys for type `object`\n // E.g. `--option.key.nested=value`\n if (optionWithKeys) {\n const previousObject = JSON.parse(context.options[optionName]?.stringValue || \"{}\") as Record<string, any>;\n\n let current = previousObject;\n for (let index = 0; index < keys.length; index++) {\n const key = keys[index];\n\n if (current[key] === undefined) {\n current[key] = {};\n }\n\n if (index === keys.length - 1) {\n current[key] = optionValue;\n continue;\n }\n\n current = current[key] as Record<string, any>;\n }\n\n optionValue = JSON.stringify(previousObject);\n }\n\n context.options[optionName] = {\n schema,\n optional,\n defaultValue,\n flag: argument,\n stringValue: optionValue,\n source: \"terminal\",\n };\n\n // Skip to the next argument if it is the current option's value.\n if (!argumentWithEquals && !isBoolean) {\n index++;\n }\n\n continue;\n }\n\n const commandDefinition = getCommandDefinition();\n\n // * Arguments check\n if (commandDefinition?.arguments) {\n context.arguments ??= {};\n\n const currentArgumentCount = Object.keys(context.arguments).length;\n const argumentDefinitionEntries = Object.entries(commandDefinition.arguments);\n\n // The current argument is a typed argument and not a positional\n if (currentArgumentCount < argumentDefinitionEntries.length) {\n const [name, argumentDefinition] = argumentDefinitionEntries[currentArgumentCount];\n\n if (!argumentDefinition._preparedType) {\n throw new CliError({\n cause: ErrorCause.Internal,\n code: InternalErrorCode.MissingPreparedTypes,\n context: {\n commandKind: context.subcommand ? \"subcommand\" : \"command\",\n commandName: context.subcommand ?? cliName,\n kind: \"argument\",\n name,\n },\n });\n }\n\n const { schema, optional, defaultValue } = argumentDefinition._preparedType;\n\n context.arguments[name] = { schema, optional, defaultValue, stringValue: argvItem, source: \"terminal\" };\n continue;\n }\n }\n\n // The current argument is a positional and not a typed argument (when `allowPositionals` is enabled)\n if (commandDefinition?.allowPositionals) {\n context.positionals ??= [];\n context.positionals.push(argvItem);\n continue;\n }\n\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.PositionalArgumentNotAllowed,\n context: {\n commandKind: context.subcommand ? \"subcommand\" : \"command\",\n commandName: context.subcommand ?? cliName,\n argumentName: argvItem,\n },\n });\n }\n\n const commandDefinition = getCommandDefinition();\n if (!commandDefinition) {\n if (context.subcommand === undefined) {\n throw new CliError({\n cause: ErrorCause.Internal,\n code: InternalErrorCode.CannotFindCliDefinition,\n context: { cliName },\n });\n }\n\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.UnknownSubcommand,\n context: { commandName: context.subcommand ?? cliName },\n });\n }\n\n // Options\n if (commandDefinition.options) {\n context.options ??= {};\n\n for (const [name, optionDefinition] of Object.entries(commandDefinition.options)) {\n // option already added to the context (found during argument parsing)\n if (name in context.options) continue;\n\n if (!optionDefinition._preparedType) {\n throw new CliError({\n cause: ErrorCause.Internal,\n code: InternalErrorCode.MissingPreparedTypes,\n context: {\n commandKind: context.subcommand ? \"subcommand\" : \"command\",\n commandName: context.subcommand ?? cliName,\n kind: \"option\",\n name,\n },\n });\n }\n\n const { schema, optional, defaultValue } = optionDefinition._preparedType;\n\n if (optional) {\n // optional without default value\n if (defaultValue === undefined) {\n continue;\n }\n\n // optional with default value\n context.options[name] = { schema, optional, defaultValue, source: \"default\" };\n continue;\n }\n\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.MissingRequiredOption,\n context: {\n commandKind: context.subcommand ? \"subcommand\" : \"command\",\n commandName: context.subcommand ?? cliName,\n optionName: name,\n },\n });\n }\n }\n\n // Arguments\n if (commandDefinition.arguments) {\n context.arguments ??= {};\n\n const currentArgumentCount = Object.keys(context.arguments).length;\n\n const argumentDefinitionEntries = Object.entries(commandDefinition.arguments);\n const argumentsDefinitionLength = argumentDefinitionEntries.length;\n\n // missing arguments\n if (currentArgumentCount < argumentsDefinitionLength) {\n for (let index = currentArgumentCount; index < argumentsDefinitionLength; index++) {\n const [name, argumentDefinition] = argumentDefinitionEntries[index];\n\n if (!argumentDefinition._preparedType) {\n throw new CliError({\n cause: ErrorCause.Internal,\n code: InternalErrorCode.MissingPreparedTypes,\n context: {\n commandKind: context.subcommand ? \"subcommand\" : \"command\",\n commandName: context.subcommand ?? cliName,\n kind: \"argument\",\n name,\n },\n });\n }\n\n const { schema, optional, defaultValue } = argumentDefinition._preparedType;\n\n if (optional) {\n // optional argument without default value\n if (defaultValue === undefined) {\n continue;\n }\n\n // optional argument with default value\n context.arguments[name] = { schema, optional, defaultValue, source: \"default\" };\n continue;\n }\n\n // required argument\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.MissingRequiredArgument,\n context: {\n commandKind: context.subcommand ? \"subcommand\" : \"command\",\n commandName: context.subcommand ?? cliName,\n argumentName: name,\n },\n });\n }\n }\n }\n\n // make sure `positionals` is defined when `allowPositionals` is enabled\n if (commandDefinition.allowPositionals) {\n context.positionals ??= [];\n }\n\n return context;\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,yBAAyB;AAClC,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,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