zod-args-parser 2.0.0-beta.1 → 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/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/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 +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,2 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/parse/context/object-context-builder.ts
|
|
2
|
+
import { CliError } from "../../cli-error/cli-error.mjs";
|
|
3
|
+
import { ErrorCause } from "../../cli-error/error-cause.mjs";
|
|
4
|
+
import { InternalErrorCode } from "../../cli-error/error-code/internal-error-code.mjs";
|
|
5
|
+
import { ParseErrorCode } from "../../cli-error/error-code/parse-error-code.mjs";
|
|
6
|
+
function buildObjectContext(inputValues, commandDefinition) {
|
|
7
|
+
const context = {
|
|
8
|
+
subcommand: "cliName" in commandDefinition ? void 0 : commandDefinition.name
|
|
9
|
+
};
|
|
10
|
+
buildForOptionsOrArguments(commandDefinition, context, inputValues.options, "options");
|
|
11
|
+
buildForOptionsOrArguments(commandDefinition, context, inputValues.arguments, "arguments");
|
|
12
|
+
if (commandDefinition.allowPositionals) {
|
|
13
|
+
context.positionals ??= inputValues.positionals;
|
|
14
|
+
}
|
|
15
|
+
return context;
|
|
16
|
+
}
|
|
17
|
+
function buildForOptionsOrArguments(commandDefinition, context, inputRecord, type) {
|
|
18
|
+
if (!commandDefinition[type]) return;
|
|
19
|
+
const optionOrArgumentDefinitions = commandDefinition[type];
|
|
20
|
+
const kind = type.slice(0, -1);
|
|
21
|
+
const commandKind = "cliName" in commandDefinition ? "command" : "subcommand";
|
|
22
|
+
const commandName = "cliName" in commandDefinition ? commandDefinition.cliName : commandDefinition.name;
|
|
23
|
+
const definitionEntries = Object.entries(optionOrArgumentDefinitions);
|
|
24
|
+
for (const [name, definition] of definitionEntries) {
|
|
25
|
+
if (!definition._preparedType) {
|
|
26
|
+
throw new CliError({
|
|
27
|
+
cause: ErrorCause.Internal,
|
|
28
|
+
code: InternalErrorCode.MissingPreparedTypes,
|
|
29
|
+
context: { commandKind, commandName, kind, name }
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const { schema, optional, defaultValue } = definition._preparedType;
|
|
33
|
+
if (inputRecord && name in inputRecord) {
|
|
34
|
+
const passedValue = inputRecord[name];
|
|
35
|
+
context[type] ??= {};
|
|
36
|
+
context[type][name] = passedValue === void 0 ? { schema, optional, defaultValue, source: "default" } : { schema, optional, defaultValue, passedValue, source: "programmatic" };
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (!optional) {
|
|
40
|
+
if (kind === "option") {
|
|
41
|
+
throw new CliError({
|
|
42
|
+
cause: ErrorCause.Parse,
|
|
43
|
+
code: ParseErrorCode.MissingRequiredOption,
|
|
44
|
+
context: { commandKind, commandName, optionName: name }
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
if (kind === "argument") {
|
|
48
|
+
throw new CliError({
|
|
49
|
+
cause: ErrorCause.Parse,
|
|
50
|
+
code: ParseErrorCode.MissingRequiredArgument,
|
|
51
|
+
context: { commandKind, commandName, argumentName: name }
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
context[type] ??= {};
|
|
56
|
+
context[type][name] = { schema, optional, defaultValue, source: "default" };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export {
|
|
60
|
+
buildObjectContext
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=object-context-builder.mjs.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/parse/context/object-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\";\n\nimport type { ContextWide } from \"../../types/context-types.ts\";\nimport type { Argument, Cli, Option, Subcommand } from \"../../types/definitions-types.ts\";\nimport type { InputTypeWide } from \"../../types/io-types.ts\";\n\n/** @throws {CliError} */\nexport function buildObjectContext(inputValues: InputTypeWide, commandDefinition: Subcommand | Cli) {\n const context: ContextWide = {\n subcommand: \"cliName\" in commandDefinition ? undefined : commandDefinition.name,\n };\n\n buildForOptionsOrArguments(commandDefinition, context, inputValues.options, \"options\");\n\n buildForOptionsOrArguments(commandDefinition, context, inputValues.arguments, \"arguments\");\n\n if (commandDefinition.allowPositionals) {\n context.positionals ??= inputValues.positionals;\n }\n\n return context;\n}\n\nfunction buildForOptionsOrArguments(\n commandDefinition: Subcommand | Cli,\n context: ContextWide,\n inputRecord: Record<string, unknown> | undefined,\n type: \"options\" | \"arguments\",\n) {\n if (!commandDefinition[type]) return;\n\n const optionOrArgumentDefinitions = commandDefinition[type];\n const kind = type.slice(0, -1) as \"option\" | \"argument\";\n const commandKind = \"cliName\" in commandDefinition ? \"command\" : \"subcommand\";\n const commandName = \"cliName\" in commandDefinition ? commandDefinition.cliName : commandDefinition.name;\n\n const definitionEntries = Object.entries(optionOrArgumentDefinitions) as [string, Option][] | [string, Argument][];\n\n for (const [name, definition] of definitionEntries) {\n if (!definition._preparedType) {\n throw new CliError({\n cause: ErrorCause.Internal,\n code: InternalErrorCode.MissingPreparedTypes,\n context: { commandKind, commandName, kind, name },\n });\n }\n\n const { schema, optional, defaultValue } = definition._preparedType;\n\n // Case the value is passed\n if (inputRecord && name in inputRecord) {\n const passedValue = inputRecord[name];\n\n context[type] ??= {};\n context[type][name] =\n passedValue === undefined\n ? { schema, optional, defaultValue, source: \"default\" }\n : { schema, optional, defaultValue, passedValue, source: \"programmatic\" };\n\n continue;\n }\n\n // case the value is not passed\n if (!optional) {\n if (kind === \"option\") {\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.MissingRequiredOption,\n context: { commandKind, commandName, optionName: name },\n });\n }\n\n if (kind === \"argument\") {\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.MissingRequiredArgument,\n context: { commandKind, commandName, argumentName: name },\n });\n }\n }\n\n // case the value is optional\n context[type] ??= {};\n context[type][name] = { schema, optional, defaultValue, source: \"default\" };\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,yBAAyB;AAClC,SAAS,sBAAsB;AAOxB,SAAS,mBAAmB,aAA4B,mBAAqC;AAClG,QAAM,UAAuB;AAAA,IAC3B,YAAY,aAAa,oBAAoB,SAAY,kBAAkB;AAAA,EAC7E;AAEA,6BAA2B,mBAAmB,SAAS,YAAY,SAAS,SAAS;AAErF,6BAA2B,mBAAmB,SAAS,YAAY,WAAW,WAAW;AAEzF,MAAI,kBAAkB,kBAAkB;AACtC,YAAQ,gBAAgB,YAAY;AAAA,EACtC;AAEA,SAAO;AACT;AAEA,SAAS,2BACP,mBACA,SACA,aACA,MACA;AACA,MAAI,CAAC,kBAAkB,IAAI,EAAG;AAE9B,QAAM,8BAA8B,kBAAkB,IAAI;AAC1D,QAAM,OAAO,KAAK,MAAM,GAAG,EAAE;AAC7B,QAAM,cAAc,aAAa,oBAAoB,YAAY;AACjE,QAAM,cAAc,aAAa,oBAAoB,kBAAkB,UAAU,kBAAkB;AAEnG,QAAM,oBAAoB,OAAO,QAAQ,2BAA2B;AAEpE,aAAW,CAAC,MAAM,UAAU,KAAK,mBAAmB;AAClD,QAAI,CAAC,WAAW,eAAe;AAC7B,YAAM,IAAI,SAAS;AAAA,QACjB,OAAO,WAAW;AAAA,QAClB,MAAM,kBAAkB;AAAA,QACxB,SAAS,EAAE,aAAa,aAAa,MAAM,KAAK;AAAA,MAClD,CAAC;AAAA,IACH;AAEA,UAAM,EAAE,QAAQ,UAAU,aAAa,IAAI,WAAW;AAGtD,QAAI,eAAe,QAAQ,aAAa;AACtC,YAAM,cAAc,YAAY,IAAI;AAEpC,cAAQ,IAAI,MAAM,CAAC;AACnB,cAAQ,IAAI,EAAE,IAAI,IAChB,gBAAgB,SACZ,EAAE,QAAQ,UAAU,cAAc,QAAQ,UAAU,IACpD,EAAE,QAAQ,UAAU,cAAc,aAAa,QAAQ,eAAe;AAE5E;AAAA,IACF;AAGA,QAAI,CAAC,UAAU;AACb,UAAI,SAAS,UAAU;AACrB,cAAM,IAAI,SAAS;AAAA,UACjB,OAAO,WAAW;AAAA,UAClB,MAAM,eAAe;AAAA,UACrB,SAAS,EAAE,aAAa,aAAa,YAAY,KAAK;AAAA,QACxD,CAAC;AAAA,MACH;AAEA,UAAI,SAAS,YAAY;AACvB,cAAM,IAAI,SAAS;AAAA,UACjB,OAAO,WAAW;AAAA,UAClB,MAAM,eAAe;AAAA,UACrB,SAAS,EAAE,aAAa,aAAa,cAAc,KAAK;AAAA,QAC1D,CAAC;AAAA,MACH;AAAA,IACF;AAGA,YAAQ,IAAI,MAAM,CAAC;AACnB,YAAQ,IAAI,EAAE,IAAI,IAAI,EAAE,QAAQ,UAAU,cAAc,QAAQ,UAAU;AAAA,EAC5E;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,2 +1,108 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/parse/parser-utilities.ts
|
|
2
|
+
function findSubcommandDefinition(subcommandName, cliDefinition) {
|
|
3
|
+
if (subcommandName === void 0) {
|
|
4
|
+
return cliDefinition;
|
|
5
|
+
}
|
|
6
|
+
if (!cliDefinition.subcommands) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
return cliDefinition.subcommands.find((c) => {
|
|
10
|
+
if (c.name === subcommandName) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
return subcommandName && c.aliases && c.aliases.includes(subcommandName);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function findOption(optionArgument, options) {
|
|
17
|
+
const validVariableNames = optionArgumentToVariableNames(optionArgument);
|
|
18
|
+
const isNegated = optionArgument.startsWith("--no-");
|
|
19
|
+
const option = Object.entries(options).find(([optionName, option2]) => {
|
|
20
|
+
if (validVariableNames.has(optionName)) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
if (isNegated && validVariableNames.has(negateOption(optionName))) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
if (!option2.aliases) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
if (option2.aliases.some((a) => validVariableNames.has(a))) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
if (isNegated && option2.aliases.map((alias) => negateOption(alias)).some((a) => validVariableNames.has(a))) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
});
|
|
37
|
+
return option;
|
|
38
|
+
}
|
|
39
|
+
function decoupleFlags(arguments_) {
|
|
40
|
+
const flagsRe = /^-[a-z0-9]{2,}$/i;
|
|
41
|
+
const result = [];
|
|
42
|
+
for (const argument of arguments_) {
|
|
43
|
+
const isCoupled = flagsRe.test(argument);
|
|
44
|
+
if (!isCoupled) {
|
|
45
|
+
result.push(argument);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const decoupledArray = argument.slice(1).split("").map((c) => "-" + c);
|
|
49
|
+
result.push(...decoupledArray);
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
function optionArgumentToVariableNames(name) {
|
|
54
|
+
name = name.startsWith("--") ? name.slice(2) : name.slice(1);
|
|
55
|
+
name = name.toLowerCase();
|
|
56
|
+
const results = /* @__PURE__ */ new Set();
|
|
57
|
+
const camelCase = name.replace(/-(.)/g, (m) => m[1].toUpperCase());
|
|
58
|
+
results.add(camelCase);
|
|
59
|
+
results.add(camelCase.replace(/^(.)/, (m) => m.toUpperCase()));
|
|
60
|
+
const snake_case = name.replace(/-(.)/g, (g) => "_" + g[1]);
|
|
61
|
+
results.add(snake_case);
|
|
62
|
+
results.add(snake_case.toUpperCase());
|
|
63
|
+
return results;
|
|
64
|
+
}
|
|
65
|
+
function isFlagArgument(name) {
|
|
66
|
+
return /^-[A-Za-z]$/.test(name);
|
|
67
|
+
}
|
|
68
|
+
function isLongArgument(name) {
|
|
69
|
+
return /^--.{2,}/.test(name);
|
|
70
|
+
}
|
|
71
|
+
function isOptionArgument(name) {
|
|
72
|
+
if (typeof name !== "string") {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
return isFlagArgument(name) || isLongArgument(name);
|
|
76
|
+
}
|
|
77
|
+
function negateOption(name) {
|
|
78
|
+
return "no" + name.replace(/^[a-z]/, (g) => g.toUpperCase());
|
|
79
|
+
}
|
|
80
|
+
function transformOptionToArgument(name) {
|
|
81
|
+
if (name.length === 1) {
|
|
82
|
+
return `-${name.toLowerCase()}`;
|
|
83
|
+
}
|
|
84
|
+
if (/^[a-z_]+$/.test(name) || /^[A-Z_]+$/.test(name)) {
|
|
85
|
+
name = name.replace(/_/g, "-");
|
|
86
|
+
return `--${name.toLowerCase()}`;
|
|
87
|
+
}
|
|
88
|
+
name = name.replace(/[A-Z]/g, (match, index) => index > 0 ? "-" + match : match);
|
|
89
|
+
return `--${name.toLowerCase()}`;
|
|
90
|
+
}
|
|
91
|
+
function splitAndGetKeys(option) {
|
|
92
|
+
const parts = option.split(".");
|
|
93
|
+
const optionName = parts[0];
|
|
94
|
+
const keys = parts.slice(1).filter(Boolean);
|
|
95
|
+
return [optionName, keys];
|
|
96
|
+
}
|
|
97
|
+
export {
|
|
98
|
+
decoupleFlags,
|
|
99
|
+
findOption,
|
|
100
|
+
findSubcommandDefinition,
|
|
101
|
+
isFlagArgument,
|
|
102
|
+
isOptionArgument,
|
|
103
|
+
negateOption,
|
|
104
|
+
optionArgumentToVariableNames,
|
|
105
|
+
splitAndGetKeys,
|
|
106
|
+
transformOptionToArgument
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=parser-utilities.mjs.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/parse/parser-utilities.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Cli, Option, Subcommand } from \"../types/definitions-types.ts\";\n\n/**\n * Retrieves a subcommand object from an array of subcommands by matching the provided subcommand name against the\n * subcommand's name or its aliases.\n *\n * @param subcommandName - The name or alias of the subcommand to search for.\n * @param subcommandArr - An array of `Subcommand` objects to search within.\n * @returns The matching `Subcommand` object if found; otherwise, `undefined`.\n */\nexport function findSubcommandDefinition(\n subcommandName: string | undefined,\n cliDefinition: Cli,\n): Subcommand | Cli | undefined {\n if (subcommandName === undefined) {\n return cliDefinition;\n }\n\n if (!cliDefinition.subcommands) {\n return;\n }\n\n return cliDefinition.subcommands.find(c => {\n // match for undefined too\n if (c.name === subcommandName) {\n return true;\n }\n\n // match for aliases\n return subcommandName && c.aliases && c.aliases.includes(subcommandName);\n });\n}\n\n/**\n * Finds and returns an `Option` object from the provided list that matches the given argument string.\n *\n * The function supports matching by option name, aliases, and their negated forms (e.g., `--no-` prefix).\n *\n * @param optionArgument - The argument string to match (e.g., `--foo`, `--no-bar`, `-f`).\n * @param options - An array of `Option` objects to search through.\n * @returns The matching `Option` object if found; otherwise, `undefined`.\n */\nexport function findOption(optionArgument: string, options: Record<string, Option>): [string, Option] | undefined {\n const validVariableNames = optionArgumentToVariableNames(optionArgument);\n const isNegated = optionArgument.startsWith(\"--no-\");\n\n const option = Object.entries(options).find(([optionName, option]) => {\n if (validVariableNames.has(optionName)) {\n return true;\n }\n\n if (isNegated && validVariableNames.has(negateOption(optionName))) {\n return true;\n }\n\n if (!option.aliases) {\n return false;\n }\n\n if (option.aliases.some(a => validVariableNames.has(a))) {\n return true;\n }\n\n if (isNegated && option.aliases.map(alias => negateOption(alias)).some(a => validVariableNames.has(a))) {\n return true;\n }\n\n return false;\n });\n\n return option;\n}\n\n/** - Decouple flags E.g. `-rf` -> `-r, -f` */\nexport function decoupleFlags(arguments_: string[]): string[] {\n const flagsRe = /^-[a-z0-9]{2,}$/i;\n\n const result = [];\n for (const argument of arguments_) {\n const isCoupled = flagsRe.test(argument);\n\n if (!isCoupled) {\n result.push(argument);\n continue;\n }\n\n const decoupledArray = argument\n .slice(1)\n .split(\"\")\n .map(c => \"-\" + c);\n\n result.push(...decoupledArray);\n }\n\n return result;\n}\n\n/**\n * Transforms an option name to a set of variants: `camelCase`, `PascalCase`, `snake_case`, `SCREAMING_SNAKE_CASE`.\n *\n * **Example** for `--input-dir`\n *\n * - CamelCase: `inputDir`\n * - PascalCase: `InputDir`\n * - Snake_case: `input_dir`\n * - SCREAMING_SNAKE_CASE: `INPUT_DIR`\n *\n * @param name - Should start with `'--'` or `'-'`\n */\nexport function optionArgumentToVariableNames(name: string): Set<string> {\n name = name.startsWith(\"--\") ? name.slice(2) : name.slice(1); // remove prefix\n name = name.toLowerCase(); // lowercase\n\n const results = new Set<string>();\n\n // camelCase\n const camelCase = name.replace(/-(.)/g, m => m[1].toUpperCase());\n results.add(camelCase);\n\n // PascalCase (UpperCamelCase)\n results.add(camelCase.replace(/^(.)/, m => m.toUpperCase()));\n\n // snake_case\n const snake_case = name.replace(/-(.)/g, g => \"_\" + g[1]);\n results.add(snake_case);\n\n // SCREAMING_SNAKE_CASE\n results.add(snake_case.toUpperCase());\n\n return results;\n}\n\n/** - Check if an arg string is a short arg. E.g. `-i` -> `true` */\nexport function isFlagArgument(name: string): boolean {\n return /^-[A-Za-z]$/.test(name);\n}\n\n/**\n * - Check if an arg string is a long arg.\n * - `--input-dir` -> `true`\n * - `-h` -> `false`\n * - `--db.https` -> `true`\n */\nfunction isLongArgument(name: string): boolean {\n return /^--.{2,}/.test(name);\n}\n\n/** - Check if an arg string is an options arg. E.g. `--input-dir` -> `true` , `-i` -> `true` */\nexport function isOptionArgument(name: string | boolean): boolean {\n if (typeof name !== \"string\") {\n return false;\n }\n\n return isFlagArgument(name) || isLongArgument(name);\n}\n\n/**\n * Transform option name to no name.\n *\n * - `verbose` -> `noVerbose`\n * - `v` -> `noV`\n */\nexport function negateOption(name: string): string {\n return \"no\" + name.replace(/^[a-z]/, g => g.toUpperCase());\n}\n\n/** - Reverse of `transformArg`. E.g. `InputDir` -> `--input-dir` , `i` -> `-i` */\nexport function transformOptionToArgument(name: string): string {\n // single letter option name\n if (name.length === 1) {\n return `-${name.toLowerCase()}`;\n }\n\n // snake_case, SCREAMING_SNAKE_CASE\n if (/^[a-z_]+$/.test(name) || /^[A-Z_]+$/.test(name)) {\n name = name.replace(/_/g, \"-\");\n return `--${name.toLowerCase()}`;\n }\n\n // camelCase, PascalCase\n\n // add \"-\" before camel case letters except for the first letter\n name = name.replace(/[A-Z]/g, (match, index: number) => (index > 0 ? \"-\" + match : match));\n\n return `--${name.toLowerCase()}`;\n}\n\n/**\n * Split an option with keys into name and a set of keys\n *\n * - `--foo` -> `[--foo, []]`\n * - `--foo.bar` -> `[--foo, [\"bar\"]]`\n * - `--foo.bar.baz` -> `[--foo, [\"bar\", \"baz\"]]`\n * - `--foo.bar.` -> `[--foo, Set(1) [\"bar\"]]`\n */\nexport function splitAndGetKeys(option: string): [string, string[]] {\n const parts = option.split(\".\");\n const optionName = parts[0];\n const keys = parts.slice(1).filter(Boolean);\n return [optionName, keys];\n}\n"],
|
|
5
|
+
"mappings": ";AAUO,SAAS,yBACd,gBACA,eAC8B;AAC9B,MAAI,mBAAmB,QAAW;AAChC,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,cAAc,aAAa;AAC9B;AAAA,EACF;AAEA,SAAO,cAAc,YAAY,KAAK,OAAK;AAEzC,QAAI,EAAE,SAAS,gBAAgB;AAC7B,aAAO;AAAA,IACT;AAGA,WAAO,kBAAkB,EAAE,WAAW,EAAE,QAAQ,SAAS,cAAc;AAAA,EACzE,CAAC;AACH;AAWO,SAAS,WAAW,gBAAwB,SAA+D;AAChH,QAAM,qBAAqB,8BAA8B,cAAc;AACvE,QAAM,YAAY,eAAe,WAAW,OAAO;AAEnD,QAAM,SAAS,OAAO,QAAQ,OAAO,EAAE,KAAK,CAAC,CAAC,YAAYA,OAAM,MAAM;AACpE,QAAI,mBAAmB,IAAI,UAAU,GAAG;AACtC,aAAO;AAAA,IACT;AAEA,QAAI,aAAa,mBAAmB,IAAI,aAAa,UAAU,CAAC,GAAG;AACjE,aAAO;AAAA,IACT;AAEA,QAAI,CAACA,QAAO,SAAS;AACnB,aAAO;AAAA,IACT;AAEA,QAAIA,QAAO,QAAQ,KAAK,OAAK,mBAAmB,IAAI,CAAC,CAAC,GAAG;AACvD,aAAO;AAAA,IACT;AAEA,QAAI,aAAaA,QAAO,QAAQ,IAAI,WAAS,aAAa,KAAK,CAAC,EAAE,KAAK,OAAK,mBAAmB,IAAI,CAAC,CAAC,GAAG;AACtG,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT,CAAC;AAED,SAAO;AACT;AAGO,SAAS,cAAc,YAAgC;AAC5D,QAAM,UAAU;AAEhB,QAAM,SAAS,CAAC;AAChB,aAAW,YAAY,YAAY;AACjC,UAAM,YAAY,QAAQ,KAAK,QAAQ;AAEvC,QAAI,CAAC,WAAW;AACd,aAAO,KAAK,QAAQ;AACpB;AAAA,IACF;AAEA,UAAM,iBAAiB,SACpB,MAAM,CAAC,EACP,MAAM,EAAE,EACR,IAAI,OAAK,MAAM,CAAC;AAEnB,WAAO,KAAK,GAAG,cAAc;AAAA,EAC/B;AAEA,SAAO;AACT;AAcO,SAAS,8BAA8B,MAA2B;AACvE,SAAO,KAAK,WAAW,IAAI,IAAI,KAAK,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC;AAC3D,SAAO,KAAK,YAAY;AAExB,QAAM,UAAU,oBAAI,IAAY;AAGhC,QAAM,YAAY,KAAK,QAAQ,SAAS,OAAK,EAAE,CAAC,EAAE,YAAY,CAAC;AAC/D,UAAQ,IAAI,SAAS;AAGrB,UAAQ,IAAI,UAAU,QAAQ,QAAQ,OAAK,EAAE,YAAY,CAAC,CAAC;AAG3D,QAAM,aAAa,KAAK,QAAQ,SAAS,OAAK,MAAM,EAAE,CAAC,CAAC;AACxD,UAAQ,IAAI,UAAU;AAGtB,UAAQ,IAAI,WAAW,YAAY,CAAC;AAEpC,SAAO;AACT;AAGO,SAAS,eAAe,MAAuB;AACpD,SAAO,cAAc,KAAK,IAAI;AAChC;AAQA,SAAS,eAAe,MAAuB;AAC7C,SAAO,WAAW,KAAK,IAAI;AAC7B;AAGO,SAAS,iBAAiB,MAAiC;AAChE,MAAI,OAAO,SAAS,UAAU;AAC5B,WAAO;AAAA,EACT;AAEA,SAAO,eAAe,IAAI,KAAK,eAAe,IAAI;AACpD;AAQO,SAAS,aAAa,MAAsB;AACjD,SAAO,OAAO,KAAK,QAAQ,UAAU,OAAK,EAAE,YAAY,CAAC;AAC3D;AAGO,SAAS,0BAA0B,MAAsB;AAE9D,MAAI,KAAK,WAAW,GAAG;AACrB,WAAO,IAAI,KAAK,YAAY,CAAC;AAAA,EAC/B;AAGA,MAAI,YAAY,KAAK,IAAI,KAAK,YAAY,KAAK,IAAI,GAAG;AACpD,WAAO,KAAK,QAAQ,MAAM,GAAG;AAC7B,WAAO,KAAK,KAAK,YAAY,CAAC;AAAA,EAChC;AAKA,SAAO,KAAK,QAAQ,UAAU,CAAC,OAAO,UAAmB,QAAQ,IAAI,MAAM,QAAQ,KAAM;AAEzF,SAAO,KAAK,KAAK,YAAY,CAAC;AAChC;AAUO,SAAS,gBAAgB,QAAoC;AAClE,QAAM,QAAQ,OAAO,MAAM,GAAG;AAC9B,QAAM,aAAa,MAAM,CAAC;AAC1B,QAAM,OAAO,MAAM,MAAM,CAAC,EAAE,OAAO,OAAO;AAC1C,SAAO,CAAC,YAAY,IAAI;AAC1B;",
|
|
6
|
+
"names": ["option"]
|
|
7
|
+
}
|
|
@@ -1,2 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/parse/safe-parse.ts
|
|
2
|
+
import { validateCliDefinition } from "../definitions/validate-cli-definition.mjs";
|
|
3
|
+
import { parseArgv } from "../utilities/parse-argv.mjs";
|
|
4
|
+
import { buildCliContext } from "./context/cli-context-builder.mjs";
|
|
5
|
+
import { findSubcommandDefinition } from "./parser-utilities.mjs";
|
|
6
|
+
import { validate } from "./validation/validate-context.mjs";
|
|
7
|
+
function safeParse(stringOrArgv, cliDefinition) {
|
|
8
|
+
const core = safeParseCore(stringOrArgv, cliDefinition);
|
|
9
|
+
if (core.error) return { error: core.error };
|
|
10
|
+
const { validateResult, subcommandObject } = core;
|
|
11
|
+
if (subcommandObject._onExecute) {
|
|
12
|
+
for (const handler of subcommandObject._onExecute) {
|
|
13
|
+
void handler(validateResult);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return { error: void 0, value: validateResult };
|
|
17
|
+
}
|
|
18
|
+
async function safeParseAsync(stringOrArgv, cliDefinition) {
|
|
19
|
+
const core = safeParseCore(stringOrArgv, cliDefinition);
|
|
20
|
+
if (core.error) return { error: core.error };
|
|
21
|
+
const { validateResult, subcommandObject } = core;
|
|
22
|
+
if (subcommandObject._onExecute) {
|
|
23
|
+
await Promise.all(subcommandObject._onExecute.map(async (handler) => await handler(validateResult)));
|
|
24
|
+
}
|
|
25
|
+
return { error: void 0, value: validateResult };
|
|
26
|
+
}
|
|
27
|
+
function safeParseCore(stringOrArgv, cliDefinition) {
|
|
28
|
+
const argv = typeof stringOrArgv === "string" ? parseArgv(stringOrArgv) : stringOrArgv;
|
|
29
|
+
try {
|
|
30
|
+
validateCliDefinition(cliDefinition);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
return { error };
|
|
33
|
+
}
|
|
34
|
+
let cliContext;
|
|
35
|
+
try {
|
|
36
|
+
cliContext = buildCliContext(argv, cliDefinition);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
return { error };
|
|
39
|
+
}
|
|
40
|
+
const subcommandObject = findSubcommandDefinition(cliContext.subcommand, cliDefinition);
|
|
41
|
+
if (!subcommandObject) {
|
|
42
|
+
const error = new Error(`Subcommand "${cliContext.subcommand}" does not exist`);
|
|
43
|
+
return { error };
|
|
44
|
+
}
|
|
45
|
+
let validateResult;
|
|
46
|
+
try {
|
|
47
|
+
validateResult = validate(cliContext, subcommandObject);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
return { error };
|
|
50
|
+
}
|
|
51
|
+
return { error: void 0, validateResult, subcommandObject };
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
safeParse,
|
|
55
|
+
safeParseAsync
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=safe-parse.mjs.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/parse/safe-parse.ts"],
|
|
4
|
+
"sourcesContent": ["import { validateCliDefinition } from \"../definitions/validate-cli-definition.ts\";\nimport { parseArgv } from \"../utilities/parse-argv.ts\";\nimport { buildCliContext } from \"./context/cli-context-builder.ts\";\nimport { findSubcommandDefinition } from \"./parser-utilities.ts\";\nimport { validate } from \"./validation/validate-context.ts\";\n\nimport type { Cli } from \"../types/definitions-types.ts\";\nimport type { CliParseResultWide } from \"../types/types.ts\";\n\nexport function safeParse(stringOrArgv: string | string[], cliDefinition: Cli): CliParseResultWide {\n const core = safeParseCore(stringOrArgv, cliDefinition);\n if (core.error) return { error: core.error };\n\n const { validateResult, subcommandObject } = core;\n\n // Fire action (throw errors caused by the usage of the action hook)\n if (subcommandObject._onExecute) {\n for (const handler of subcommandObject._onExecute) {\n void handler(validateResult);\n }\n }\n\n return { error: undefined, value: validateResult };\n}\n\nexport async function safeParseAsync(stringOrArgv: string | string[], cliDefinition: Cli): Promise<CliParseResultWide> {\n const core = safeParseCore(stringOrArgv, cliDefinition);\n if (core.error) return { error: core.error };\n\n const { validateResult, subcommandObject } = core;\n\n // Fire action (throw errors caused by the usage of the action hook)\n if (subcommandObject._onExecute) {\n await Promise.all(subcommandObject._onExecute.map(async handler => await handler(validateResult)));\n }\n\n return { error: undefined, value: validateResult };\n}\n\nfunction safeParseCore(stringOrArgv: string | string[], cliDefinition: Cli) {\n const argv = typeof stringOrArgv === \"string\" ? parseArgv(stringOrArgv) : stringOrArgv;\n\n // validate cli definition\n try {\n validateCliDefinition(cliDefinition);\n } catch (error) {\n return { error: error as Error };\n }\n\n // Parse\n let cliContext;\n try {\n cliContext = buildCliContext(argv, cliDefinition);\n } catch (error) {\n return { error: error as Error };\n }\n\n const subcommandObject = findSubcommandDefinition(cliContext.subcommand, cliDefinition);\n if (!subcommandObject) {\n const error = new Error(`Subcommand \"${cliContext.subcommand}\" does not exist`);\n return { error };\n }\n\n // Validate context\n let validateResult;\n try {\n validateResult = validate(cliContext, subcommandObject);\n } catch (error) {\n return { error: error as Error };\n }\n\n return { error: undefined, validateResult, subcommandObject };\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,6BAA6B;AACtC,SAAS,iBAAiB;AAC1B,SAAS,uBAAuB;AAChC,SAAS,gCAAgC;AACzC,SAAS,gBAAgB;AAKlB,SAAS,UAAU,cAAiC,eAAwC;AACjG,QAAM,OAAO,cAAc,cAAc,aAAa;AACtD,MAAI,KAAK,MAAO,QAAO,EAAE,OAAO,KAAK,MAAM;AAE3C,QAAM,EAAE,gBAAgB,iBAAiB,IAAI;AAG7C,MAAI,iBAAiB,YAAY;AAC/B,eAAW,WAAW,iBAAiB,YAAY;AACjD,WAAK,QAAQ,cAAc;AAAA,IAC7B;AAAA,EACF;AAEA,SAAO,EAAE,OAAO,QAAW,OAAO,eAAe;AACnD;AAEA,eAAsB,eAAe,cAAiC,eAAiD;AACrH,QAAM,OAAO,cAAc,cAAc,aAAa;AACtD,MAAI,KAAK,MAAO,QAAO,EAAE,OAAO,KAAK,MAAM;AAE3C,QAAM,EAAE,gBAAgB,iBAAiB,IAAI;AAG7C,MAAI,iBAAiB,YAAY;AAC/B,UAAM,QAAQ,IAAI,iBAAiB,WAAW,IAAI,OAAM,YAAW,MAAM,QAAQ,cAAc,CAAC,CAAC;AAAA,EACnG;AAEA,SAAO,EAAE,OAAO,QAAW,OAAO,eAAe;AACnD;AAEA,SAAS,cAAc,cAAiC,eAAoB;AAC1E,QAAM,OAAO,OAAO,iBAAiB,WAAW,UAAU,YAAY,IAAI;AAG1E,MAAI;AACF,0BAAsB,aAAa;AAAA,EACrC,SAAS,OAAO;AACd,WAAO,EAAE,MAAsB;AAAA,EACjC;AAGA,MAAI;AACJ,MAAI;AACF,iBAAa,gBAAgB,MAAM,aAAa;AAAA,EAClD,SAAS,OAAO;AACd,WAAO,EAAE,MAAsB;AAAA,EACjC;AAEA,QAAM,mBAAmB,yBAAyB,WAAW,YAAY,aAAa;AACtF,MAAI,CAAC,kBAAkB;AACrB,UAAM,QAAQ,IAAI,MAAM,eAAe,WAAW,UAAU,kBAAkB;AAC9E,WAAO,EAAE,MAAM;AAAA,EACjB;AAGA,MAAI;AACJ,MAAI;AACF,qBAAiB,SAAS,YAAY,gBAAgB;AAAA,EACxD,SAAS,OAAO;AACd,WAAO,EAAE,MAAsB;AAAA,EACjC;AAEA,SAAO,EAAE,OAAO,QAAW,gBAAgB,iBAAiB;AAC9D;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/parse/validation/validate-context.ts
|
|
2
|
+
import { validateArguments } from "./validators/arguments.mjs";
|
|
3
|
+
import { validateOptions } from "./validators/options.mjs";
|
|
4
|
+
function validate(context, commandDefinition) {
|
|
5
|
+
const output = {
|
|
6
|
+
subcommand: context.subcommand,
|
|
7
|
+
positionals: context.positionals,
|
|
8
|
+
context
|
|
9
|
+
};
|
|
10
|
+
validateOptions({ commandDefinition, context, output });
|
|
11
|
+
validateArguments({ commandDefinition, context, output });
|
|
12
|
+
return output;
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
validate
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=validate-context.mjs.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/parse/validation/validate-context.ts"],
|
|
4
|
+
"sourcesContent": ["import { validateArguments } from \"./validators/arguments.ts\";\nimport { validateOptions } from \"./validators/options.ts\";\n\nimport type { ContextWide } from \"../../types/context-types.ts\";\nimport type { Cli, Subcommand } from \"../../types/definitions-types.ts\";\nimport type { OutputTypeWide } from \"../../types/io-types.ts\";\n\n/** @throws {CliError} */\nexport function validate(context: ContextWide, commandDefinition: Subcommand | Cli) {\n const output: OutputTypeWide = {\n subcommand: context.subcommand,\n positionals: context.positionals,\n context: context,\n };\n\n // validate options\n validateOptions({ commandDefinition, context, output });\n\n // validate arguments\n validateArguments({ commandDefinition, context, output });\n\n return output;\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,yBAAyB;AAClC,SAAS,uBAAuB;AAOzB,SAAS,SAAS,SAAsB,mBAAqC;AAClF,QAAM,SAAyB;AAAA,IAC7B,YAAY,QAAQ;AAAA,IACpB,aAAa,QAAQ;AAAA,IACrB;AAAA,EACF;AAGA,kBAAgB,EAAE,mBAAmB,SAAS,OAAO,CAAC;AAGtD,oBAAkB,EAAE,mBAAmB,SAAS,OAAO,CAAC;AAExD,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,2 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/parse/validation/validators/arguments.ts
|
|
2
|
+
import { CliError } from "../../../cli-error/cli-error.mjs";
|
|
3
|
+
import { ErrorCause } from "../../../cli-error/error-cause.mjs";
|
|
4
|
+
import { InternalErrorCode } from "../../../cli-error/error-code/internal-error-code.mjs";
|
|
5
|
+
import { ValidationErrorCode } from "../../../cli-error/error-code/validation-error-code.mjs";
|
|
6
|
+
import { validateSync } from "../../../utilities/schema-utilities.mjs";
|
|
7
|
+
import { validateConflictWith } from "./conflict.mjs";
|
|
8
|
+
import { validateExclusive } from "./exclusive.mjs";
|
|
9
|
+
import { validateRequires } from "./requires.mjs";
|
|
10
|
+
function validateArguments({ commandDefinition, context, output }) {
|
|
11
|
+
if (!context.arguments) return;
|
|
12
|
+
output.arguments ??= {};
|
|
13
|
+
const commandKind = "cliName" in commandDefinition ? "command" : "subcommand";
|
|
14
|
+
const commandName = "cliName" in commandDefinition ? commandDefinition.cliName : commandDefinition.name;
|
|
15
|
+
const argumentsDefinition = commandDefinition.arguments;
|
|
16
|
+
if (!argumentsDefinition) {
|
|
17
|
+
throw new CliError({
|
|
18
|
+
cause: ErrorCause.Validation,
|
|
19
|
+
code: ValidationErrorCode.NoArgumentsToValidate,
|
|
20
|
+
context: { commandKind, commandName }
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
for (const [argumentName, argument] of Object.entries(argumentsDefinition)) {
|
|
24
|
+
validateRequires({ name: argumentName, commandDefinition, optionOrArgument: argument, context, kind: "option" });
|
|
25
|
+
validateExclusive({ name: argumentName, optionOrArgument: argument, context, kind: "option" });
|
|
26
|
+
validateConflictWith({ name: argumentName, optionOrArgument: argument, context, kind: "option" });
|
|
27
|
+
}
|
|
28
|
+
const argumentContextEntries = Object.entries(context.arguments);
|
|
29
|
+
for (const [argumentName, { passedValue, stringValue, source, schema }] of argumentContextEntries) {
|
|
30
|
+
const isProgrammatic = source === "programmatic";
|
|
31
|
+
const argument = argumentsDefinition[argumentName];
|
|
32
|
+
if (!argument) {
|
|
33
|
+
throw new CliError({
|
|
34
|
+
cause: ErrorCause.Validation,
|
|
35
|
+
code: ValidationErrorCode.UnknownArgumentValidation,
|
|
36
|
+
context: { commandKind, commandName, argumentName }
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
if (!argument._preparedType) {
|
|
40
|
+
throw new CliError({
|
|
41
|
+
cause: ErrorCause.Internal,
|
|
42
|
+
code: InternalErrorCode.MissingPreparedTypes,
|
|
43
|
+
context: { commandKind, commandName, kind: "argument", name: argumentName }
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const safeParseResult = isProgrammatic ? validateSync(schema, passedValue) : argument._preparedType.validate(stringValue);
|
|
47
|
+
if (safeParseResult.issues) {
|
|
48
|
+
throw new CliError({
|
|
49
|
+
cause: ErrorCause.Validation,
|
|
50
|
+
code: ValidationErrorCode.SchemaValidationFailed,
|
|
51
|
+
context: {
|
|
52
|
+
commandKind,
|
|
53
|
+
commandName,
|
|
54
|
+
kind: "option",
|
|
55
|
+
name: argumentName,
|
|
56
|
+
inputValue: isProgrammatic ? passedValue : stringValue,
|
|
57
|
+
issues: safeParseResult.issues
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
output.arguments[argumentName] = safeParseResult.value;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export {
|
|
65
|
+
validateArguments
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=arguments.mjs.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/parse/validation/validators/arguments.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 { ValidationErrorCode } from \"../../../cli-error/error-code/validation-error-code.ts\";\nimport { validateSync } from \"../../../utilities/schema-utilities.ts\";\nimport { validateConflictWith } from \"./conflict.ts\";\nimport { validateExclusive } from \"./exclusive.ts\";\nimport { validateRequires } from \"./requires.ts\";\n\nimport type { ContextWide } from \"../../../types/context-types.ts\";\nimport type { Cli, Subcommand } from \"../../../types/definitions-types.ts\";\nimport type { OutputTypeWide } from \"../../../types/io-types.ts\";\n\ninterface ValidateArgument {\n commandDefinition: Subcommand | Cli;\n context: ContextWide;\n output: OutputTypeWide;\n}\n\n/** @throws {CliError} */\nexport function validateArguments({ commandDefinition, context, output }: ValidateArgument) {\n if (!context.arguments) return;\n\n output.arguments ??= {};\n\n const commandKind = \"cliName\" in commandDefinition ? \"command\" : \"subcommand\";\n const commandName = \"cliName\" in commandDefinition ? commandDefinition.cliName : commandDefinition.name;\n\n const argumentsDefinition = commandDefinition.arguments;\n if (!argumentsDefinition) {\n throw new CliError({\n cause: ErrorCause.Validation,\n code: ValidationErrorCode.NoArgumentsToValidate,\n context: { commandKind, commandName },\n });\n }\n\n for (const [argumentName, argument] of Object.entries(argumentsDefinition)) {\n validateRequires({ name: argumentName, commandDefinition, optionOrArgument: argument, context, kind: \"option\" });\n validateExclusive({ name: argumentName, optionOrArgument: argument, context, kind: \"option\" });\n validateConflictWith({ name: argumentName, optionOrArgument: argument, context, kind: \"option\" });\n }\n\n const argumentContextEntries = Object.entries(context.arguments);\n\n for (const [argumentName, { passedValue, stringValue, source, schema }] of argumentContextEntries) {\n const isProgrammatic = source === \"programmatic\";\n\n const argument = argumentsDefinition[argumentName];\n if (!argument) {\n throw new CliError({\n cause: ErrorCause.Validation,\n code: ValidationErrorCode.UnknownArgumentValidation,\n context: { commandKind, commandName, argumentName },\n });\n }\n\n if (!argument._preparedType) {\n throw new CliError({\n cause: ErrorCause.Internal,\n code: InternalErrorCode.MissingPreparedTypes,\n context: { commandKind, commandName, kind: \"argument\", name: argumentName },\n });\n }\n\n const safeParseResult = isProgrammatic\n ? validateSync(schema, passedValue)\n : argument._preparedType.validate(stringValue);\n\n if (safeParseResult.issues) {\n throw new CliError({\n cause: ErrorCause.Validation,\n code: ValidationErrorCode.SchemaValidationFailed,\n context: {\n commandKind,\n commandName,\n kind: \"option\",\n name: argumentName,\n inputValue: isProgrammatic ? passedValue : stringValue,\n issues: safeParseResult.issues,\n },\n });\n }\n\n output.arguments[argumentName] = safeParseResult.value;\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,yBAAyB;AAClC,SAAS,2BAA2B;AACpC,SAAS,oBAAoB;AAC7B,SAAS,4BAA4B;AACrC,SAAS,yBAAyB;AAClC,SAAS,wBAAwB;AAa1B,SAAS,kBAAkB,EAAE,mBAAmB,SAAS,OAAO,GAAqB;AAC1F,MAAI,CAAC,QAAQ,UAAW;AAExB,SAAO,cAAc,CAAC;AAEtB,QAAM,cAAc,aAAa,oBAAoB,YAAY;AACjE,QAAM,cAAc,aAAa,oBAAoB,kBAAkB,UAAU,kBAAkB;AAEnG,QAAM,sBAAsB,kBAAkB;AAC9C,MAAI,CAAC,qBAAqB;AACxB,UAAM,IAAI,SAAS;AAAA,MACjB,OAAO,WAAW;AAAA,MAClB,MAAM,oBAAoB;AAAA,MAC1B,SAAS,EAAE,aAAa,YAAY;AAAA,IACtC,CAAC;AAAA,EACH;AAEA,aAAW,CAAC,cAAc,QAAQ,KAAK,OAAO,QAAQ,mBAAmB,GAAG;AAC1E,qBAAiB,EAAE,MAAM,cAAc,mBAAmB,kBAAkB,UAAU,SAAS,MAAM,SAAS,CAAC;AAC/G,sBAAkB,EAAE,MAAM,cAAc,kBAAkB,UAAU,SAAS,MAAM,SAAS,CAAC;AAC7F,yBAAqB,EAAE,MAAM,cAAc,kBAAkB,UAAU,SAAS,MAAM,SAAS,CAAC;AAAA,EAClG;AAEA,QAAM,yBAAyB,OAAO,QAAQ,QAAQ,SAAS;AAE/D,aAAW,CAAC,cAAc,EAAE,aAAa,aAAa,QAAQ,OAAO,CAAC,KAAK,wBAAwB;AACjG,UAAM,iBAAiB,WAAW;AAElC,UAAM,WAAW,oBAAoB,YAAY;AACjD,QAAI,CAAC,UAAU;AACb,YAAM,IAAI,SAAS;AAAA,QACjB,OAAO,WAAW;AAAA,QAClB,MAAM,oBAAoB;AAAA,QAC1B,SAAS,EAAE,aAAa,aAAa,aAAa;AAAA,MACpD,CAAC;AAAA,IACH;AAEA,QAAI,CAAC,SAAS,eAAe;AAC3B,YAAM,IAAI,SAAS;AAAA,QACjB,OAAO,WAAW;AAAA,QAClB,MAAM,kBAAkB;AAAA,QACxB,SAAS,EAAE,aAAa,aAAa,MAAM,YAAY,MAAM,aAAa;AAAA,MAC5E,CAAC;AAAA,IACH;AAEA,UAAM,kBAAkB,iBACpB,aAAa,QAAQ,WAAW,IAChC,SAAS,cAAc,SAAS,WAAW;AAE/C,QAAI,gBAAgB,QAAQ;AAC1B,YAAM,IAAI,SAAS;AAAA,QACjB,OAAO,WAAW;AAAA,QAClB,MAAM,oBAAoB;AAAA,QAC1B,SAAS;AAAA,UACP;AAAA,UACA;AAAA,UACA,MAAM;AAAA,UACN,MAAM;AAAA,UACN,YAAY,iBAAiB,cAAc;AAAA,UAC3C,QAAQ,gBAAgB;AAAA,QAC1B;AAAA,MACF,CAAC;AAAA,IACH;AAEA,WAAO,UAAU,YAAY,IAAI,gBAAgB;AAAA,EACnD;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,2 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/parse/validation/validators/conflict.ts
|
|
2
|
+
import { CliError } from "../../../cli-error/cli-error.mjs";
|
|
3
|
+
import { ErrorCause } from "../../../cli-error/error-cause.mjs";
|
|
4
|
+
import { ValidationErrorCode } from "../../../cli-error/error-code/validation-error-code.mjs";
|
|
5
|
+
import { isOptionOrArgumentExplicitlyPassed } from "./explicitly-passed.mjs";
|
|
6
|
+
function validateConflictWith({ name, optionOrArgument, context, kind }) {
|
|
7
|
+
const conflictWith = optionOrArgument.conflictWith;
|
|
8
|
+
if (!conflictWith || conflictWith.length === 0) return;
|
|
9
|
+
if (!isOptionOrArgumentExplicitlyPassed(name, context)) return;
|
|
10
|
+
const conflictedOptions = [];
|
|
11
|
+
const conflictedArguments = [];
|
|
12
|
+
if (context.options) {
|
|
13
|
+
for (const [optionName, optionContext] of Object.entries(context.options)) {
|
|
14
|
+
if (optionName === name) continue;
|
|
15
|
+
if (!conflictWith.includes(optionName)) continue;
|
|
16
|
+
if (optionContext.source === "default") continue;
|
|
17
|
+
conflictedOptions.push(optionName);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (context.arguments) {
|
|
21
|
+
for (const [argumentName, argumentContext] of Object.entries(context.arguments)) {
|
|
22
|
+
if (argumentName === name) continue;
|
|
23
|
+
if (!conflictWith.includes(argumentName)) continue;
|
|
24
|
+
if (argumentContext.source === "default") continue;
|
|
25
|
+
conflictedArguments.push(argumentName);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (conflictedOptions.length === 0 && conflictedArguments.length === 0) return;
|
|
29
|
+
throw new CliError({
|
|
30
|
+
cause: ErrorCause.Validation,
|
|
31
|
+
code: ValidationErrorCode.MutuallyExclusiveConflict,
|
|
32
|
+
context: { kind, name, conflictedOptions, conflictedArguments }
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
export {
|
|
36
|
+
validateConflictWith
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=conflict.mjs.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/parse/validation/validators/conflict.ts"],
|
|
4
|
+
"sourcesContent": ["import { CliError } from \"../../../cli-error/cli-error.ts\";\nimport { ErrorCause } from \"../../../cli-error/error-cause.ts\";\nimport { ValidationErrorCode } from \"../../../cli-error/error-code/validation-error-code.ts\";\nimport { isOptionOrArgumentExplicitlyPassed } from \"./explicitly-passed.ts\";\n\nimport type { ContextWide } from \"../../../types/context-types.ts\";\nimport type { Argument, Option } from \"../../../types/definitions-types.ts\";\n\ninterface ValidateConflictOptions {\n /** The option or argument name to check its `requires` */\n name: string;\n\n /** The option or argument to check */\n optionOrArgument: Option | Argument;\n\n /** The parsed context */\n context: ContextWide;\n\n /** What we're checking */\n kind: \"option\" | \"argument\";\n}\n\n/** @throws {CliError} */\nexport function validateConflictWith({ name, optionOrArgument, context, kind }: ValidateConflictOptions) {\n const conflictWith = optionOrArgument.conflictWith;\n if (!conflictWith || conflictWith.length === 0) return;\n\n // Check if the options/argument is passed\n if (!isOptionOrArgumentExplicitlyPassed(name, context)) return;\n\n const conflictedOptions: string[] = [];\n const conflictedArguments: string[] = [];\n\n if (context.options) {\n for (const [optionName, optionContext] of Object.entries(context.options)) {\n if (optionName === name) continue; // don't check self\n if (!conflictWith.includes(optionName)) continue; // not a conflict\n if (optionContext.source === \"default\") continue; // not explicitly passed\n conflictedOptions.push(optionName);\n }\n }\n\n if (context.arguments) {\n for (const [argumentName, argumentContext] of Object.entries(context.arguments)) {\n if (argumentName === name) continue; // don't check self\n if (!conflictWith.includes(argumentName)) continue; // not a conflict\n if (argumentContext.source === \"default\") continue; // not explicitly passed\n conflictedArguments.push(argumentName);\n }\n }\n\n if (conflictedOptions.length === 0 && conflictedArguments.length === 0) return; // OK\n\n throw new CliError({\n cause: ErrorCause.Validation,\n code: ValidationErrorCode.MutuallyExclusiveConflict,\n context: { kind, name, conflictedOptions, conflictedArguments },\n });\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,2BAA2B;AACpC,SAAS,0CAA0C;AAoB5C,SAAS,qBAAqB,EAAE,MAAM,kBAAkB,SAAS,KAAK,GAA4B;AACvG,QAAM,eAAe,iBAAiB;AACtC,MAAI,CAAC,gBAAgB,aAAa,WAAW,EAAG;AAGhD,MAAI,CAAC,mCAAmC,MAAM,OAAO,EAAG;AAExD,QAAM,oBAA8B,CAAC;AACrC,QAAM,sBAAgC,CAAC;AAEvC,MAAI,QAAQ,SAAS;AACnB,eAAW,CAAC,YAAY,aAAa,KAAK,OAAO,QAAQ,QAAQ,OAAO,GAAG;AACzE,UAAI,eAAe,KAAM;AACzB,UAAI,CAAC,aAAa,SAAS,UAAU,EAAG;AACxC,UAAI,cAAc,WAAW,UAAW;AACxC,wBAAkB,KAAK,UAAU;AAAA,IACnC;AAAA,EACF;AAEA,MAAI,QAAQ,WAAW;AACrB,eAAW,CAAC,cAAc,eAAe,KAAK,OAAO,QAAQ,QAAQ,SAAS,GAAG;AAC/E,UAAI,iBAAiB,KAAM;AAC3B,UAAI,CAAC,aAAa,SAAS,YAAY,EAAG;AAC1C,UAAI,gBAAgB,WAAW,UAAW;AAC1C,0BAAoB,KAAK,YAAY;AAAA,IACvC;AAAA,EACF;AAEA,MAAI,kBAAkB,WAAW,KAAK,oBAAoB,WAAW,EAAG;AAExE,QAAM,IAAI,SAAS;AAAA,IACjB,OAAO,WAAW;AAAA,IAClB,MAAM,oBAAoB;AAAA,IAC1B,SAAS,EAAE,MAAM,MAAM,mBAAmB,oBAAoB;AAAA,EAChE,CAAC;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,2 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/parse/validation/validators/exclusive.ts
|
|
2
|
+
import { CliError } from "../../../cli-error/cli-error.mjs";
|
|
3
|
+
import { ErrorCause } from "../../../cli-error/error-cause.mjs";
|
|
4
|
+
import { ValidationErrorCode } from "../../../cli-error/error-code/validation-error-code.mjs";
|
|
5
|
+
import { isOptionOrArgumentExplicitlyPassed } from "./explicitly-passed.mjs";
|
|
6
|
+
function validateExclusive({ name, optionOrArgument, context, kind }) {
|
|
7
|
+
const exclusive = optionOrArgument.exclusive;
|
|
8
|
+
if (!exclusive) return;
|
|
9
|
+
if (!isOptionOrArgumentExplicitlyPassed(name, context)) return;
|
|
10
|
+
const requires = optionOrArgument.requires ?? [];
|
|
11
|
+
const conflictedOptions = [];
|
|
12
|
+
const conflictedArguments = [];
|
|
13
|
+
if (context.options) {
|
|
14
|
+
for (const [optionName, optionContext] of Object.entries(context.options)) {
|
|
15
|
+
if (optionName === name) continue;
|
|
16
|
+
if (requires.includes(optionName)) continue;
|
|
17
|
+
if (optionContext.source === "default") continue;
|
|
18
|
+
conflictedOptions.push(optionName);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (context.arguments) {
|
|
22
|
+
for (const [argumentName, argumentContext] of Object.entries(context.arguments)) {
|
|
23
|
+
if (argumentName === name) continue;
|
|
24
|
+
if (requires.includes(argumentName)) continue;
|
|
25
|
+
if (argumentContext.source === "default") continue;
|
|
26
|
+
conflictedArguments.push(argumentName);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (conflictedOptions.length === 0 && conflictedArguments.length === 0) return;
|
|
30
|
+
throw new CliError({
|
|
31
|
+
cause: ErrorCause.Validation,
|
|
32
|
+
code: ValidationErrorCode.MutuallyExclusiveConflict,
|
|
33
|
+
context: { kind, name, conflictedOptions, conflictedArguments }
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
validateExclusive
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=exclusive.mjs.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/parse/validation/validators/exclusive.ts"],
|
|
4
|
+
"sourcesContent": ["import { CliError } from \"../../../cli-error/cli-error.ts\";\nimport { ErrorCause } from \"../../../cli-error/error-cause.ts\";\nimport { ValidationErrorCode } from \"../../../cli-error/error-code/validation-error-code.ts\";\nimport { isOptionOrArgumentExplicitlyPassed } from \"./explicitly-passed.ts\";\n\nimport type { ContextWide } from \"../../../types/context-types.ts\";\nimport type { Argument, Option } from \"../../../types/definitions-types.ts\";\n\ninterface ValidateExclusiveOptions {\n /** The option or argument name to check its `requires` */\n name: string;\n\n /** The option or argument to check */\n optionOrArgument: Option | Argument;\n\n /** The parsed context */\n context: ContextWide;\n\n /** What we're checking */\n kind: \"option\" | \"argument\";\n}\n\n/** @throws {CliError} */\nexport function validateExclusive({ name, optionOrArgument, context, kind }: ValidateExclusiveOptions) {\n const exclusive = optionOrArgument.exclusive;\n if (!exclusive) return;\n\n // Check if the options/argument is passed\n if (!isOptionOrArgumentExplicitlyPassed(name, context)) return;\n\n const requires = optionOrArgument.requires ?? [];\n\n const conflictedOptions: string[] = [];\n const conflictedArguments: string[] = [];\n\n if (context.options) {\n for (const [optionName, optionContext] of Object.entries(context.options)) {\n if (optionName === name) continue; // don't check self\n if (requires.includes(optionName)) continue; // allow required options\n if (optionContext.source === \"default\") continue; // not explicitly passed\n conflictedOptions.push(optionName);\n }\n }\n\n if (context.arguments) {\n for (const [argumentName, argumentContext] of Object.entries(context.arguments)) {\n if (argumentName === name) continue; // don't check self\n if (requires.includes(argumentName)) continue; // allow required arguments\n if (argumentContext.source === \"default\") continue; // not explicitly passed\n conflictedArguments.push(argumentName);\n }\n }\n\n if (conflictedOptions.length === 0 && conflictedArguments.length === 0) return;\n\n throw new CliError({\n cause: ErrorCause.Validation,\n code: ValidationErrorCode.MutuallyExclusiveConflict,\n context: { kind, name, conflictedOptions, conflictedArguments },\n });\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,2BAA2B;AACpC,SAAS,0CAA0C;AAoB5C,SAAS,kBAAkB,EAAE,MAAM,kBAAkB,SAAS,KAAK,GAA6B;AACrG,QAAM,YAAY,iBAAiB;AACnC,MAAI,CAAC,UAAW;AAGhB,MAAI,CAAC,mCAAmC,MAAM,OAAO,EAAG;AAExD,QAAM,WAAW,iBAAiB,YAAY,CAAC;AAE/C,QAAM,oBAA8B,CAAC;AACrC,QAAM,sBAAgC,CAAC;AAEvC,MAAI,QAAQ,SAAS;AACnB,eAAW,CAAC,YAAY,aAAa,KAAK,OAAO,QAAQ,QAAQ,OAAO,GAAG;AACzE,UAAI,eAAe,KAAM;AACzB,UAAI,SAAS,SAAS,UAAU,EAAG;AACnC,UAAI,cAAc,WAAW,UAAW;AACxC,wBAAkB,KAAK,UAAU;AAAA,IACnC;AAAA,EACF;AAEA,MAAI,QAAQ,WAAW;AACrB,eAAW,CAAC,cAAc,eAAe,KAAK,OAAO,QAAQ,QAAQ,SAAS,GAAG;AAC/E,UAAI,iBAAiB,KAAM;AAC3B,UAAI,SAAS,SAAS,YAAY,EAAG;AACrC,UAAI,gBAAgB,WAAW,UAAW;AAC1C,0BAAoB,KAAK,YAAY;AAAA,IACvC;AAAA,EACF;AAEA,MAAI,kBAAkB,WAAW,KAAK,oBAAoB,WAAW,EAAG;AAExE,QAAM,IAAI,SAAS;AAAA,IACjB,OAAO,WAAW;AAAA,IAClB,MAAM,oBAAoB;AAAA,IAC1B,SAAS,EAAE,MAAM,MAAM,mBAAmB,oBAAoB;AAAA,EAChE,CAAC;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|