zod-args-parser 2.0.0-beta.1 → 2.0.0-beta.3
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 +244 -282
- 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 +41 -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 +10 -9
- 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
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { DefinitionErrorCode } from "../error-code/definition-error-code.ts";
|
|
2
|
+
|
|
3
|
+
import type { CliErrorOptionByCause } from "../../types/error-types.ts";
|
|
4
|
+
|
|
5
|
+
export function definitionErrorMessage({ code, context }: CliErrorOptionByCause<"Definition">) {
|
|
6
|
+
if (code === DefinitionErrorCode.MissingDefinitionName) {
|
|
7
|
+
const propertyName = context.commandKind === "command" ? "cliName" : "name";
|
|
8
|
+
return `invalid ${context.commandKind} definition: "${propertyName}" property is required.`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (code === DefinitionErrorCode.EmptyDefinitionGroup) {
|
|
12
|
+
return (
|
|
13
|
+
`invalid ${context.commandKind} definition "${context.commandName}": ` +
|
|
14
|
+
`"${context.kind}" property is optional but cannot be empty.`
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (code === DefinitionErrorCode.MissingSchema) {
|
|
19
|
+
return (
|
|
20
|
+
`invalid ${context.commandKind} definition "${context.commandName}": ` +
|
|
21
|
+
`the ${context.kind} "${context.name}" is missing the "schema" property.`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (code === DefinitionErrorCode.InvalidDefinitionOptionName) {
|
|
26
|
+
if (context.negatedAliasName) {
|
|
27
|
+
return (
|
|
28
|
+
`invalid ${context.commandKind} definition "${context.commandName}": ` +
|
|
29
|
+
`the option "${context.optionName}" has the alias "${context.negatedAliasName}" which cannot be named as a negated option.`
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
`invalid ${context.commandKind} definition "${context.commandName}": ` +
|
|
35
|
+
`the option "${context.optionName}" cannot be named as a negated option.`
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (code === DefinitionErrorCode.InvalidDefinitionArgumentName) {
|
|
40
|
+
return (
|
|
41
|
+
`invalid ${context.commandKind} definition "${context.commandName}": ` +
|
|
42
|
+
`the argument "${context.name}" cannot be a number..`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (code === DefinitionErrorCode.DuplicateDefinitionName) {
|
|
47
|
+
const foundIn = context.foundInName
|
|
48
|
+
? `conflict with the ${context.foundInKind} "${context.foundInName}" alias name`
|
|
49
|
+
: `conflict with other ${context.foundInKind} name`;
|
|
50
|
+
|
|
51
|
+
if (context.duplicatedAlias) {
|
|
52
|
+
return (
|
|
53
|
+
`invalid ${context.commandKind} definition "${context.commandName}": ` +
|
|
54
|
+
`the ${context.kind} "${context.name}" has the alias "${context.duplicatedAlias}" which ${foundIn}.`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
`invalid ${context.commandKind} definition "${context.commandName}": ` +
|
|
60
|
+
`the ${context.kind} "${context.name}" name ${foundIn}.`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (code === DefinitionErrorCode.EmptyStringAliasName) {
|
|
65
|
+
if (context.optionName) {
|
|
66
|
+
return (
|
|
67
|
+
`invalid ${context.commandKind} definition "${context.commandName}": ` +
|
|
68
|
+
`the option "${context.optionName}" has an empty string alias name.`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
`invalid ${context.commandKind} definition "${context.commandName}": ` + `empty string alias name is not allowed.`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (code === DefinitionErrorCode.SelfRequire) {
|
|
78
|
+
return (
|
|
79
|
+
`invalid ${context.commandKind} definition "${context.commandName}": ` +
|
|
80
|
+
`the ${context.kind} "${context.name}" cannot require itself.`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (code === DefinitionErrorCode.UnknownRequireName) {
|
|
85
|
+
return (
|
|
86
|
+
`invalid ${context.commandKind} definition "${context.commandName}": ` +
|
|
87
|
+
`the ${context.kind} "${context.name}" requires a non-existent name "${context.requiredName}".`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (code === DefinitionErrorCode.SelfConflict) {
|
|
92
|
+
return (
|
|
93
|
+
`invalid ${context.commandKind} definition "${context.commandName}": ` +
|
|
94
|
+
`the ${context.kind} "${context.name}" cannot conflict with itself.`
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (code === DefinitionErrorCode.UnknownConflictName) {
|
|
99
|
+
return (
|
|
100
|
+
`invalid ${context.commandKind} definition "${context.commandName}": ` +
|
|
101
|
+
`the ${context.kind} "${context.name}" conflicts with a non-existent name "${context.requiredName}".`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (code === DefinitionErrorCode.DefinitionRequiresConflictOverlap) {
|
|
106
|
+
const s = context.intersectedNames.length > 1 ? "s" : "";
|
|
107
|
+
return (
|
|
108
|
+
`invalid ${context.commandKind} definition "${context.commandName}": ` +
|
|
109
|
+
`the ${context.kind} "${context.name}" has overlapping 'requires' and 'conflictsWith' name${s}: ` +
|
|
110
|
+
context.intersectedNames.join(", ")
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (code === DefinitionErrorCode.InvalidOptionalArgumentDefinition) {
|
|
115
|
+
if (context.allowPositionals) {
|
|
116
|
+
return (
|
|
117
|
+
`invalid ${context.commandKind} definition "${context.commandName}": ` +
|
|
118
|
+
`the argument "${context.name}" cannot be optional when "allowPositionals" is enabled.`
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return (
|
|
123
|
+
`invalid ${context.commandKind} definition "${context.commandName}": ` +
|
|
124
|
+
`the argument "${context.name}" cannot be optional unless it is the last argument.`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (code === DefinitionErrorCode.MissingOnExecute) {
|
|
129
|
+
return (
|
|
130
|
+
`trying to execute ${context.commandKind} "${context.commandName}" ` +
|
|
131
|
+
`which does not have an "onExecute" handler.`
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (code === DefinitionErrorCode.SubcommandHelpNotFound) {
|
|
136
|
+
return (
|
|
137
|
+
`cannot generate help message for subcommand "${context.subcommandName}" ` +
|
|
138
|
+
`because it does not exist in CLI "${context.cliName}".`
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const executiveCheck: never = code;
|
|
143
|
+
return executiveCheck;
|
|
144
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { InternalErrorCode } from "../error-code/internal-error-code.ts";
|
|
2
|
+
|
|
3
|
+
import type { CliErrorOptionByCause } from "../../types/error-types.ts";
|
|
4
|
+
|
|
5
|
+
export function internalErrorMessage({ code, context }: CliErrorOptionByCause<"Internal">) {
|
|
6
|
+
if (code === InternalErrorCode.MissingPreparedTypes) {
|
|
7
|
+
return (
|
|
8
|
+
`internal error: missing prepared type ` +
|
|
9
|
+
`for option "${context.name}" in ${context.commandKind} "${context.commandName}"`
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (code === InternalErrorCode.CannotFindCliDefinition) {
|
|
14
|
+
return `internal error: cannot find cli definition "${context.cliName}"`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const executiveCheck: never = code;
|
|
18
|
+
return executiveCheck;
|
|
19
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { ParseErrorCode } from "../error-code/parse-error-code.ts";
|
|
2
|
+
|
|
3
|
+
import type { CliErrorOptionByCause } from "../../types/error-types.ts";
|
|
4
|
+
|
|
5
|
+
export function parseErrorMessage({ code, context }: CliErrorOptionByCause<"Parse">) {
|
|
6
|
+
if (code === ParseErrorCode.UnknownSubcommand) {
|
|
7
|
+
return `parsing error: unknown subcommand "${context.commandName}".`;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (code === ParseErrorCode.CommandWithoutOptions) {
|
|
11
|
+
return (
|
|
12
|
+
`parsing error: the ${context.commandKind} "${context.commandName}" ` +
|
|
13
|
+
`does not allow options, but received "${context.optionName}".`
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (code === ParseErrorCode.UnknownOption) {
|
|
18
|
+
return (
|
|
19
|
+
`parsing error: unknown option "${context.optionName}" ` +
|
|
20
|
+
`for the ${context.commandKind} "${context.commandName}".`
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (code === ParseErrorCode.DuplicateOptionProvided) {
|
|
25
|
+
return (
|
|
26
|
+
`parsing error: duplicate option "${context.optionName}" ` +
|
|
27
|
+
`provided for the ${context.commandKind} "${context.commandName}".`
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (code === ParseErrorCode.InvalidNegationForNonBooleanOption) {
|
|
32
|
+
return (
|
|
33
|
+
`parsing error: option "${context.optionName}" cannot be negated ` +
|
|
34
|
+
`because it is not a boolean option for the ${context.commandKind} "${context.commandName}".`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (code === ParseErrorCode.PositionalArgumentNotAllowed) {
|
|
39
|
+
return (
|
|
40
|
+
`parsing error: positional argument "${context.argumentName}" ` +
|
|
41
|
+
`is not allowed for the ${context.commandKind} "${context.commandName}".`
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (code === ParseErrorCode.MissingRequiredOption) {
|
|
46
|
+
return (
|
|
47
|
+
`parsing error: missing required option "${context.optionName}" ` +
|
|
48
|
+
`for the ${context.commandKind} "${context.commandName}".`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (code === ParseErrorCode.MissingRequiredArgument) {
|
|
53
|
+
return (
|
|
54
|
+
`parsing error: missing required argument "${context.argumentName}" ` +
|
|
55
|
+
`for the ${context.commandKind} "${context.commandName}".`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (code === ParseErrorCode.OptionMissingValue) {
|
|
60
|
+
return (
|
|
61
|
+
`parsing error: the option "${context.optionName}" ` +
|
|
62
|
+
`for the ${context.commandKind} "${context.commandName}" expects a value but received none.`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (code === ParseErrorCode.FlagAssignedValue) {
|
|
67
|
+
return (
|
|
68
|
+
`parsing error: ` +
|
|
69
|
+
`flag option "${context.flag}" in ${context.commandKind} "${context.commandName}" ` +
|
|
70
|
+
`cannot be assigned a value using "=" (provided: "${context.value}").`
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const executiveCheck: never = code;
|
|
75
|
+
return executiveCheck;
|
|
76
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { prettifyError } from "../../utilities/schema-utilities.ts";
|
|
2
|
+
import { ValidationErrorCode } from "../error-code/validation-error-code.ts";
|
|
3
|
+
|
|
4
|
+
import type { CliErrorOptionByCause } from "../../types/error-types.ts";
|
|
5
|
+
|
|
6
|
+
export function validationErrorMessage({ code, context }: CliErrorOptionByCause<"Validation">) {
|
|
7
|
+
if (code === ValidationErrorCode.NoOptionsToValidate) {
|
|
8
|
+
return (
|
|
9
|
+
`validation error: trying to validate options ` +
|
|
10
|
+
`for ${context.commandKind} "${context.commandName}" which does not define any.`
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (code === ValidationErrorCode.NoArgumentsToValidate) {
|
|
15
|
+
return (
|
|
16
|
+
`validation error: trying to validate typed arguments ` +
|
|
17
|
+
`for ${context.commandKind} "${context.commandName}" which does not define any.`
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (code === ValidationErrorCode.UnknownOptionValidation) {
|
|
22
|
+
return (
|
|
23
|
+
`validation error: trying to validate a non-existent option "${context.optionName}" ` +
|
|
24
|
+
`for ${context.commandKind} "${context.commandName}".`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (code === ValidationErrorCode.UnknownArgumentValidation) {
|
|
29
|
+
return (
|
|
30
|
+
`validation error: trying to validate a non-existent typed argument "${context.argumentName}" ` +
|
|
31
|
+
`for ${context.commandKind} "${context.commandName}".`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (code === ValidationErrorCode.SchemaValidationFailed) {
|
|
36
|
+
return (
|
|
37
|
+
`validation error: ` +
|
|
38
|
+
`the ${context.kind} "${context.name}" for ${context.commandKind} "${context.commandName}" failed to validate ` +
|
|
39
|
+
`"${typeof context.inputValue === "string" ? context.inputValue : JSON.stringify(context.inputValue)}": ` +
|
|
40
|
+
prettifyError(context.issues)
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (code === ValidationErrorCode.MutuallyExclusiveConflict) {
|
|
45
|
+
const parts: string[] = [];
|
|
46
|
+
|
|
47
|
+
if (context.conflictedOptions.length > 0) {
|
|
48
|
+
const formatted = context.conflictedOptions.map(o => `"${o}"`).join(", ");
|
|
49
|
+
const s = context.conflictedOptions.length > 1 ? "s" : "";
|
|
50
|
+
parts.push(`option${s} ${formatted}`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (context.conflictedArguments.length > 0) {
|
|
54
|
+
const formatted = context.conflictedArguments.map(a => `"${a}"`).join(", ");
|
|
55
|
+
const s = context.conflictedArguments.length > 1 ? "s" : "";
|
|
56
|
+
parts.push(`argument${s} ${formatted}`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
`validation error: the ${context.kind} "${context.name}" ` +
|
|
61
|
+
`cannot be used with the ${parts.join(" and ")} because they are mutually exclusive.`
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (code === ValidationErrorCode.RequiredDependencyMissing) {
|
|
66
|
+
const parts: string[] = [];
|
|
67
|
+
|
|
68
|
+
if (context.missingOptions.length > 0) {
|
|
69
|
+
const formatted = context.missingOptions.map(o => `"${o}"`).join(", ");
|
|
70
|
+
const s = context.missingOptions.length > 1 ? "s" : "";
|
|
71
|
+
parts.push(`option${s} ${formatted}`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (context.missingArguments.length > 0) {
|
|
75
|
+
const formatted = context.missingArguments.map(a => `"${a}"`).join(", ");
|
|
76
|
+
const s = context.missingArguments.length > 1 ? "s" : "";
|
|
77
|
+
parts.push(`argument${s} ${formatted}`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
`validation error: the ${context.kind} "${context.name}" ` +
|
|
82
|
+
`cannot be used without the required "${parts.join(" and ")}".`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (code === ValidationErrorCode.AsyncSchemaNotSupported) {
|
|
87
|
+
return (
|
|
88
|
+
`validation error: cannot validate async schema: ` +
|
|
89
|
+
`received ${typeof context.value === "string" ? context.value : JSON.stringify(context.value)}`
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (code === ValidationErrorCode.CoercionFailed) {
|
|
94
|
+
return (
|
|
95
|
+
`validation error: ` +
|
|
96
|
+
`failed to coerce the value ` +
|
|
97
|
+
`"${typeof context.providedValue === "string" ? context.providedValue : JSON.stringify(context.providedValue)}" ` +
|
|
98
|
+
`of type "${typeof context.providedValue}" to type "${context.coerceToType}".`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const executiveCheck: never = code;
|
|
103
|
+
return executiveCheck;
|
|
104
|
+
}
|
|
@@ -1,75 +1,230 @@
|
|
|
1
|
+
import { walkObject } from "../utilities/utilities.ts";
|
|
1
2
|
import { stringToBooleanArray, stringToNumberArray, stringToStringArray } from "./string-to-array.ts";
|
|
2
|
-
import { stringToBoolean, stringToNumber } from "./string-to-primitive.ts";
|
|
3
|
+
import { stringToBigint, stringToBoolean, stringToNumber } from "./string-to-primitive.ts";
|
|
3
4
|
import { stringToBooleanSet, stringToNumberSet, stringToStringSet } from "./string-to-set.ts";
|
|
4
5
|
|
|
5
|
-
import type {
|
|
6
|
+
import type { ObjectCoerceMethodOptions } from "../types/types.ts";
|
|
6
7
|
|
|
7
|
-
const string
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
8
|
+
const string = <T extends string | undefined>(terminalInput: string): T => terminalInput as T;
|
|
9
|
+
const number = <T extends number | undefined>(terminalInput: string): T => stringToNumber(terminalInput) as T;
|
|
10
|
+
const bigint = <T extends bigint | undefined>(terminalInput: string): T => stringToBigint(terminalInput) as T;
|
|
11
|
+
const json = <T>(terminalInput: string): T => JSON.parse(terminalInput) as T;
|
|
12
|
+
const boolean = <T extends boolean | undefined>(terminalInput: string): T => stringToBoolean(terminalInput) as T;
|
|
11
13
|
boolean.type = "boolean";
|
|
12
14
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const json = <T>(reviver?: (this: any, key: string, value: any) => any): CoerceMethod<T> => {
|
|
17
|
-
const coerceMethod: CoerceMethod<T> = terminalInput => JSON.parse(terminalInput, reviver) as T;
|
|
18
|
-
coerceMethod.type = "unknown";
|
|
19
|
-
return coerceMethod;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const stringArray = (separator: string): CoerceMethod<string[]> => {
|
|
23
|
-
const coerceMethod: CoerceMethod<string[]> = terminalInput => stringToStringArray(terminalInput, separator);
|
|
24
|
-
coerceMethod.type = "string[]";
|
|
25
|
-
return coerceMethod;
|
|
15
|
+
const stringArray = (separator: string) => {
|
|
16
|
+
return <T extends string[] | undefined>(terminalInput: string): T =>
|
|
17
|
+
stringToStringArray(terminalInput, separator) as T;
|
|
26
18
|
};
|
|
27
19
|
|
|
28
20
|
const numberArray = (separator: string) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return coerceMethod;
|
|
21
|
+
return <T extends number[] | undefined>(terminalInput: string): T =>
|
|
22
|
+
stringToNumberArray(terminalInput, separator) as T;
|
|
32
23
|
};
|
|
33
24
|
|
|
34
25
|
const booleanArray = (separator: string) => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return coerceMethod;
|
|
26
|
+
return <T extends boolean[] | undefined>(terminalInput: string): T =>
|
|
27
|
+
stringToBooleanArray(terminalInput, separator) as T;
|
|
38
28
|
};
|
|
39
29
|
|
|
40
30
|
const stringSet = (separator: string) => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return coerceMethod;
|
|
31
|
+
return <T extends Set<string> | undefined>(terminalInput: string): T =>
|
|
32
|
+
stringToStringSet(terminalInput, separator) as T;
|
|
44
33
|
};
|
|
45
34
|
|
|
46
35
|
const numberSet = (separator: string) => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return coerceMethod;
|
|
36
|
+
return <T extends Set<number> | undefined>(terminalInput: string): T =>
|
|
37
|
+
stringToNumberSet(terminalInput, separator) as T;
|
|
50
38
|
};
|
|
51
39
|
|
|
52
40
|
const booleanSet = (separator: string) => {
|
|
53
|
-
|
|
54
|
-
|
|
41
|
+
return <T extends Set<boolean> | undefined>(terminalInput: string): T =>
|
|
42
|
+
stringToBooleanSet(terminalInput, separator) as T;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const object = (options: ObjectCoerceMethodOptions = {}) => {
|
|
46
|
+
const coerceMethod = <T extends Record<string, unknown> | undefined>(terminalInput: string): T => {
|
|
47
|
+
const object = JSON.parse(terminalInput) as T;
|
|
48
|
+
|
|
49
|
+
if (!options.coerceBoolean && !options.coerceNumber && !options.coerceBigint && !options.coerceDate) {
|
|
50
|
+
return object;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
walkObject(object!, (_, value, path) => {
|
|
54
|
+
if (typeof value !== "string") return value;
|
|
55
|
+
|
|
56
|
+
const shouldCoerce = (boolOrArray: boolean | string[] | undefined) => {
|
|
57
|
+
if (!boolOrArray) return false;
|
|
58
|
+
if (typeof boolOrArray === "boolean") return boolOrArray;
|
|
59
|
+
return boolOrArray.includes(path);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
if (shouldCoerce(options.coerceBoolean)) {
|
|
63
|
+
try {
|
|
64
|
+
return stringToBoolean(value);
|
|
65
|
+
} catch {
|
|
66
|
+
return value;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (shouldCoerce(options.coerceNumber)) {
|
|
71
|
+
try {
|
|
72
|
+
return stringToNumber(value);
|
|
73
|
+
} catch {
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (shouldCoerce(options.coerceBigint)) {
|
|
79
|
+
try {
|
|
80
|
+
return BigInt(value);
|
|
81
|
+
} catch {
|
|
82
|
+
return value;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (shouldCoerce(options.coerceDate)) {
|
|
87
|
+
try {
|
|
88
|
+
return new Date(value);
|
|
89
|
+
} catch {
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return value;
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
return object;
|
|
98
|
+
};
|
|
99
|
+
|
|
55
100
|
return coerceMethod;
|
|
56
101
|
};
|
|
57
102
|
|
|
58
103
|
export const coerce = {
|
|
104
|
+
/**
|
|
105
|
+
* Since the terminal input is a string, this method does nothing.
|
|
106
|
+
*
|
|
107
|
+
* @since 2.0.0
|
|
108
|
+
* @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}
|
|
109
|
+
*/
|
|
59
110
|
string,
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Coerces a string matching `"true"` or `"false"` (case-insensitive) to a boolean value.
|
|
114
|
+
*
|
|
115
|
+
* @since 2.0.0
|
|
116
|
+
* @throws {CliError} If input is not a valid boolean string.
|
|
117
|
+
* @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}
|
|
118
|
+
*/
|
|
60
119
|
boolean,
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Coerces a string matching a number to a number value.
|
|
123
|
+
*
|
|
124
|
+
* @since 2.0.0
|
|
125
|
+
* @throws {CliError} If input is empty or not a valid number.
|
|
126
|
+
* @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}
|
|
127
|
+
*/
|
|
61
128
|
number,
|
|
62
|
-
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Coerces a string matching a number to a bigint value.
|
|
132
|
+
*
|
|
133
|
+
* @since 2.0.0
|
|
134
|
+
* @throws {CliError} If input is empty or not a valid bigint.
|
|
135
|
+
* @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}
|
|
136
|
+
*/
|
|
137
|
+
bigint,
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Coerces a JSON string into a JavaScript object, optionally converting certain string values into native types such
|
|
141
|
+
* as booleans, numbers, bigints, or dates.
|
|
142
|
+
*
|
|
143
|
+
* Each coercion option attempts conversion and silently falls back to the original string if the value cannot be
|
|
144
|
+
* converted.
|
|
145
|
+
*
|
|
146
|
+
* @since 2.0.0
|
|
147
|
+
* @throws {SyntaxError} If input is not a valid JSON string.
|
|
148
|
+
* @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/README.md##structured-object-options}
|
|
149
|
+
* @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}
|
|
150
|
+
*/
|
|
151
|
+
object,
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Converts a string to an array of strings by splitting it on the specified separator.
|
|
155
|
+
*
|
|
156
|
+
* @since 2.0.0
|
|
157
|
+
* @param separator - The separator to use to split the string.`
|
|
158
|
+
* @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}
|
|
159
|
+
*/
|
|
63
160
|
stringArray,
|
|
64
|
-
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Converts a string to an array of numbers by splitting it on the specified separator.
|
|
164
|
+
*
|
|
165
|
+
* Items that match the number regex will be converted to numbers.
|
|
166
|
+
*
|
|
167
|
+
* @since 2.0.0
|
|
168
|
+
* @param separator - The separator to use to split the string.`
|
|
169
|
+
* @throws {CliError} - When an item cannot be converted to a number
|
|
170
|
+
* @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}
|
|
171
|
+
*/
|
|
65
172
|
numberArray,
|
|
66
|
-
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Converts a string to an array of booleans by splitting it on the specified separator.
|
|
176
|
+
*
|
|
177
|
+
* Items that match `"true"` or `"false"` (case-insensitive) will be converted to booleans.
|
|
178
|
+
*
|
|
179
|
+
* @since 2.0.0
|
|
180
|
+
* @param separator - The separator to use to split the string.`
|
|
181
|
+
* @throws {CliError} - When an item cannot be converted to a boolean
|
|
182
|
+
* @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}
|
|
183
|
+
*/
|
|
67
184
|
booleanArray,
|
|
68
|
-
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Converts a string to a set of strings by splitting it on the specified separator.
|
|
188
|
+
*
|
|
189
|
+
* Items that match the number regex will be converted to numbers.
|
|
190
|
+
*
|
|
191
|
+
* @since 2.0.0
|
|
192
|
+
* @param separator - The separator to use to split the string.`
|
|
193
|
+
* @throws {CliError} - When an item cannot be converted to a number
|
|
194
|
+
* @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}
|
|
195
|
+
*/
|
|
69
196
|
stringSet,
|
|
70
|
-
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Converts a string to a set of numbers by splitting it on the specified separator.
|
|
200
|
+
*
|
|
201
|
+
* Items that match the number regex will be converted to numbers.
|
|
202
|
+
*
|
|
203
|
+
* @since 2.0.0
|
|
204
|
+
* @param separator - The separator to use to split the string.
|
|
205
|
+
* @throws {CliError} - When an item cannot be converted to a number
|
|
206
|
+
* @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}
|
|
207
|
+
*/
|
|
71
208
|
numberSet,
|
|
72
|
-
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Converts a string to a set of booleans by splitting it on the specified separator.
|
|
212
|
+
*
|
|
213
|
+
* Items that match `"true"` or `"false"` (case-insensitive) will be converted to booleans.
|
|
214
|
+
*
|
|
215
|
+
* @since 2.0.0
|
|
216
|
+
* @param separator - The separator to use to split the string.
|
|
217
|
+
* @throws {CliError} - When an item cannot be converted to a boolean
|
|
218
|
+
* @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}
|
|
219
|
+
*/
|
|
73
220
|
booleanSet,
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Parses a JSON string into a JavaScript object.
|
|
224
|
+
*
|
|
225
|
+
* @since 2.0.0
|
|
226
|
+
* @throws {SyntaxError} If input is not a valid JSON string.
|
|
227
|
+
* @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}
|
|
228
|
+
*/
|
|
74
229
|
json,
|
|
75
230
|
};
|
|
@@ -7,12 +7,12 @@ export function stringToStringArray(stringValue: string, separator: string = ","
|
|
|
7
7
|
.filter(Boolean);
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
/** @throws {
|
|
10
|
+
/** @throws {CliError} - Because of `stringToNumber` */
|
|
11
11
|
export function stringToNumberArray(stringValue: string, separator: string = ","): number[] {
|
|
12
12
|
return stringToStringArray(stringValue, separator).map(element => stringToNumber(element));
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
/** @throws {
|
|
15
|
+
/** @throws {CliError} - Because of `stringToBoolean` */
|
|
16
16
|
export function stringToBooleanArray(stringValue: string, separator: string = ","): boolean[] {
|
|
17
17
|
return stringToStringArray(stringValue, separator).map(element => stringToBoolean(element));
|
|
18
18
|
}
|