zod-args-parser 1.2.8 → 2.0.0-beta.0
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/README.md +525 -588
- package/lib/cjs/autocomplete-scripts/bash-autocomplete-script.cjs +2 -0
- package/lib/cjs/autocomplete-scripts/bash-autocomplete-script.cjs.map +1 -0
- package/lib/cjs/autocomplete-scripts/powershell-autocomplete-script.cjs +2 -0
- package/lib/cjs/autocomplete-scripts/powershell-autocomplete-script.cjs.map +1 -0
- package/lib/cjs/autocomplete-scripts/zsh-autocomplete-script.cjs +42 -0
- package/lib/cjs/autocomplete-scripts/zsh-autocomplete-script.cjs.map +1 -0
- package/lib/cjs/coerce/coerce-methods.cjs +2 -0
- package/lib/cjs/coerce/coerce-methods.cjs.map +1 -0
- package/lib/cjs/coerce/string-to-array.cjs +2 -0
- package/lib/cjs/coerce/string-to-array.cjs.map +1 -0
- package/lib/cjs/coerce/string-to-primitive.cjs +2 -0
- package/lib/cjs/coerce/string-to-primitive.cjs.map +1 -0
- package/lib/cjs/coerce/string-to-set.cjs +2 -0
- package/lib/cjs/coerce/string-to-set.cjs.map +1 -0
- package/lib/cjs/definitions/define-arguments.cjs +2 -0
- package/lib/cjs/definitions/define-arguments.cjs.map +1 -0
- package/lib/cjs/definitions/define-cli.cjs +2 -0
- package/lib/cjs/definitions/define-cli.cjs.map +1 -0
- package/lib/cjs/definitions/define-options.cjs +2 -0
- package/lib/cjs/definitions/define-options.cjs.map +1 -0
- package/lib/cjs/definitions/define-subcommand.cjs +2 -0
- package/lib/cjs/definitions/define-subcommand.cjs.map +1 -0
- package/lib/cjs/definitions/validate-cli-definition.cjs +2 -0
- package/lib/cjs/definitions/validate-cli-definition.cjs.map +1 -0
- package/lib/cjs/help-message/format-arguments.cjs +2 -0
- package/lib/cjs/help-message/format-arguments.cjs.map +1 -0
- package/lib/cjs/help-message/format-options.cjs +2 -0
- package/lib/cjs/help-message/format-options.cjs.map +1 -0
- package/lib/cjs/help-message/format-subcommands.cjs +2 -0
- package/lib/cjs/help-message/format-subcommands.cjs.map +1 -0
- package/lib/cjs/help-message/generate-for-cli.cjs +2 -0
- package/lib/cjs/help-message/generate-for-cli.cjs.map +1 -0
- package/lib/cjs/help-message/generate-for-subcommand.cjs +2 -0
- package/lib/cjs/help-message/generate-for-subcommand.cjs.map +1 -0
- package/lib/cjs/help-message/print-help.cjs +2 -0
- package/lib/cjs/help-message/print-help.cjs.map +1 -0
- package/lib/cjs/help-message/set-defaults.cjs +2 -0
- package/lib/cjs/help-message/set-defaults.cjs.map +1 -0
- package/lib/cjs/help-message/styles.cjs +2 -0
- package/lib/cjs/help-message/styles.cjs.map +1 -0
- package/lib/cjs/help-message/terminal-markdown.cjs +2 -0
- package/lib/cjs/help-message/terminal-markdown.cjs.map +1 -0
- package/lib/cjs/index.cjs +2 -0
- package/lib/cjs/index.cjs.map +1 -0
- package/lib/cjs/markdown/generate-markdown.cjs +2 -0
- package/lib/cjs/markdown/generate-markdown.cjs.map +1 -0
- package/lib/cjs/metadata/arguments-metadata.cjs +2 -0
- package/lib/cjs/metadata/arguments-metadata.cjs.map +1 -0
- package/lib/cjs/metadata/cli-metadata.cjs +2 -0
- package/lib/cjs/metadata/cli-metadata.cjs.map +1 -0
- package/lib/cjs/metadata/options-metadata.cjs +2 -0
- package/lib/cjs/metadata/options-metadata.cjs.map +1 -0
- package/lib/cjs/metadata/subcommands-metadata.cjs +2 -0
- package/lib/cjs/metadata/subcommands-metadata.cjs.map +1 -0
- package/lib/cjs/parse/context/cli-context-builder.cjs +2 -0
- package/lib/cjs/parse/context/cli-context-builder.cjs.map +1 -0
- package/lib/cjs/parse/context/object-context-builder.cjs +2 -0
- package/lib/cjs/parse/context/object-context-builder.cjs.map +1 -0
- package/lib/cjs/parse/parser-utilities.cjs +2 -0
- package/lib/cjs/parse/parser-utilities.cjs.map +1 -0
- package/lib/cjs/parse/safe-parse.cjs +2 -0
- package/lib/cjs/parse/safe-parse.cjs.map +1 -0
- package/lib/cjs/parse/validation/validate-context.cjs +2 -0
- package/lib/cjs/parse/validation/validate-context.cjs.map +1 -0
- package/lib/cjs/parse/validation/validators/arguments.cjs +2 -0
- package/lib/cjs/parse/validation/validators/arguments.cjs.map +1 -0
- package/lib/cjs/parse/validation/validators/conflict.cjs +2 -0
- package/lib/cjs/parse/validation/validators/conflict.cjs.map +1 -0
- package/lib/cjs/parse/validation/validators/exclusive.cjs +2 -0
- package/lib/cjs/parse/validation/validators/exclusive.cjs.map +1 -0
- package/lib/cjs/parse/validation/validators/explicitly-passed.cjs +2 -0
- package/lib/cjs/parse/validation/validators/explicitly-passed.cjs.map +1 -0
- package/lib/cjs/parse/validation/validators/options.cjs +2 -0
- package/lib/cjs/parse/validation/validators/options.cjs.map +1 -0
- package/lib/cjs/parse/validation/validators/requires.cjs +2 -0
- package/lib/cjs/parse/validation/validators/requires.cjs.map +1 -0
- package/lib/cjs/utilities.cjs +2 -0
- package/lib/cjs/utilities.cjs.map +1 -0
- package/lib/esm/autocomplete-scripts/bash-autocomplete-script.js +2 -0
- package/lib/esm/autocomplete-scripts/bash-autocomplete-script.js.map +1 -0
- package/lib/esm/autocomplete-scripts/powershell-autocomplete-script.js +2 -0
- package/lib/esm/autocomplete-scripts/powershell-autocomplete-script.js.map +1 -0
- package/lib/esm/autocomplete-scripts/zsh-autocomplete-script.js +42 -0
- package/lib/esm/autocomplete-scripts/zsh-autocomplete-script.js.map +1 -0
- package/lib/esm/coerce/coerce-methods.js +2 -0
- package/lib/esm/coerce/coerce-methods.js.map +1 -0
- package/lib/esm/coerce/string-to-array.js +2 -0
- package/lib/esm/coerce/string-to-array.js.map +1 -0
- package/lib/esm/coerce/string-to-primitive.js +2 -0
- package/lib/esm/coerce/string-to-primitive.js.map +1 -0
- package/lib/esm/coerce/string-to-set.js +2 -0
- package/lib/esm/coerce/string-to-set.js.map +1 -0
- package/lib/esm/definitions/define-arguments.js +2 -0
- package/lib/esm/definitions/define-arguments.js.map +1 -0
- package/lib/esm/definitions/define-cli.js +2 -0
- package/lib/esm/definitions/define-cli.js.map +1 -0
- package/lib/esm/definitions/define-options.js +2 -0
- package/lib/esm/definitions/define-options.js.map +1 -0
- package/lib/esm/definitions/define-subcommand.js +2 -0
- package/lib/esm/definitions/define-subcommand.js.map +1 -0
- package/lib/esm/definitions/validate-cli-definition.js +2 -0
- package/lib/esm/definitions/validate-cli-definition.js.map +1 -0
- package/lib/esm/help-message/format-arguments.js +2 -0
- package/lib/esm/help-message/format-arguments.js.map +1 -0
- package/lib/esm/help-message/format-options.js +2 -0
- package/lib/esm/help-message/format-options.js.map +1 -0
- package/lib/esm/help-message/format-subcommands.js +2 -0
- package/lib/esm/help-message/format-subcommands.js.map +1 -0
- package/lib/esm/help-message/generate-for-cli.js +2 -0
- package/lib/esm/help-message/generate-for-cli.js.map +1 -0
- package/lib/esm/help-message/generate-for-subcommand.js +2 -0
- package/lib/esm/help-message/generate-for-subcommand.js.map +1 -0
- package/lib/esm/help-message/print-help.js +2 -0
- package/lib/esm/help-message/print-help.js.map +1 -0
- package/lib/esm/help-message/set-defaults.js +2 -0
- package/lib/esm/help-message/set-defaults.js.map +1 -0
- package/lib/esm/help-message/styles.js +2 -0
- package/lib/esm/help-message/styles.js.map +1 -0
- package/lib/esm/help-message/terminal-markdown.js +2 -0
- package/lib/esm/help-message/terminal-markdown.js.map +1 -0
- package/lib/esm/index.js +2 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/markdown/generate-markdown.js +2 -0
- package/lib/esm/markdown/generate-markdown.js.map +1 -0
- package/lib/esm/metadata/arguments-metadata.js +2 -0
- package/lib/esm/metadata/arguments-metadata.js.map +1 -0
- package/lib/esm/metadata/cli-metadata.js +2 -0
- package/lib/esm/metadata/cli-metadata.js.map +1 -0
- package/lib/esm/metadata/options-metadata.js +2 -0
- package/lib/esm/metadata/options-metadata.js.map +1 -0
- package/lib/esm/metadata/subcommands-metadata.js +2 -0
- package/lib/esm/metadata/subcommands-metadata.js.map +1 -0
- package/lib/esm/parse/context/cli-context-builder.js +2 -0
- package/lib/esm/parse/context/cli-context-builder.js.map +1 -0
- package/lib/esm/parse/context/object-context-builder.js +2 -0
- package/lib/esm/parse/context/object-context-builder.js.map +1 -0
- package/lib/esm/parse/parser-utilities.js +2 -0
- package/lib/esm/parse/parser-utilities.js.map +1 -0
- package/lib/esm/parse/safe-parse.js +2 -0
- package/lib/esm/parse/safe-parse.js.map +1 -0
- package/lib/esm/parse/validation/validate-context.js +2 -0
- package/lib/esm/parse/validation/validate-context.js.map +1 -0
- package/lib/esm/parse/validation/validators/arguments.js +2 -0
- package/lib/esm/parse/validation/validators/arguments.js.map +1 -0
- package/lib/esm/parse/validation/validators/conflict.js +2 -0
- package/lib/esm/parse/validation/validators/conflict.js.map +1 -0
- package/lib/esm/parse/validation/validators/exclusive.js +2 -0
- package/lib/esm/parse/validation/validators/exclusive.js.map +1 -0
- package/lib/esm/parse/validation/validators/explicitly-passed.js +2 -0
- package/lib/esm/parse/validation/validators/explicitly-passed.js.map +1 -0
- package/lib/esm/parse/validation/validators/options.js +2 -0
- package/lib/esm/parse/validation/validators/options.js.map +1 -0
- package/lib/esm/parse/validation/validators/requires.js +2 -0
- package/lib/esm/parse/validation/validators/requires.js.map +1 -0
- package/lib/esm/utilities.js +2 -0
- package/lib/esm/utilities.js.map +1 -0
- package/lib/iife/index.js +2 -0
- package/lib/iife/index.js.map +1 -0
- package/lib/mjs/autocomplete-scripts/bash-autocomplete-script.mjs +2 -0
- package/lib/mjs/autocomplete-scripts/bash-autocomplete-script.mjs.map +1 -0
- package/lib/mjs/autocomplete-scripts/powershell-autocomplete-script.mjs +2 -0
- package/lib/mjs/autocomplete-scripts/powershell-autocomplete-script.mjs.map +1 -0
- package/lib/mjs/autocomplete-scripts/zsh-autocomplete-script.mjs +42 -0
- package/lib/mjs/autocomplete-scripts/zsh-autocomplete-script.mjs.map +1 -0
- package/lib/mjs/coerce/coerce-methods.mjs +2 -0
- package/lib/mjs/coerce/coerce-methods.mjs.map +1 -0
- package/lib/mjs/coerce/string-to-array.mjs +2 -0
- package/lib/mjs/coerce/string-to-array.mjs.map +1 -0
- package/lib/mjs/coerce/string-to-primitive.mjs +2 -0
- package/lib/mjs/coerce/string-to-primitive.mjs.map +1 -0
- package/lib/mjs/coerce/string-to-set.mjs +2 -0
- package/lib/mjs/coerce/string-to-set.mjs.map +1 -0
- package/lib/mjs/definitions/define-arguments.mjs +2 -0
- package/lib/mjs/definitions/define-arguments.mjs.map +1 -0
- package/lib/mjs/definitions/define-cli.mjs +2 -0
- package/lib/mjs/definitions/define-cli.mjs.map +1 -0
- package/lib/mjs/definitions/define-options.mjs +2 -0
- package/lib/mjs/definitions/define-options.mjs.map +1 -0
- package/lib/mjs/definitions/define-subcommand.mjs +2 -0
- package/lib/mjs/definitions/define-subcommand.mjs.map +1 -0
- package/lib/mjs/definitions/validate-cli-definition.mjs +2 -0
- package/lib/mjs/definitions/validate-cli-definition.mjs.map +1 -0
- package/lib/mjs/help-message/format-arguments.mjs +2 -0
- package/lib/mjs/help-message/format-arguments.mjs.map +1 -0
- package/lib/mjs/help-message/format-options.mjs +2 -0
- package/lib/mjs/help-message/format-options.mjs.map +1 -0
- package/lib/mjs/help-message/format-subcommands.mjs +2 -0
- package/lib/mjs/help-message/format-subcommands.mjs.map +1 -0
- package/lib/mjs/help-message/generate-for-cli.mjs +2 -0
- package/lib/mjs/help-message/generate-for-cli.mjs.map +1 -0
- package/lib/mjs/help-message/generate-for-subcommand.mjs +2 -0
- package/lib/mjs/help-message/generate-for-subcommand.mjs.map +1 -0
- package/lib/mjs/help-message/print-help.mjs +2 -0
- package/lib/mjs/help-message/print-help.mjs.map +1 -0
- package/lib/mjs/help-message/set-defaults.mjs +2 -0
- package/lib/mjs/help-message/set-defaults.mjs.map +1 -0
- package/lib/mjs/help-message/styles.mjs +2 -0
- package/lib/mjs/help-message/styles.mjs.map +1 -0
- package/lib/mjs/help-message/terminal-markdown.mjs +2 -0
- package/lib/mjs/help-message/terminal-markdown.mjs.map +1 -0
- package/lib/mjs/index.mjs +2 -0
- package/lib/mjs/index.mjs.map +1 -0
- package/lib/mjs/markdown/generate-markdown.mjs +2 -0
- package/lib/mjs/markdown/generate-markdown.mjs.map +1 -0
- package/lib/mjs/metadata/arguments-metadata.mjs +2 -0
- package/lib/mjs/metadata/arguments-metadata.mjs.map +1 -0
- package/lib/mjs/metadata/cli-metadata.mjs +2 -0
- package/lib/mjs/metadata/cli-metadata.mjs.map +1 -0
- package/lib/mjs/metadata/options-metadata.mjs +2 -0
- package/lib/mjs/metadata/options-metadata.mjs.map +1 -0
- package/lib/mjs/metadata/subcommands-metadata.mjs +2 -0
- package/lib/mjs/metadata/subcommands-metadata.mjs.map +1 -0
- package/lib/mjs/parse/context/cli-context-builder.mjs +2 -0
- package/lib/mjs/parse/context/cli-context-builder.mjs.map +1 -0
- package/lib/mjs/parse/context/object-context-builder.mjs +2 -0
- package/lib/mjs/parse/context/object-context-builder.mjs.map +1 -0
- package/lib/mjs/parse/parser-utilities.mjs +2 -0
- package/lib/mjs/parse/parser-utilities.mjs.map +1 -0
- package/lib/mjs/parse/safe-parse.mjs +2 -0
- package/lib/mjs/parse/safe-parse.mjs.map +1 -0
- package/lib/mjs/parse/validation/validate-context.mjs +2 -0
- package/lib/mjs/parse/validation/validate-context.mjs.map +1 -0
- package/lib/mjs/parse/validation/validators/arguments.mjs +2 -0
- package/lib/mjs/parse/validation/validators/arguments.mjs.map +1 -0
- package/lib/mjs/parse/validation/validators/conflict.mjs +2 -0
- package/lib/mjs/parse/validation/validators/conflict.mjs.map +1 -0
- package/lib/mjs/parse/validation/validators/exclusive.mjs +2 -0
- package/lib/mjs/parse/validation/validators/exclusive.mjs.map +1 -0
- package/lib/mjs/parse/validation/validators/explicitly-passed.mjs +2 -0
- package/lib/mjs/parse/validation/validators/explicitly-passed.mjs.map +1 -0
- package/lib/mjs/parse/validation/validators/options.mjs +2 -0
- package/lib/mjs/parse/validation/validators/options.mjs.map +1 -0
- package/lib/mjs/parse/validation/validators/requires.mjs +2 -0
- package/lib/mjs/parse/validation/validators/requires.mjs.map +1 -0
- package/lib/mjs/utilities.mjs +2 -0
- package/lib/mjs/utilities.mjs.map +1 -0
- package/lib/typescript/autocomplete-scripts/bash-autocomplete-script.d.ts +2 -2
- package/lib/typescript/autocomplete-scripts/bash-autocomplete-script.d.ts.map +1 -1
- package/lib/typescript/autocomplete-scripts/powershell-autocomplete-script.d.ts +2 -2
- package/lib/typescript/autocomplete-scripts/powershell-autocomplete-script.d.ts.map +1 -1
- package/lib/typescript/autocomplete-scripts/zsh-autocomplete-script.d.ts +2 -2
- package/lib/typescript/autocomplete-scripts/zsh-autocomplete-script.d.ts.map +1 -1
- package/lib/typescript/coerce/coerce-methods.d.ts +20 -0
- package/lib/typescript/coerce/coerce-methods.d.ts.map +1 -0
- package/lib/typescript/coerce/string-to-array.d.ts +6 -0
- package/lib/typescript/coerce/string-to-array.d.ts.map +1 -0
- package/lib/typescript/coerce/string-to-primitive.d.ts +5 -0
- package/lib/typescript/coerce/string-to-primitive.d.ts.map +1 -0
- package/lib/typescript/coerce/string-to-set.d.ts +6 -0
- package/lib/typescript/coerce/string-to-set.d.ts.map +1 -0
- package/lib/typescript/definitions/define-arguments.d.ts +7 -0
- package/lib/typescript/definitions/define-arguments.d.ts.map +1 -0
- package/lib/typescript/definitions/define-cli.d.ts +24 -0
- package/lib/typescript/definitions/define-cli.d.ts.map +1 -0
- package/lib/typescript/definitions/define-options.d.ts +7 -0
- package/lib/typescript/definitions/define-options.d.ts.map +1 -0
- package/lib/typescript/definitions/define-subcommand.d.ts +17 -0
- package/lib/typescript/definitions/define-subcommand.d.ts.map +1 -0
- package/lib/typescript/definitions/validate-cli-definition.d.ts +4 -0
- package/lib/typescript/definitions/validate-cli-definition.d.ts.map +1 -0
- package/lib/typescript/help-message/format-arguments.d.ts +3 -3
- package/lib/typescript/help-message/format-arguments.d.ts.map +1 -1
- package/lib/typescript/help-message/format-options.d.ts +3 -3
- package/lib/typescript/help-message/format-options.d.ts.map +1 -1
- package/lib/typescript/help-message/format-subcommands.d.ts +3 -3
- package/lib/typescript/help-message/format-subcommands.d.ts.map +1 -1
- package/lib/typescript/help-message/generate-for-cli.d.ts +8 -0
- package/lib/typescript/help-message/generate-for-cli.d.ts.map +1 -0
- package/lib/typescript/help-message/generate-for-subcommand.d.ts +4 -0
- package/lib/typescript/help-message/generate-for-subcommand.d.ts.map +1 -0
- package/lib/typescript/help-message/print-help.d.ts +5 -0
- package/lib/typescript/help-message/print-help.d.ts.map +1 -0
- package/lib/typescript/help-message/set-defaults.d.ts +4 -0
- package/lib/typescript/help-message/set-defaults.d.ts.map +1 -0
- package/lib/typescript/help-message/styles.d.ts +30 -106
- package/lib/typescript/help-message/styles.d.ts.map +1 -1
- package/lib/typescript/help-message/terminal-markdown.d.ts +3 -0
- package/lib/typescript/help-message/terminal-markdown.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +23 -35
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/markdown/generate-markdown.d.ts +2 -2
- package/lib/typescript/markdown/generate-markdown.d.ts.map +1 -1
- package/lib/typescript/metadata/arguments-metadata.d.ts +4 -0
- package/lib/typescript/metadata/arguments-metadata.d.ts.map +1 -0
- package/lib/typescript/metadata/cli-metadata.d.ts +4 -0
- package/lib/typescript/metadata/cli-metadata.d.ts.map +1 -0
- package/lib/typescript/metadata/options-metadata.d.ts +4 -0
- package/lib/typescript/metadata/options-metadata.d.ts.map +1 -0
- package/lib/typescript/metadata/subcommands-metadata.d.ts +4 -0
- package/lib/typescript/metadata/subcommands-metadata.d.ts.map +1 -0
- package/lib/typescript/parse/context/cli-context-builder.d.ts +9 -0
- package/lib/typescript/parse/context/cli-context-builder.d.ts.map +1 -0
- package/lib/typescript/parse/context/object-context-builder.d.ts +6 -0
- package/lib/typescript/parse/context/object-context-builder.d.ts.map +1 -0
- package/lib/typescript/{parser/parse/parser-helpers.d.ts → parse/parser-utilities.d.ts} +18 -9
- package/lib/typescript/parse/parser-utilities.d.ts.map +1 -0
- package/lib/typescript/parse/safe-parse.d.ts +5 -0
- package/lib/typescript/parse/safe-parse.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validate-context.d.ts +6 -0
- package/lib/typescript/parse/validation/validate-context.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validators/arguments.d.ts +12 -0
- package/lib/typescript/parse/validation/validators/arguments.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validators/conflict.d.ts +16 -0
- package/lib/typescript/parse/validation/validators/conflict.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validators/exclusive.d.ts +16 -0
- package/lib/typescript/parse/validation/validators/exclusive.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validators/explicitly-passed.d.ts +5 -0
- package/lib/typescript/parse/validation/validators/explicitly-passed.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validators/options.d.ts +12 -0
- package/lib/typescript/parse/validation/validators/options.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validators/requires.d.ts +18 -0
- package/lib/typescript/parse/validation/validators/requires.d.ts.map +1 -0
- package/lib/typescript/types/context-types.d.ts +135 -0
- package/lib/typescript/types/context-types.d.ts.map +1 -0
- package/lib/typescript/types/definitions-types.d.ts +294 -0
- package/lib/typescript/types/definitions-types.d.ts.map +1 -0
- package/lib/typescript/types/help-message-types.d.ts +134 -0
- package/lib/typescript/types/help-message-types.d.ts.map +1 -0
- package/lib/typescript/types/io-types.d.ts +96 -0
- package/lib/typescript/types/io-types.d.ts.map +1 -0
- package/lib/typescript/types/metadata-types.d.ts +75 -0
- package/lib/typescript/types/metadata-types.d.ts.map +1 -0
- package/lib/typescript/types/schema-types.d.ts +6 -0
- package/lib/typescript/types/schema-types.d.ts.map +1 -0
- package/lib/typescript/types/types.d.ts +61 -0
- package/lib/typescript/types/types.d.ts.map +1 -0
- package/lib/typescript/types/utilities-types.d.ts +17 -0
- package/lib/typescript/types/utilities-types.d.ts.map +1 -0
- package/lib/typescript/utilities.d.ts +24 -10
- package/lib/typescript/utilities.d.ts.map +1 -1
- package/package.json +29 -26
- package/src/autocomplete-scripts/bash-autocomplete-script.ts +13 -9
- package/src/autocomplete-scripts/powershell-autocomplete-script.ts +21 -13
- package/src/autocomplete-scripts/zsh-autocomplete-script.ts +27 -23
- package/src/coerce/coerce-methods.ts +75 -0
- package/src/coerce/string-to-array.ts +18 -0
- package/src/coerce/string-to-primitive.ts +31 -0
- package/src/coerce/string-to-set.ts +15 -0
- package/src/definitions/define-arguments.ts +10 -0
- package/src/definitions/define-cli.ts +105 -0
- package/src/definitions/define-options.ts +12 -0
- package/src/definitions/define-subcommand.ts +57 -0
- package/src/definitions/validate-cli-definition.ts +331 -0
- package/src/help-message/format-arguments.ts +57 -33
- package/src/help-message/format-options.ts +59 -34
- package/src/help-message/format-subcommands.ts +43 -21
- package/src/help-message/generate-for-cli.ts +114 -0
- package/src/help-message/generate-for-subcommand.ts +32 -0
- package/src/help-message/print-help.ts +13 -0
- package/src/help-message/set-defaults.ts +34 -0
- package/src/help-message/styles.ts +148 -103
- package/src/help-message/terminal-markdown.ts +147 -0
- package/src/index.ts +28 -97
- package/src/markdown/generate-markdown.ts +47 -58
- package/src/metadata/arguments-metadata.ts +28 -0
- package/src/metadata/cli-metadata.ts +26 -0
- package/src/metadata/options-metadata.ts +38 -0
- package/src/metadata/subcommands-metadata.ts +35 -0
- package/src/parse/context/cli-context-builder.ts +246 -0
- package/src/parse/context/object-context-builder.ts +63 -0
- package/src/{parser/parse/parser-helpers.ts → parse/parser-utilities.ts} +46 -25
- package/src/parse/safe-parse.ts +76 -0
- package/src/parse/validation/validate-context.ts +23 -0
- package/src/parse/validation/validators/arguments.ts +59 -0
- package/src/parse/validation/validators/conflict.ts +68 -0
- package/src/parse/validation/validators/exclusive.ts +70 -0
- package/src/parse/validation/validators/explicitly-passed.ts +15 -0
- package/src/parse/validation/validators/options.ts +59 -0
- package/src/parse/validation/validators/requires.ts +82 -0
- package/src/types/context-types.ts +171 -0
- package/src/types/definitions-types.ts +340 -0
- package/src/types/help-message-types.ts +153 -0
- package/src/types/io-types.ts +131 -0
- package/src/types/metadata-types.ts +104 -0
- package/src/types/schema-types.ts +9 -0
- package/src/types/types.ts +72 -0
- package/src/types/utilities-types.ts +26 -0
- package/src/utilities.ts +200 -23
- package/lib/commonjs/autocomplete-scripts/bash-autocomplete-script.cjs +0 -42
- package/lib/commonjs/autocomplete-scripts/bash-autocomplete-script.cjs.map +0 -1
- package/lib/commonjs/autocomplete-scripts/powershell-autocomplete-script.cjs +0 -31
- package/lib/commonjs/autocomplete-scripts/powershell-autocomplete-script.cjs.map +0 -1
- package/lib/commonjs/autocomplete-scripts/zsh-autocomplete-script.cjs +0 -41
- package/lib/commonjs/autocomplete-scripts/zsh-autocomplete-script.cjs.map +0 -1
- package/lib/commonjs/help-message/format-arguments.cjs +0 -1
- package/lib/commonjs/help-message/format-arguments.cjs.map +0 -1
- package/lib/commonjs/help-message/format-cli.cjs +0 -1
- package/lib/commonjs/help-message/format-cli.cjs.map +0 -1
- package/lib/commonjs/help-message/format-options.cjs +0 -1
- package/lib/commonjs/help-message/format-options.cjs.map +0 -1
- package/lib/commonjs/help-message/format-subcommands.cjs +0 -1
- package/lib/commonjs/help-message/format-subcommands.cjs.map +0 -1
- package/lib/commonjs/help-message/styles.cjs +0 -1
- package/lib/commonjs/help-message/styles.cjs.map +0 -1
- package/lib/commonjs/index.cjs +0 -1
- package/lib/commonjs/index.cjs.map +0 -1
- package/lib/commonjs/markdown/generate-markdown.cjs +0 -1
- package/lib/commonjs/markdown/generate-markdown.cjs.map +0 -1
- package/lib/commonjs/metadata/get-arguments-metadata.cjs +0 -1
- package/lib/commonjs/metadata/get-arguments-metadata.cjs.map +0 -1
- package/lib/commonjs/metadata/get-cli-metadata.cjs +0 -1
- package/lib/commonjs/metadata/get-cli-metadata.cjs.map +0 -1
- package/lib/commonjs/metadata/get-options-metadata.cjs +0 -1
- package/lib/commonjs/metadata/get-options-metadata.cjs.map +0 -1
- package/lib/commonjs/metadata/get-subcommands-metadata.cjs +0 -1
- package/lib/commonjs/metadata/get-subcommands-metadata.cjs.map +0 -1
- package/lib/commonjs/parser/parse/parse.cjs +0 -1
- package/lib/commonjs/parser/parse/parse.cjs.map +0 -1
- package/lib/commonjs/parser/parse/parser-helpers.cjs +0 -1
- package/lib/commonjs/parser/parse/parser-helpers.cjs.map +0 -1
- package/lib/commonjs/parser/safe-parse.cjs +0 -1
- package/lib/commonjs/parser/safe-parse.cjs.map +0 -1
- package/lib/commonjs/parser/unsafe-parse.cjs +0 -1
- package/lib/commonjs/parser/unsafe-parse.cjs.map +0 -1
- package/lib/commonjs/parser/validate/validate-type.cjs +0 -1
- package/lib/commonjs/parser/validate/validate-type.cjs.map +0 -1
- package/lib/commonjs/parser/validate/validate.cjs +0 -1
- package/lib/commonjs/parser/validate/validate.cjs.map +0 -1
- package/lib/commonjs/utilities.cjs +0 -1
- package/lib/commonjs/utilities.cjs.map +0 -1
- package/lib/commonjs/zod-utilities.cjs +0 -1
- package/lib/commonjs/zod-utilities.cjs.map +0 -1
- package/lib/module/autocomplete-scripts/bash-autocomplete-script.mjs +0 -42
- package/lib/module/autocomplete-scripts/bash-autocomplete-script.mjs.map +0 -1
- package/lib/module/autocomplete-scripts/powershell-autocomplete-script.mjs +0 -31
- package/lib/module/autocomplete-scripts/powershell-autocomplete-script.mjs.map +0 -1
- package/lib/module/autocomplete-scripts/zsh-autocomplete-script.mjs +0 -41
- package/lib/module/autocomplete-scripts/zsh-autocomplete-script.mjs.map +0 -1
- package/lib/module/help-message/format-arguments.mjs +0 -1
- package/lib/module/help-message/format-arguments.mjs.map +0 -1
- package/lib/module/help-message/format-cli.mjs +0 -1
- package/lib/module/help-message/format-cli.mjs.map +0 -1
- package/lib/module/help-message/format-options.mjs +0 -1
- package/lib/module/help-message/format-options.mjs.map +0 -1
- package/lib/module/help-message/format-subcommands.mjs +0 -1
- package/lib/module/help-message/format-subcommands.mjs.map +0 -1
- package/lib/module/help-message/styles.mjs +0 -1
- package/lib/module/help-message/styles.mjs.map +0 -1
- package/lib/module/index.mjs +0 -1
- package/lib/module/index.mjs.map +0 -1
- package/lib/module/markdown/generate-markdown.mjs +0 -1
- package/lib/module/markdown/generate-markdown.mjs.map +0 -1
- package/lib/module/metadata/get-arguments-metadata.mjs +0 -1
- package/lib/module/metadata/get-arguments-metadata.mjs.map +0 -1
- package/lib/module/metadata/get-cli-metadata.mjs +0 -1
- package/lib/module/metadata/get-cli-metadata.mjs.map +0 -1
- package/lib/module/metadata/get-options-metadata.mjs +0 -1
- package/lib/module/metadata/get-options-metadata.mjs.map +0 -1
- package/lib/module/metadata/get-subcommands-metadata.mjs +0 -1
- package/lib/module/metadata/get-subcommands-metadata.mjs.map +0 -1
- package/lib/module/parser/parse/parse.mjs +0 -1
- package/lib/module/parser/parse/parse.mjs.map +0 -1
- package/lib/module/parser/parse/parser-helpers.mjs +0 -1
- package/lib/module/parser/parse/parser-helpers.mjs.map +0 -1
- package/lib/module/parser/safe-parse.mjs +0 -1
- package/lib/module/parser/safe-parse.mjs.map +0 -1
- package/lib/module/parser/unsafe-parse.mjs +0 -1
- package/lib/module/parser/unsafe-parse.mjs.map +0 -1
- package/lib/module/parser/validate/validate-type.mjs +0 -1
- package/lib/module/parser/validate/validate-type.mjs.map +0 -1
- package/lib/module/parser/validate/validate.mjs +0 -1
- package/lib/module/parser/validate/validate.mjs.map +0 -1
- package/lib/module/utilities.mjs +0 -1
- package/lib/module/utilities.mjs.map +0 -1
- package/lib/module/zod-utilities.mjs +0 -1
- package/lib/module/zod-utilities.mjs.map +0 -1
- package/lib/typescript/help-message/format-cli.d.ts +0 -6
- package/lib/typescript/help-message/format-cli.d.ts.map +0 -1
- package/lib/typescript/metadata/get-arguments-metadata.d.ts +0 -4
- package/lib/typescript/metadata/get-arguments-metadata.d.ts.map +0 -1
- package/lib/typescript/metadata/get-cli-metadata.d.ts +0 -4
- package/lib/typescript/metadata/get-cli-metadata.d.ts.map +0 -1
- package/lib/typescript/metadata/get-options-metadata.d.ts +0 -4
- package/lib/typescript/metadata/get-options-metadata.d.ts.map +0 -1
- package/lib/typescript/metadata/get-subcommands-metadata.d.ts +0 -4
- package/lib/typescript/metadata/get-subcommands-metadata.d.ts.map +0 -1
- package/lib/typescript/metadata/metadata-types.d.ts +0 -80
- package/lib/typescript/metadata/metadata-types.d.ts.map +0 -1
- package/lib/typescript/parser/parse/parse-types.d.ts +0 -85
- package/lib/typescript/parser/parse/parse-types.d.ts.map +0 -1
- package/lib/typescript/parser/parse/parse.d.ts +0 -4
- package/lib/typescript/parser/parse/parse.d.ts.map +0 -1
- package/lib/typescript/parser/parse/parser-helpers.d.ts.map +0 -1
- package/lib/typescript/parser/safe-parse.d.ts +0 -4
- package/lib/typescript/parser/safe-parse.d.ts.map +0 -1
- package/lib/typescript/parser/unsafe-parse.d.ts +0 -4
- package/lib/typescript/parser/unsafe-parse.d.ts.map +0 -1
- package/lib/typescript/parser/validate/validate-type.d.ts +0 -22
- package/lib/typescript/parser/validate/validate-type.d.ts.map +0 -1
- package/lib/typescript/parser/validate/validate.d.ts +0 -11
- package/lib/typescript/parser/validate/validate.d.ts.map +0 -1
- package/lib/typescript/types.d.ts +0 -294
- package/lib/typescript/types.d.ts.map +0 -1
- package/lib/typescript/zod-utilities.d.ts +0 -28
- package/lib/typescript/zod-utilities.d.ts.map +0 -1
- package/src/help-message/format-cli.ts +0 -141
- package/src/metadata/get-arguments-metadata.ts +0 -25
- package/src/metadata/get-cli-metadata.ts +0 -23
- package/src/metadata/get-options-metadata.ts +0 -35
- package/src/metadata/get-subcommands-metadata.ts +0 -32
- package/src/metadata/metadata-types.ts +0 -114
- package/src/parser/parse/parse-types.ts +0 -89
- package/src/parser/parse/parse.ts +0 -230
- package/src/parser/safe-parse.ts +0 -103
- package/src/parser/unsafe-parse.ts +0 -98
- package/src/parser/validate/validate-type.ts +0 -21
- package/src/parser/validate/validate.ts +0 -66
- package/src/types.ts +0 -365
- package/src/zod-utilities.ts +0 -214
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { prettifyError } from "zod/v4/core";
|
|
2
|
-
|
|
3
|
-
import { generateOrdinalSuffix, stringToBoolean } from "../../utilities.js";
|
|
4
|
-
import { isBooleanSchema, safeParseSchema } from "../../zod-utilities.js";
|
|
5
|
-
|
|
6
|
-
import type { ParsedContext } from "../parse/parse-types.js";
|
|
7
|
-
|
|
8
|
-
/** The return result object temporarily type. used inside the `parse` function */
|
|
9
|
-
type ResultsTemporaryType = Record<string, unknown> & {
|
|
10
|
-
subcommand: string | undefined;
|
|
11
|
-
positional?: string[];
|
|
12
|
-
arguments?: unknown[];
|
|
13
|
-
ctx: ParsedContext;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export function validate(parsedData: ParsedContext) {
|
|
17
|
-
const results: ResultsTemporaryType = {
|
|
18
|
-
subcommand: parsedData.subcommand,
|
|
19
|
-
positional: parsedData.positional,
|
|
20
|
-
ctx: parsedData,
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
// validate options
|
|
24
|
-
for (const [optionName, { schema, rawValue, flag }] of Object.entries(parsedData.options)) {
|
|
25
|
-
let optionsValue: string | boolean | undefined = rawValue;
|
|
26
|
-
|
|
27
|
-
// infer boolean value if possible
|
|
28
|
-
if (flag && rawValue && isBooleanSchema(schema)) {
|
|
29
|
-
const booleanValue = stringToBoolean(rawValue);
|
|
30
|
-
if (typeof booleanValue === "boolean") {
|
|
31
|
-
const isNegated = flag.startsWith("--no");
|
|
32
|
-
optionsValue = isNegated ? !booleanValue : booleanValue;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const safeParseResult = safeParseSchema(schema, optionsValue);
|
|
37
|
-
if (!safeParseResult.success) {
|
|
38
|
-
throw new Error(`Invalid value "${rawValue}" for "${flag}": ${prettifyError(safeParseResult.error)}`, {
|
|
39
|
-
cause: "zod-args-parser",
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
results[optionName] = safeParseResult.data;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// validate arguments
|
|
47
|
-
if (parsedData.arguments) {
|
|
48
|
-
if (!results.arguments) results.arguments = [];
|
|
49
|
-
|
|
50
|
-
for (const { schema, rawValue } of parsedData.arguments) {
|
|
51
|
-
const argumentValue = rawValue && isBooleanSchema(schema) ? stringToBoolean(rawValue) : rawValue;
|
|
52
|
-
|
|
53
|
-
const safeParseResult = safeParseSchema(schema, argumentValue);
|
|
54
|
-
if (!safeParseResult.success) {
|
|
55
|
-
throw new Error(
|
|
56
|
-
`The ${generateOrdinalSuffix(results.arguments.length)} argument "${rawValue}" is invalid: ${prettifyError(safeParseResult.error)}`,
|
|
57
|
-
{ cause: "zod-args-parser" },
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
results.arguments.push(safeParseResult.data);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return results;
|
|
66
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,365 +0,0 @@
|
|
|
1
|
-
import type * as Z3 from "zod/v3";
|
|
2
|
-
import type * as Z4 from "zod/v4/core";
|
|
3
|
-
import type { ParseResult } from "./parser/parse/parse-types.js";
|
|
4
|
-
import type { ValidateResult } from "./parser/validate/validate-type.js";
|
|
5
|
-
|
|
6
|
-
export type SchemaV3 = Z3.ZodTypeAny;
|
|
7
|
-
export type SchemaV4 = Z4.$ZodType;
|
|
8
|
-
export type Schema = SchemaV3 | SchemaV4;
|
|
9
|
-
|
|
10
|
-
export type ZodInferOutput<T extends Schema> = T extends SchemaV4
|
|
11
|
-
? Z4.infer<T>
|
|
12
|
-
: T extends SchemaV3
|
|
13
|
-
? Z3.infer<T>
|
|
14
|
-
: never;
|
|
15
|
-
|
|
16
|
-
export type ZodInferInput<T extends Schema> = T extends SchemaV4
|
|
17
|
-
? Z4.input<T>
|
|
18
|
-
: T extends SchemaV3
|
|
19
|
-
? Z3.input<T>
|
|
20
|
-
: never;
|
|
21
|
-
|
|
22
|
-
export interface Subcommand {
|
|
23
|
-
/**
|
|
24
|
-
* - The subcommand name
|
|
25
|
-
* - Make sure to not duplicate commands and aliases.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* name: "test";
|
|
29
|
-
* name: "run-app";
|
|
30
|
-
*/
|
|
31
|
-
name: string;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* - The description of the subcommand.
|
|
35
|
-
* - Used for generating the help message.
|
|
36
|
-
*/
|
|
37
|
-
description?: string;
|
|
38
|
-
|
|
39
|
-
/** - The usage message in the help message. */
|
|
40
|
-
usage?: string;
|
|
41
|
-
|
|
42
|
-
/** - Used for generating the help message. */
|
|
43
|
-
placeholder?: string;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* - Provide an example to show to the user.
|
|
47
|
-
* - Used for generating the help message.
|
|
48
|
-
*/
|
|
49
|
-
example?: string;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* - The aliases of the subcommand.
|
|
53
|
-
* - Make sure to not duplicate aliases and commands.
|
|
54
|
-
*/
|
|
55
|
-
aliases?: string[];
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* - Allows positional arguments for this subcommand.
|
|
59
|
-
* - Unlike `arguments`, which are strictly typed, positional arguments are untyped and represented as a string array of
|
|
60
|
-
* variable length.
|
|
61
|
-
* - When enabled and `arguments` are provided, `arguments` will be parsed first. Any remaining arguments will be
|
|
62
|
-
* considered positional arguments and added to the `positional` property in the result.
|
|
63
|
-
*/
|
|
64
|
-
allowPositional?: boolean;
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* - The options of the command.
|
|
68
|
-
* - Those options are specific to this subcommand.
|
|
69
|
-
*/
|
|
70
|
-
options?: [Option, ...Option[]];
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* - Specifies a list of strictly typed arguments.
|
|
74
|
-
* - The order is important; for example, the first argument will be validated against the first specified type.
|
|
75
|
-
* - It is recommended to not use optional arguments as the parser will fill the arguments by order and can't determine
|
|
76
|
-
* which arguments are optional.
|
|
77
|
-
*/
|
|
78
|
-
arguments?: [Argument, ...Argument[]];
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* - The action is executed with the result of the parsed arguments.
|
|
82
|
-
* - To get typescript types use `setAction` instead of this.
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
* const helpCommand = createSubcommand({ name: "help", options: [...] });
|
|
86
|
-
* helpCommand.setAction(res => console.log(res));
|
|
87
|
-
*/
|
|
88
|
-
action?: (data?: any) => any;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* - The preValidation hook is executed before the action.
|
|
92
|
-
* - To get typescript types use `setPreValidationHook` instead of this.
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* const helpCommand = createSubcommand({ name: "help", options: [...] });
|
|
96
|
-
* helpCommand.setPreValidationHook(ctx => console.log(ctx));
|
|
97
|
-
*/
|
|
98
|
-
preValidation?: (context?: any) => any;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export type Cli = Prettify<
|
|
102
|
-
Omit<Subcommand, "name" | "aliases" | "placeholder"> & {
|
|
103
|
-
/** - The name of the CLI program. */
|
|
104
|
-
cliName: string;
|
|
105
|
-
}
|
|
106
|
-
>;
|
|
107
|
-
|
|
108
|
-
export interface Option {
|
|
109
|
-
/**
|
|
110
|
-
* The name of the option, use a valid **JavaScript** variable name.\
|
|
111
|
-
* **Supports:** `camelCase`, `PascalCase`, `snake_case`, and `SCREAMING_SNAKE_CASE`.\
|
|
112
|
-
* **Examples:**
|
|
113
|
-
*
|
|
114
|
-
* - `I` or `i` ➡️ `-i`
|
|
115
|
-
* - `InputDir`, `inputDir`, or `INPUT_DIR` ➡️ `--input-dir`
|
|
116
|
-
* - `Help`, `help`, or `HELP` ➡️ `--help`
|
|
117
|
-
*/
|
|
118
|
-
name: string;
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* - The will be used to validate the user input.
|
|
122
|
-
*
|
|
123
|
-
* @see https://zod.dev/api
|
|
124
|
-
*/
|
|
125
|
-
type: Schema;
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* - The description of the option.
|
|
129
|
-
* - Used for generating the help message.
|
|
130
|
-
*/
|
|
131
|
-
description?: string;
|
|
132
|
-
|
|
133
|
-
/** - Used for generating the help message. */
|
|
134
|
-
placeholder?: string;
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* - The example of using the option.
|
|
138
|
-
* - Used for generating the help message.
|
|
139
|
-
*/
|
|
140
|
-
example?: string;
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* - The aliases of the option, use `CamelCase`.
|
|
144
|
-
* - Here you can specify short names or flags.
|
|
145
|
-
* - Make sure to not duplicate aliases.
|
|
146
|
-
*/
|
|
147
|
-
aliases?: [string, ...string[]];
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export interface Argument {
|
|
151
|
-
/** - The name of the argument. */
|
|
152
|
-
name: string;
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* - The will be used to validate the user input.
|
|
156
|
-
*
|
|
157
|
-
* @see https://zod.dev/api
|
|
158
|
-
*/
|
|
159
|
-
type: Schema;
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* - The description of the argument.
|
|
163
|
-
* - Used for generating the help message.
|
|
164
|
-
*/
|
|
165
|
-
description?: string;
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* - The example of using the argument.
|
|
169
|
-
* - Used for generating the help message.
|
|
170
|
-
*/
|
|
171
|
-
example?: string;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export type ColorFunctionType = (...text: unknown[]) => string;
|
|
175
|
-
|
|
176
|
-
/** - The colors to use for the help message. */
|
|
177
|
-
export type HelpMessageStyle = Record<
|
|
178
|
-
| "title"
|
|
179
|
-
| "description"
|
|
180
|
-
| "default"
|
|
181
|
-
| "optional"
|
|
182
|
-
| "exampleTitle"
|
|
183
|
-
| "example"
|
|
184
|
-
| "command"
|
|
185
|
-
| "option"
|
|
186
|
-
| "argument"
|
|
187
|
-
| "placeholder"
|
|
188
|
-
| "punctuation",
|
|
189
|
-
ColorFunctionType
|
|
190
|
-
>;
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* - Infer the options type from a subcommand.
|
|
194
|
-
*
|
|
195
|
-
* @deprecated Use `InferOptionsOutput` instead.
|
|
196
|
-
*/
|
|
197
|
-
export type InferOptionsType<T extends Partial<Subcommand>> = InferOptionsOutput<T>;
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* - Infer the options output type (after zod validation) from a subcommand.
|
|
201
|
-
*
|
|
202
|
-
* @example
|
|
203
|
-
* const subcommand = createSubcommand({ name: "build", options: [...] });
|
|
204
|
-
* type OptionsType = InferOptionsOutput<typeof subcommand>;
|
|
205
|
-
*/
|
|
206
|
-
export type InferOptionsOutput<T extends Partial<Subcommand>> = T["options"] extends infer U extends Option[]
|
|
207
|
-
? ToOptional<{ [K in U[number]["name"]]: ZodInferOutput<Extract<U[number], { name: K }>["type"]> }>
|
|
208
|
-
: undefined;
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* - Infer the options input type (before zod validation) from a subcommand.
|
|
212
|
-
*
|
|
213
|
-
* @example
|
|
214
|
-
* const subcommand = createSubcommand({ name: "build", options: [...] });
|
|
215
|
-
* type OptionsType = InferOptionsInput<typeof subcommand>;
|
|
216
|
-
*/
|
|
217
|
-
export type InferOptionsInput<T extends Partial<Subcommand>> = T["options"] extends infer U extends Option[]
|
|
218
|
-
? ToOptional<{ [K in U[number]["name"]]: ZodInferInput<Extract<U[number], { name: K }>["type"]> }>
|
|
219
|
-
: undefined;
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* - Infer the arguments output type (after zod validation) from a subcommand.
|
|
223
|
-
*
|
|
224
|
-
* @deprecated Use `InferArgumentsOutput` instead.
|
|
225
|
-
*/
|
|
226
|
-
export type InferArgumentsType<T extends Partial<Subcommand>> = InferArgumentsOutput<T>;
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* - Infer the arguments output type (after zod validation) from a subcommand.
|
|
230
|
-
*
|
|
231
|
-
* @example
|
|
232
|
-
* const subcommand = createSubcommand({ name: "build", arguments: [...] });
|
|
233
|
-
* type ArgumentsType = InferArgumentsOutput<typeof subcommand>;
|
|
234
|
-
*/
|
|
235
|
-
export type InferArgumentsOutput<T extends Partial<Subcommand>> = T["arguments"] extends infer U extends Argument[]
|
|
236
|
-
? { [K in keyof U]: U[K] extends { type: Schema } ? ZodInferOutput<U[K]["type"]> : never }
|
|
237
|
-
: undefined;
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* - Infer the arguments Input type (before zod validation) from a subcommand.
|
|
241
|
-
*
|
|
242
|
-
* @example
|
|
243
|
-
* const subcommand = createSubcommand({ name: "build", arguments: [...] });
|
|
244
|
-
* type ArgumentsType = InferArgumentsInput<typeof subcommand>;
|
|
245
|
-
*/
|
|
246
|
-
export type InferArgumentsInput<T extends Partial<Subcommand>> = T["arguments"] extends infer U extends Argument[]
|
|
247
|
-
? { [K in keyof U]: U[K] extends { type: Schema } ? ZodInferInput<U[K]["type"]> : never }
|
|
248
|
-
: undefined;
|
|
249
|
-
|
|
250
|
-
/** `{ some props } & { other props }` => `{ some props, other props }` */
|
|
251
|
-
export type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
252
|
-
|
|
253
|
-
/** Allow string type for literal union and get auto completion */
|
|
254
|
-
export type LiteralUnion<T extends string> = T | (string & {});
|
|
255
|
-
|
|
256
|
-
/** Extract the undefined properties from an object */
|
|
257
|
-
export type UndefinedProperties<T> = { [P in keyof T]-?: undefined extends T[P] ? P : never }[keyof T];
|
|
258
|
-
|
|
259
|
-
/** Make undefined properties optional? */
|
|
260
|
-
export type ToOptional<T> = Prettify<
|
|
261
|
-
Partial<Pick<T, UndefinedProperties<T>>> & Pick<T, Exclude<keyof T, UndefinedProperties<T>>>
|
|
262
|
-
>;
|
|
263
|
-
|
|
264
|
-
export type NoSubcommand = { name: undefined };
|
|
265
|
-
|
|
266
|
-
export type PrintMethods<N extends Subcommand["name"]> = {
|
|
267
|
-
printCliHelp: (style?: Partial<HelpMessageStyle>) => void;
|
|
268
|
-
printSubcommandHelp: (subcommand: LiteralUnion<NonNullable<N>>, style?: Partial<HelpMessageStyle>) => void;
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
export type UnsafeParseResult<S extends Partial<Subcommand>[]> =
|
|
272
|
-
CheckDuplicatedSubcommands<S> extends infer E extends string
|
|
273
|
-
? E
|
|
274
|
-
: Prettify<ValidateResult<S> & PrintMethods<NonNullable<S[number]["name"]>>>;
|
|
275
|
-
|
|
276
|
-
export type SafeParseResult<S extends Partial<Subcommand>[]> =
|
|
277
|
-
CheckDuplicatedSubcommands<S> extends infer E extends string
|
|
278
|
-
? E
|
|
279
|
-
: Prettify<
|
|
280
|
-
({ success: false; error: Error } | { success: true; data: ValidateResult<S> }) &
|
|
281
|
-
PrintMethods<NonNullable<S[number]["name"]>>
|
|
282
|
-
>;
|
|
283
|
-
|
|
284
|
-
export type ActionsFunctions<T extends Subcommand | Cli> = {
|
|
285
|
-
setAction: (actions: (data: UnsafeParseResult<[T]>) => void) => void;
|
|
286
|
-
setPreValidationHook: (hook: (context: ParseResult<[T]>) => void) => void;
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
/** - Combine `name` and `aliases` to a `string[]` */
|
|
290
|
-
type MapNameAndAliasesToStringArray<T extends { name?: string; aliases?: string[] }[]> = T extends [
|
|
291
|
-
infer First extends Subcommand,
|
|
292
|
-
...infer Rest,
|
|
293
|
-
]
|
|
294
|
-
? Rest extends { name?: string; aliases?: string[] }[]
|
|
295
|
-
? [
|
|
296
|
-
First["name"],
|
|
297
|
-
...(First["aliases"] extends string[] ? First["aliases"] : []),
|
|
298
|
-
...MapNameAndAliasesToStringArray<Rest>,
|
|
299
|
-
]
|
|
300
|
-
: [First["name"], ...(First["aliases"] extends string[] ? First["aliases"] : [])]
|
|
301
|
-
: [];
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* - Find duplicated items in an array and return it
|
|
305
|
-
* - Return `false` if not found
|
|
306
|
-
*/
|
|
307
|
-
type IsDuplicatesInArray<Input extends any[]> = Input extends [infer Item, ...infer Rest]
|
|
308
|
-
? Rest extends any[]
|
|
309
|
-
? Item extends Rest[number]
|
|
310
|
-
? Item
|
|
311
|
-
: IsDuplicatesInArray<Rest>
|
|
312
|
-
: false
|
|
313
|
-
: false;
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* - Check if there are duplicated options including aliases in `subcommand`
|
|
317
|
-
* - Return an error message if duplicated is found
|
|
318
|
-
* - Return `undefined` if not found
|
|
319
|
-
*/
|
|
320
|
-
export type CheckDuplicatedOptions<T extends { options?: Option[] }> = T["options"] extends infer O extends Option[]
|
|
321
|
-
? IsDuplicatesInArray<MapNameAndAliasesToStringArray<O>> extends infer Name extends string
|
|
322
|
-
? `>>> Error: Duplicated Options. Check the options with the name \`${Name}\` <<<`
|
|
323
|
-
: undefined
|
|
324
|
-
: undefined;
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* - Check for duplicated subcommands including aliases
|
|
328
|
-
* - Return an error message if duplicated is found
|
|
329
|
-
* - Return the `undefined` if no error
|
|
330
|
-
*/
|
|
331
|
-
type CheckDuplicatedSubcommands<T extends Partial<Subcommand>[]> =
|
|
332
|
-
IsDuplicatesInArray<MapNameAndAliasesToStringArray<T>> extends infer Name extends string
|
|
333
|
-
? `>>> Error: Duplicated Subcommand. Check the subcommands with the name \`${Name}\` <<<`
|
|
334
|
-
: undefined;
|
|
335
|
-
|
|
336
|
-
/**
|
|
337
|
-
* - Check for duplicated arguments
|
|
338
|
-
* - Return an error message if duplicated is found
|
|
339
|
-
* - Return the `undefined` if no error
|
|
340
|
-
*/
|
|
341
|
-
export type CheckDuplicatedArguments<T extends { arguments?: Argument[] }> = T["arguments"] extends infer A extends
|
|
342
|
-
Argument[]
|
|
343
|
-
? IsDuplicatesInArray<MapNameAndAliasesToStringArray<A>> extends infer Name extends string
|
|
344
|
-
? `>>> Error: Duplicated Arguments. Check the arguments with the name \`${Name}\` <<<`
|
|
345
|
-
: undefined
|
|
346
|
-
: undefined;
|
|
347
|
-
|
|
348
|
-
type OptionalUnion = Z3.ZodOptional<Z3.ZodAny> | Z4.$ZodOptional | Z3.ZodDefault<Z3.ZodAny> | Z4.$ZodDefault;
|
|
349
|
-
|
|
350
|
-
/**
|
|
351
|
-
* - Insures that only the last argument is optional
|
|
352
|
-
* - Insures no optional arguments are allowed when `allowPositional` is enabled
|
|
353
|
-
*/
|
|
354
|
-
export type CheckArgumentsOptional<T extends { allowPositional?: boolean; arguments?: readonly Argument[] }> =
|
|
355
|
-
T["arguments"] extends readonly [...infer Rest, infer Last]
|
|
356
|
-
? Last extends { type: OptionalUnion }
|
|
357
|
-
? T["allowPositional"] extends true
|
|
358
|
-
? `>>> Error: Cannot have optional arguments when \`allowPositional\` is enabled. The argument \`${Last extends { name: string } ? Last["name"] : ""}\` should not be optional <<<`
|
|
359
|
-
: T
|
|
360
|
-
: Extract<Rest[number], { type: OptionalUnion }> extends never
|
|
361
|
-
? T
|
|
362
|
-
: T["allowPositional"] extends true
|
|
363
|
-
? `>>> Error: Cannot have optional arguments when \`allowPositional\` is enabled. The argument \`${Rest[number] extends { name: string } ? Rest[number]["name"] : ""}\` should not be optional <<<`
|
|
364
|
-
: `>>> Error: Only the last argument may be optional. The argument \`${Rest[number] extends { name: string } ? Rest[number]["name"] : ""}\` should not be optional <<<`
|
|
365
|
-
: T;
|
package/src/zod-utilities.ts
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import { ZodBoolean, ZodDefault, ZodEffects } from "zod/v3";
|
|
2
|
-
import { safeParse } from "zod/v4/core";
|
|
3
|
-
|
|
4
|
-
import type * as Z3 from "zod/v3";
|
|
5
|
-
import type * as Z4 from "zod/v4/core";
|
|
6
|
-
import type { Schema, SchemaV3, SchemaV4 } from "./types.ts";
|
|
7
|
-
|
|
8
|
-
function isV4Schema(schema: Schema): schema is SchemaV4 {
|
|
9
|
-
return "_zod" in schema;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** - Safe parse a value against a schema */
|
|
13
|
-
export function safeParseSchema(schema: Schema, value: unknown) {
|
|
14
|
-
if (isV4Schema(schema)) {
|
|
15
|
-
return safeParse(schema, value);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return schema.safeParse(value);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** - Check if a schema is a boolean */
|
|
22
|
-
export function isBooleanSchema(schema: Schema): boolean {
|
|
23
|
-
if (isV4Schema(schema)) {
|
|
24
|
-
return isBooleanV4Schema(schema);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return isBooleanV3Schema(schema);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function isBooleanV4Schema(schema: SchemaV4): boolean {
|
|
31
|
-
let schemaDefinition = schema._zod.def;
|
|
32
|
-
|
|
33
|
-
while (schemaDefinition) {
|
|
34
|
-
if (schemaDefinition.type === "boolean") {
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (isV4SchemaDefinitionPipe(schemaDefinition)) {
|
|
39
|
-
return isBooleanV4Schema(schemaDefinition.out);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (!isV4SchemaDefinitionHasInnerType(schemaDefinition)) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
schemaDefinition = schemaDefinition.innerType._zod.def;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function isBooleanV3Schema(schema: SchemaV3): boolean {
|
|
53
|
-
let type = schema;
|
|
54
|
-
|
|
55
|
-
while (type) {
|
|
56
|
-
if (type instanceof ZodBoolean) {
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (type instanceof ZodEffects) {
|
|
61
|
-
return isBooleanV3Schema(type._def.schema as SchemaV3);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const definition = type._def as Z3.ZodTypeDef;
|
|
65
|
-
|
|
66
|
-
if ("innerType" in definition) {
|
|
67
|
-
type = definition.innerType as Z3.ZodTypeAny;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** - Get the default value of a schema */
|
|
77
|
-
export function schemaDefaultValue(schema: Schema): unknown {
|
|
78
|
-
if (isV4Schema(schema)) {
|
|
79
|
-
return schemaV4DefaultValue(schema);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return schemaV3DefaultValue(schema);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function schemaV4DefaultValue(schema: SchemaV4): unknown {
|
|
86
|
-
let schemaDefinition = schema._zod.def;
|
|
87
|
-
|
|
88
|
-
while (schemaDefinition) {
|
|
89
|
-
if (isSchemaDefinitionDefaultV4(schemaDefinition)) {
|
|
90
|
-
return schemaDefinition.defaultValue;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (isV4SchemaDefinitionPipe(schemaDefinition)) {
|
|
94
|
-
return schemaV4DefaultValue(schemaDefinition.out);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (!isV4SchemaDefinitionHasInnerType(schemaDefinition)) {
|
|
98
|
-
return undefined;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
schemaDefinition = schemaDefinition.innerType._zod.def;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return undefined;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function schemaV3DefaultValue(schema: SchemaV3): unknown {
|
|
108
|
-
let type = schema;
|
|
109
|
-
while (type) {
|
|
110
|
-
if (type instanceof ZodDefault) {
|
|
111
|
-
return type._def.defaultValue();
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (type instanceof ZodEffects) {
|
|
115
|
-
return schemaV3DefaultValue(type._def.schema as SchemaV3);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const definition = type._def as Z3.ZodTypeDef;
|
|
119
|
-
|
|
120
|
-
if ("innerType" in definition) {
|
|
121
|
-
type = definition.innerType as Z3.ZodTypeAny;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/** - Get the description of a schema */
|
|
131
|
-
export function schemaDescription(schema: Schema): string | undefined {
|
|
132
|
-
if (isV4Schema(schema)) {
|
|
133
|
-
if (!("meta" in schema) || typeof schema.meta !== "function") {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
138
|
-
const metaResult = schema.meta() as { description?: string } | undefined;
|
|
139
|
-
|
|
140
|
-
if (!metaResult || typeof metaResult !== "object" || !("description" in metaResult)) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return metaResult.description;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return schema.description;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/** - Check if a schema is optional */
|
|
151
|
-
export function isOptionalSchema(schema: Schema): schema is Z4.$ZodOptional {
|
|
152
|
-
if (isV4Schema(schema)) {
|
|
153
|
-
return schema._zod.def.type === "optional" || schema._zod.def.type === "default";
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return schema.isOptional();
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function isSchemaDefinitionDefaultV4(schemaDefinition: Z4.$ZodTypeDef): schemaDefinition is Z4.$ZodDefaultDef {
|
|
160
|
-
return schemaDefinition.type === "default";
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
type SchemaWithInnerType =
|
|
164
|
-
| Z4.$ZodDefaultDef
|
|
165
|
-
| Z4.$ZodPrefaultDef
|
|
166
|
-
| Z4.$ZodOptionalDef
|
|
167
|
-
| Z4.$ZodNonOptionalDef
|
|
168
|
-
| Z4.$ZodNullableDef
|
|
169
|
-
| Z4.$ZodSuccessDef
|
|
170
|
-
| Z4.$ZodCatchDef
|
|
171
|
-
| Z4.$ZodReadonlyDef
|
|
172
|
-
| Z4.$ZodPromiseDef;
|
|
173
|
-
|
|
174
|
-
function isV4SchemaDefinitionHasInnerType(schemaDefinition: Z4.$ZodTypeDef): schemaDefinition is SchemaWithInnerType {
|
|
175
|
-
return new Set([
|
|
176
|
-
"default",
|
|
177
|
-
"prefault",
|
|
178
|
-
"optional",
|
|
179
|
-
"nonoptional",
|
|
180
|
-
"nullable",
|
|
181
|
-
"success",
|
|
182
|
-
"catch",
|
|
183
|
-
"readonly",
|
|
184
|
-
"promise",
|
|
185
|
-
]).has(schemaDefinition.type);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
function isV4SchemaDefinitionPipe(schemaDefinition: Z4.$ZodTypeDef): schemaDefinition is Z4.$ZodPipeDef {
|
|
189
|
-
return schemaDefinition.type === "pipe";
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* A preprocessing function for Zod that converts a string to an array of strings.
|
|
194
|
-
*
|
|
195
|
-
* @param stringValue - The string value given by zod.
|
|
196
|
-
* @param separator - The separator to use when splitting the string. Defaults to ",".
|
|
197
|
-
*/
|
|
198
|
-
export function stringToArray(stringValue: string, separator: string = ","): string[] {
|
|
199
|
-
return stringValue
|
|
200
|
-
.split(separator)
|
|
201
|
-
.map(s => s.trim())
|
|
202
|
-
.filter(Boolean);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* A preprocessing function for Zod that converts a string to a `Set` of strings.
|
|
207
|
-
*
|
|
208
|
-
* @param stringValue - The string value given by zod.
|
|
209
|
-
* @param separator - The separator to use when splitting the string. Defaults to ",".
|
|
210
|
-
*/
|
|
211
|
-
export function stringToSet(stringValue: string, separator: string = ","): Set<string> {
|
|
212
|
-
const maybeArray = stringToArray(stringValue, separator);
|
|
213
|
-
return new Set(maybeArray);
|
|
214
|
-
}
|