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
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CliError } from "../../../cli-error/cli-error.ts";
|
|
2
|
+
import { ErrorCause } from "../../../cli-error/error-cause.ts";
|
|
3
|
+
import { InternalErrorCode } from "../../../cli-error/error-code/internal-error-code.ts";
|
|
4
|
+
import { ValidationErrorCode } from "../../../cli-error/error-code/validation-error-code.ts";
|
|
5
|
+
import { validateSync } from "../../../utilities/schema-utilities.ts";
|
|
2
6
|
import { validateConflictWith } from "./conflict.ts";
|
|
3
7
|
import { validateExclusive } from "./exclusive.ts";
|
|
4
8
|
import { validateRequires } from "./requires.ts";
|
|
@@ -13,35 +17,50 @@ interface ValidateArgument {
|
|
|
13
17
|
output: OutputTypeWide;
|
|
14
18
|
}
|
|
15
19
|
|
|
16
|
-
/** @throws {
|
|
20
|
+
/** @throws {CliError} */
|
|
17
21
|
export function validateArguments({ commandDefinition, context, output }: ValidateArgument) {
|
|
18
22
|
if (!context.arguments) return;
|
|
19
23
|
|
|
20
24
|
output.arguments ??= {};
|
|
21
25
|
|
|
26
|
+
const commandKind = "cliName" in commandDefinition ? "command" : "subcommand";
|
|
27
|
+
const commandName = "cliName" in commandDefinition ? commandDefinition.cliName : commandDefinition.name;
|
|
28
|
+
|
|
22
29
|
const argumentsDefinition = commandDefinition.arguments;
|
|
23
30
|
if (!argumentsDefinition) {
|
|
24
|
-
throw new
|
|
31
|
+
throw new CliError({
|
|
32
|
+
cause: ErrorCause.Validation,
|
|
33
|
+
code: ValidationErrorCode.NoArgumentsToValidate,
|
|
34
|
+
context: { commandKind, commandName },
|
|
35
|
+
});
|
|
25
36
|
}
|
|
26
37
|
|
|
27
38
|
for (const [argumentName, argument] of Object.entries(argumentsDefinition)) {
|
|
28
|
-
validateRequires({ name: argumentName, commandDefinition, optionOrArgument: argument, context,
|
|
29
|
-
validateExclusive({ name: argumentName, optionOrArgument: argument, context,
|
|
30
|
-
validateConflictWith({ name: argumentName, optionOrArgument: argument, context,
|
|
39
|
+
validateRequires({ name: argumentName, commandDefinition, optionOrArgument: argument, context, kind: "option" });
|
|
40
|
+
validateExclusive({ name: argumentName, optionOrArgument: argument, context, kind: "option" });
|
|
41
|
+
validateConflictWith({ name: argumentName, optionOrArgument: argument, context, kind: "option" });
|
|
31
42
|
}
|
|
32
43
|
|
|
33
44
|
const argumentContextEntries = Object.entries(context.arguments);
|
|
34
45
|
|
|
35
|
-
for (const [
|
|
46
|
+
for (const [argumentName, { passedValue, stringValue, source, schema }] of argumentContextEntries) {
|
|
36
47
|
const isProgrammatic = source === "programmatic";
|
|
37
48
|
|
|
38
|
-
const argument = argumentsDefinition[
|
|
49
|
+
const argument = argumentsDefinition[argumentName];
|
|
39
50
|
if (!argument) {
|
|
40
|
-
throw new
|
|
51
|
+
throw new CliError({
|
|
52
|
+
cause: ErrorCause.Validation,
|
|
53
|
+
code: ValidationErrorCode.UnknownArgumentValidation,
|
|
54
|
+
context: { commandKind, commandName, argumentName },
|
|
55
|
+
});
|
|
41
56
|
}
|
|
42
57
|
|
|
43
58
|
if (!argument._preparedType) {
|
|
44
|
-
throw new
|
|
59
|
+
throw new CliError({
|
|
60
|
+
cause: ErrorCause.Internal,
|
|
61
|
+
code: InternalErrorCode.MissingPreparedTypes,
|
|
62
|
+
context: { commandKind, commandName, kind: "argument", name: argumentName },
|
|
63
|
+
});
|
|
45
64
|
}
|
|
46
65
|
|
|
47
66
|
const safeParseResult = isProgrammatic
|
|
@@ -49,11 +68,20 @@ export function validateArguments({ commandDefinition, context, output }: Valida
|
|
|
49
68
|
: argument._preparedType.validate(stringValue);
|
|
50
69
|
|
|
51
70
|
if (safeParseResult.issues) {
|
|
52
|
-
throw new
|
|
53
|
-
|
|
54
|
-
|
|
71
|
+
throw new CliError({
|
|
72
|
+
cause: ErrorCause.Validation,
|
|
73
|
+
code: ValidationErrorCode.SchemaValidationFailed,
|
|
74
|
+
context: {
|
|
75
|
+
commandKind,
|
|
76
|
+
commandName,
|
|
77
|
+
kind: "option",
|
|
78
|
+
name: argumentName,
|
|
79
|
+
inputValue: isProgrammatic ? passedValue : stringValue,
|
|
80
|
+
issues: safeParseResult.issues,
|
|
81
|
+
},
|
|
82
|
+
});
|
|
55
83
|
}
|
|
56
84
|
|
|
57
|
-
output.arguments[
|
|
85
|
+
output.arguments[argumentName] = safeParseResult.value;
|
|
58
86
|
}
|
|
59
87
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { CliError } from "../../../cli-error/cli-error.ts";
|
|
2
|
+
import { ErrorCause } from "../../../cli-error/error-cause.ts";
|
|
3
|
+
import { ValidationErrorCode } from "../../../cli-error/error-code/validation-error-code.ts";
|
|
1
4
|
import { isOptionOrArgumentExplicitlyPassed } from "./explicitly-passed.ts";
|
|
2
5
|
|
|
3
6
|
import type { ContextWide } from "../../../types/context-types.ts";
|
|
@@ -14,11 +17,11 @@ interface ValidateConflictOptions {
|
|
|
14
17
|
context: ContextWide;
|
|
15
18
|
|
|
16
19
|
/** What we're checking */
|
|
17
|
-
|
|
20
|
+
kind: "option" | "argument";
|
|
18
21
|
}
|
|
19
22
|
|
|
20
|
-
/** @throws {
|
|
21
|
-
export function validateConflictWith({ name, optionOrArgument, context,
|
|
23
|
+
/** @throws {CliError} */
|
|
24
|
+
export function validateConflictWith({ name, optionOrArgument, context, kind }: ValidateConflictOptions) {
|
|
22
25
|
const conflictWith = optionOrArgument.conflictWith;
|
|
23
26
|
if (!conflictWith || conflictWith.length === 0) return;
|
|
24
27
|
|
|
@@ -48,21 +51,9 @@ export function validateConflictWith({ name, optionOrArgument, context, type }:
|
|
|
48
51
|
|
|
49
52
|
if (conflictedOptions.length === 0 && conflictedArguments.length === 0) return; // OK
|
|
50
53
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
parts.push(`option${s} ${formatted}`);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (conflictedArguments.length > 0) {
|
|
60
|
-
const formatted = conflictedArguments.map(a => `"${a}"`).join(", ");
|
|
61
|
-
const s = conflictedArguments.length > 1 ? "s" : "";
|
|
62
|
-
parts.push(`argument${s} ${formatted}`);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const joinedParts = parts.join(" and ");
|
|
66
|
-
|
|
67
|
-
throw new Error(`${type} "${name}" cannot be used with the ${joinedParts} because they are mutually exclusive.`);
|
|
54
|
+
throw new CliError({
|
|
55
|
+
cause: ErrorCause.Validation,
|
|
56
|
+
code: ValidationErrorCode.MutuallyExclusiveConflict,
|
|
57
|
+
context: { kind, name, conflictedOptions, conflictedArguments },
|
|
58
|
+
});
|
|
68
59
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { CliError } from "../../../cli-error/cli-error.ts";
|
|
2
|
+
import { ErrorCause } from "../../../cli-error/error-cause.ts";
|
|
3
|
+
import { ValidationErrorCode } from "../../../cli-error/error-code/validation-error-code.ts";
|
|
1
4
|
import { isOptionOrArgumentExplicitlyPassed } from "./explicitly-passed.ts";
|
|
2
5
|
|
|
3
6
|
import type { ContextWide } from "../../../types/context-types.ts";
|
|
@@ -14,11 +17,11 @@ interface ValidateExclusiveOptions {
|
|
|
14
17
|
context: ContextWide;
|
|
15
18
|
|
|
16
19
|
/** What we're checking */
|
|
17
|
-
|
|
20
|
+
kind: "option" | "argument";
|
|
18
21
|
}
|
|
19
22
|
|
|
20
|
-
/** @throws {
|
|
21
|
-
export function validateExclusive({ name, optionOrArgument, context,
|
|
23
|
+
/** @throws {CliError} */
|
|
24
|
+
export function validateExclusive({ name, optionOrArgument, context, kind }: ValidateExclusiveOptions) {
|
|
22
25
|
const exclusive = optionOrArgument.exclusive;
|
|
23
26
|
if (!exclusive) return;
|
|
24
27
|
|
|
@@ -27,15 +30,15 @@ export function validateExclusive({ name, optionOrArgument, context, type }: Val
|
|
|
27
30
|
|
|
28
31
|
const requires = optionOrArgument.requires ?? [];
|
|
29
32
|
|
|
30
|
-
const
|
|
31
|
-
const
|
|
33
|
+
const conflictedOptions: string[] = [];
|
|
34
|
+
const conflictedArguments: string[] = [];
|
|
32
35
|
|
|
33
36
|
if (context.options) {
|
|
34
37
|
for (const [optionName, optionContext] of Object.entries(context.options)) {
|
|
35
38
|
if (optionName === name) continue; // don't check self
|
|
36
39
|
if (requires.includes(optionName)) continue; // allow required options
|
|
37
40
|
if (optionContext.source === "default") continue; // not explicitly passed
|
|
38
|
-
|
|
41
|
+
conflictedOptions.push(optionName);
|
|
39
42
|
}
|
|
40
43
|
}
|
|
41
44
|
|
|
@@ -44,27 +47,15 @@ export function validateExclusive({ name, optionOrArgument, context, type }: Val
|
|
|
44
47
|
if (argumentName === name) continue; // don't check self
|
|
45
48
|
if (requires.includes(argumentName)) continue; // allow required arguments
|
|
46
49
|
if (argumentContext.source === "default") continue; // not explicitly passed
|
|
47
|
-
|
|
50
|
+
conflictedArguments.push(argumentName);
|
|
48
51
|
}
|
|
49
52
|
}
|
|
50
53
|
|
|
51
|
-
if (
|
|
54
|
+
if (conflictedOptions.length === 0 && conflictedArguments.length === 0) return;
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
parts.push(`option${s} ${formatted}`);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (mutuallyExclusiveArguments.length > 0) {
|
|
62
|
-
const formatted = mutuallyExclusiveArguments.map(a => `"${a}"`).join(", ");
|
|
63
|
-
const s = mutuallyExclusiveArguments.length > 1 ? "s" : "";
|
|
64
|
-
parts.push(`argument${s} ${formatted}`);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const joinedParts = parts.join(" and ");
|
|
68
|
-
|
|
69
|
-
throw new Error(`${type} "${name}" cannot be used with the ${joinedParts} because they are mutually exclusive.`);
|
|
56
|
+
throw new CliError({
|
|
57
|
+
cause: ErrorCause.Validation,
|
|
58
|
+
code: ValidationErrorCode.MutuallyExclusiveConflict,
|
|
59
|
+
context: { kind, name, conflictedOptions, conflictedArguments },
|
|
60
|
+
});
|
|
70
61
|
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CliError } from "../../../cli-error/cli-error.ts";
|
|
2
|
+
import { ErrorCause } from "../../../cli-error/error-cause.ts";
|
|
3
|
+
import { InternalErrorCode } from "../../../cli-error/error-code/internal-error-code.ts";
|
|
4
|
+
import { ValidationErrorCode } from "../../../cli-error/error-code/validation-error-code.ts";
|
|
5
|
+
import { validateSync } from "../../../utilities/schema-utilities.ts";
|
|
2
6
|
import { validateConflictWith } from "./conflict.ts";
|
|
3
7
|
import { validateExclusive } from "./exclusive.ts";
|
|
4
8
|
import { validateRequires } from "./requires.ts";
|
|
@@ -13,33 +17,48 @@ interface ValidateOptions {
|
|
|
13
17
|
output: OutputTypeWide;
|
|
14
18
|
}
|
|
15
19
|
|
|
16
|
-
/** @throws {
|
|
20
|
+
/** @throws {CliError} */
|
|
17
21
|
export function validateOptions({ commandDefinition, context, output }: ValidateOptions) {
|
|
18
22
|
if (!context.options) return;
|
|
19
23
|
|
|
20
24
|
output.options ??= {};
|
|
21
25
|
|
|
26
|
+
const commandKind = "cliName" in commandDefinition ? "command" : "subcommand";
|
|
27
|
+
const commandName = "cliName" in commandDefinition ? commandDefinition.cliName : commandDefinition.name;
|
|
28
|
+
|
|
22
29
|
const optionsDefinition = commandDefinition.options;
|
|
23
30
|
if (!optionsDefinition) {
|
|
24
|
-
throw new
|
|
31
|
+
throw new CliError({
|
|
32
|
+
cause: ErrorCause.Validation,
|
|
33
|
+
code: ValidationErrorCode.NoOptionsToValidate,
|
|
34
|
+
context: { commandKind, commandName },
|
|
35
|
+
});
|
|
25
36
|
}
|
|
26
37
|
|
|
27
38
|
for (const [optionName, option] of Object.entries(optionsDefinition)) {
|
|
28
|
-
validateRequires({ name: optionName, commandDefinition, optionOrArgument: option, context,
|
|
29
|
-
validateExclusive({ name: optionName, optionOrArgument: option, context,
|
|
30
|
-
validateConflictWith({ name: optionName, optionOrArgument: option, context,
|
|
39
|
+
validateRequires({ name: optionName, commandDefinition, optionOrArgument: option, context, kind: "option" });
|
|
40
|
+
validateExclusive({ name: optionName, optionOrArgument: option, context, kind: "option" });
|
|
41
|
+
validateConflictWith({ name: optionName, optionOrArgument: option, context, kind: "option" });
|
|
31
42
|
}
|
|
32
43
|
|
|
33
44
|
const optionContextEntries = Object.entries(context.options);
|
|
34
45
|
|
|
35
|
-
for (const [optionName, { passedValue, stringValue,
|
|
46
|
+
for (const [optionName, { passedValue, stringValue, source, schema }] of optionContextEntries) {
|
|
36
47
|
const option = optionsDefinition[optionName];
|
|
37
48
|
if (!option) {
|
|
38
|
-
throw new
|
|
49
|
+
throw new CliError({
|
|
50
|
+
cause: ErrorCause.Validation,
|
|
51
|
+
code: ValidationErrorCode.UnknownOptionValidation,
|
|
52
|
+
context: { commandKind, commandName, optionName },
|
|
53
|
+
});
|
|
39
54
|
}
|
|
40
55
|
|
|
41
56
|
if (!option._preparedType) {
|
|
42
|
-
throw new
|
|
57
|
+
throw new CliError({
|
|
58
|
+
cause: ErrorCause.Internal,
|
|
59
|
+
code: InternalErrorCode.MissingPreparedTypes,
|
|
60
|
+
context: { commandKind, commandName, kind: "option", name: optionName },
|
|
61
|
+
});
|
|
43
62
|
}
|
|
44
63
|
|
|
45
64
|
const isProgrammatic = source === "programmatic";
|
|
@@ -49,9 +68,18 @@ export function validateOptions({ commandDefinition, context, output }: Validate
|
|
|
49
68
|
: option._preparedType.validate(stringValue);
|
|
50
69
|
|
|
51
70
|
if (safeParseResult.issues) {
|
|
52
|
-
throw new
|
|
53
|
-
|
|
54
|
-
|
|
71
|
+
throw new CliError({
|
|
72
|
+
cause: ErrorCause.Validation,
|
|
73
|
+
code: ValidationErrorCode.SchemaValidationFailed,
|
|
74
|
+
context: {
|
|
75
|
+
commandKind,
|
|
76
|
+
commandName,
|
|
77
|
+
kind: "option",
|
|
78
|
+
name: optionName,
|
|
79
|
+
inputValue: isProgrammatic ? passedValue : stringValue,
|
|
80
|
+
issues: safeParseResult.issues,
|
|
81
|
+
},
|
|
82
|
+
});
|
|
55
83
|
}
|
|
56
84
|
|
|
57
85
|
output.options[optionName] = safeParseResult.value;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { CliError } from "../../../cli-error/cli-error.ts";
|
|
2
|
+
import { ErrorCause } from "../../../cli-error/error-cause.ts";
|
|
3
|
+
import { ValidationErrorCode } from "../../../cli-error/error-code/validation-error-code.ts";
|
|
1
4
|
import {
|
|
2
5
|
isArgumentExplicitlyPassed,
|
|
3
6
|
isOptionExplicitlyPassed,
|
|
@@ -21,16 +24,16 @@ interface ValidateRequiresOptions {
|
|
|
21
24
|
context: ContextWide;
|
|
22
25
|
|
|
23
26
|
/** What we're checking */
|
|
24
|
-
|
|
27
|
+
kind: "option" | "argument";
|
|
25
28
|
}
|
|
26
29
|
|
|
27
|
-
/** @throws {
|
|
30
|
+
/** @throws {CliError} */
|
|
28
31
|
export function validateRequires({
|
|
29
32
|
name,
|
|
30
33
|
commandDefinition,
|
|
31
34
|
optionOrArgument,
|
|
32
35
|
context,
|
|
33
|
-
|
|
36
|
+
kind,
|
|
34
37
|
}: ValidateRequiresOptions) {
|
|
35
38
|
const requires = optionOrArgument.requires;
|
|
36
39
|
if (!requires || requires.length === 0) return;
|
|
@@ -62,21 +65,9 @@ export function validateRequires({
|
|
|
62
65
|
|
|
63
66
|
if (missingOptions.length === 0 && missingArguments.length === 0) return; // OK
|
|
64
67
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
parts.push(`option${s} ${formatted}`);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (missingArguments.length > 0) {
|
|
74
|
-
const formatted = missingArguments.map(a => `"${a}"`).join(", ");
|
|
75
|
-
const s = missingArguments.length > 1 ? "s" : "";
|
|
76
|
-
parts.push(`argument${s} ${formatted}`);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const joinedParts = parts.join(" and ");
|
|
80
|
-
|
|
81
|
-
throw new Error(`${type} "${name}" cannot be used without the required ${joinedParts}.`);
|
|
68
|
+
throw new CliError({
|
|
69
|
+
cause: ErrorCause.Validation,
|
|
70
|
+
code: ValidationErrorCode.RequiredDependencyMissing,
|
|
71
|
+
context: { kind, name, missingArguments, missingOptions },
|
|
72
|
+
});
|
|
82
73
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { OutputTypeWide } from "./io-types.ts";
|
|
2
2
|
import type { InferSchemaOutputType, SchemaResult, SchemaType } from "./schema-types.ts";
|
|
3
3
|
import type { CoerceMethod, CoerceTypes } from "./types.ts";
|
|
4
|
-
import type { Widen } from "./utilities-types.ts";
|
|
5
4
|
|
|
6
5
|
export interface PreparedType {
|
|
7
6
|
schema: SchemaType;
|
|
@@ -11,20 +10,49 @@ export interface PreparedType {
|
|
|
11
10
|
validate: (value: string | undefined) => SchemaResult;
|
|
12
11
|
}
|
|
13
12
|
|
|
14
|
-
// NOTE:
|
|
15
|
-
// Putting these interfaces (`RequiredCoerce` and `OptionalCoerce`) in a union makes TypeScript treat them as a
|
|
16
|
-
// combined structural type, so JSDoc doesn’t appear on hover.
|
|
17
|
-
|
|
18
13
|
/** `schema` (generic) with required `coerce` */
|
|
19
14
|
interface RequiredCoerce<Schema extends SchemaType> {
|
|
15
|
+
/**
|
|
16
|
+
* The schema to validate the input against.
|
|
17
|
+
*
|
|
18
|
+
* Any validation library that supports [`StandardSchemaV1`](https://github.com/standard-schema/standard-schema) and
|
|
19
|
+
* allows primitive types to be optional or have default values can be used.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* schema: z.boolean().optional(),
|
|
23
|
+
* schema: z.number().default(0),
|
|
24
|
+
* schema: z.string(),
|
|
25
|
+
* schema: z.array(z.string())
|
|
26
|
+
*/
|
|
20
27
|
schema: Schema;
|
|
21
|
-
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A function to convert the terminal string input into the schema's output type.
|
|
31
|
+
*
|
|
32
|
+
* When the expected input type is `string`, this is not required and can be omitted.
|
|
33
|
+
*
|
|
34
|
+
* The return type of this function must be the same as the output type of the `schema`.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* schema: z.boolean(),
|
|
38
|
+
* coerce: coerce.boolean
|
|
39
|
+
*
|
|
40
|
+
* schema: z.number(),
|
|
41
|
+
* coerce: coerce.number
|
|
42
|
+
*
|
|
43
|
+
* schema: z.string(),
|
|
44
|
+
* // coerce is not required in this case
|
|
45
|
+
*
|
|
46
|
+
* schema: z.array(z.string()),
|
|
47
|
+
* coerce: coerce.stringArray(",")
|
|
48
|
+
*/
|
|
49
|
+
coerce: CoerceMethod<InferSchemaOutputType<Schema>>;
|
|
22
50
|
}
|
|
23
51
|
|
|
24
52
|
/** `schema` (string) with optional `coerce` */
|
|
25
53
|
interface OptionalCoerce {
|
|
26
54
|
schema: SchemaType<string | undefined>;
|
|
27
|
-
coerce?:
|
|
55
|
+
coerce?: never;
|
|
28
56
|
}
|
|
29
57
|
|
|
30
58
|
// Derived from `Subcommand`
|
|
@@ -154,7 +182,7 @@ export interface Subcommand {
|
|
|
154
182
|
* const myCli = defineCLI({ name: "my-cli", subcommands: [helpCommand] });
|
|
155
183
|
* myCli.onExecute((result) => console.log(result));
|
|
156
184
|
*/
|
|
157
|
-
_onExecute?: ((result: OutputTypeWide) => void)[];
|
|
185
|
+
_onExecute?: ((result: OutputTypeWide) => void | Promise<void>)[];
|
|
158
186
|
}
|
|
159
187
|
|
|
160
188
|
interface OptionMeta extends MetaBase {
|