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
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -16,25 +16,31 @@ A strictly typed command-line arguments parser powered by schema validation.
|
|
|
16
16
|
- [Creating a subcommand](#creating-a-subcommand)
|
|
17
17
|
- [Creating options](#creating-options)
|
|
18
18
|
- [Creating typed arguments](#creating-typed-arguments)
|
|
19
|
+
- [Sharing options and typed arguments](#sharing-options-and-typed-arguments)
|
|
19
20
|
- [Using Schemas](#using-schemas)
|
|
20
21
|
- [Default Values and Optional Inputs](#default-values-and-optional-inputs)
|
|
21
22
|
- [Positionals vs Typed Arguments](#positionals-vs-typed-arguments)
|
|
22
23
|
- [Option and Argument Constraints](#option-and-argument-constraints)
|
|
23
24
|
- [Negating a boolean option](#negating-a-boolean-option)
|
|
25
|
+
- [Structured Object Options](#structured-object-options)
|
|
26
|
+
- [Execute commands programmatically](#execute-commands-programmatically)
|
|
24
27
|
- [Creating a Custom Help Message Style](#creating-a-custom-help-message-style)
|
|
25
28
|
- [Help Message as HTML](#help-message-as-html)
|
|
29
|
+
- [Handling and Inspecting Errors](#handling-and-inspecting-errors)
|
|
30
|
+
- [Loading from a CDN](#loading-from-a-cdn)
|
|
26
31
|
- [API Reference](#api-reference)
|
|
27
|
-
- [Type Utilities](#type-utilities)
|
|
28
|
-
- [Coerce Helpers](#coerce-helpers)
|
|
29
|
-
- [Markdown Generation](#markdown-generation)
|
|
30
|
-
- [Autocompletion Script Generation](#autocompletion-script-generation)
|
|
31
|
-
- [Help Message](#help-message)
|
|
32
|
-
- [PrintHelpOptions](#printhelpoptions)
|
|
33
|
-
- [Cli](#cli)
|
|
34
|
-
- [Subcommand](#subcommand)
|
|
35
|
-
- [Option](#option)
|
|
36
|
-
- [Argument](#argument)
|
|
37
|
-
- [Context Type](#context-type)
|
|
32
|
+
- [Type Utilities](docs/api-reference.md#type-utilities)
|
|
33
|
+
- [Coerce Helpers](docs/api-reference.md#coerce-helpers)
|
|
34
|
+
- [Markdown Generation](docs/api-reference.md#markdown-generation)
|
|
35
|
+
- [Autocompletion Script Generation](docs/api-reference.md#autocompletion-script-generation)
|
|
36
|
+
- [Help Message](docs/api-reference.md#help-message)
|
|
37
|
+
- [PrintHelpOptions](docs/api-reference.md#printhelpoptions)
|
|
38
|
+
- [Cli](docs/api-reference.md#cli)
|
|
39
|
+
- [Subcommand](docs/api-reference.md#subcommand)
|
|
40
|
+
- [Option](docs/api-reference.md#option)
|
|
41
|
+
- [Argument](docs/api-reference.md#argument)
|
|
42
|
+
- [Context Type](docs/api-reference.md#context-type)
|
|
43
|
+
- [Error Types](docs/api-reference.md#error-types)
|
|
38
44
|
- [License](#license)
|
|
39
45
|
|
|
40
46
|
## Features
|
|
@@ -65,46 +71,24 @@ The following example uses `zod` as the validation library, but you can use any
|
|
|
65
71
|
import * as z from "zod";
|
|
66
72
|
import { defineCLI, coerce } from "zod-args-parser";
|
|
67
73
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
cliName: "listy",
|
|
71
|
-
|
|
72
|
-
subcommands: [
|
|
73
|
-
// ...
|
|
74
|
-
],
|
|
75
|
-
|
|
74
|
+
const cli = defineCLI({
|
|
75
|
+
cliName: "hello",
|
|
76
76
|
options: {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
/** `--name` or `-n` */
|
|
78
|
+
name: {
|
|
79
|
+
aliases: ["n"],
|
|
80
|
+
schema: z.string().default("world"),
|
|
80
81
|
},
|
|
81
82
|
},
|
|
82
|
-
|
|
83
|
-
arguments: {
|
|
84
|
-
// ...
|
|
85
|
-
},
|
|
86
83
|
});
|
|
87
84
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const { help } = results.options;
|
|
91
|
-
|
|
92
|
-
// print help for the CLI
|
|
93
|
-
if (help && listyCLI.generateCliHelpMessage) {
|
|
94
|
-
console.log(listyCLI.generateCliHelpMessage());
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
console.error("Please try `listy --help`");
|
|
85
|
+
cli.onExecute(({ options }) => {
|
|
86
|
+
console.log(`Hello, ${options.name}!`);
|
|
99
87
|
});
|
|
100
88
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
// Inspect parsed results
|
|
105
|
-
if (results.error) {
|
|
106
|
-
console.error(results.error.message);
|
|
107
|
-
console.log("\n`listy --help` for more information");
|
|
89
|
+
const result = cli.run(process.argv.slice(2));
|
|
90
|
+
if (result.error) {
|
|
91
|
+
console.error(result.error.message);
|
|
108
92
|
}
|
|
109
93
|
```
|
|
110
94
|
|
|
@@ -220,6 +204,7 @@ Option names can use any common case style:
|
|
|
220
204
|
- LIST_NAME `=>` --list-name
|
|
221
205
|
|
|
222
206
|
```ts
|
|
207
|
+
import * as z from "zod";
|
|
223
208
|
import { defineSubcommand, coerce } from "zod-args-parser";
|
|
224
209
|
|
|
225
210
|
const createListCommand = defineSubcommand({
|
|
@@ -329,6 +314,52 @@ const createListCommand = defineSubcommand({
|
|
|
329
314
|
});
|
|
330
315
|
```
|
|
331
316
|
|
|
317
|
+
### Sharing options and typed arguments
|
|
318
|
+
|
|
319
|
+
Options and typed arguments can be shared between subcommands/main CLI.
|
|
320
|
+
|
|
321
|
+
```ts
|
|
322
|
+
// shared.ts
|
|
323
|
+
import * as z from "zod";
|
|
324
|
+
import { defineArguments, defineOptions, coerce } from "zod-args-parser";
|
|
325
|
+
|
|
326
|
+
export const sharedOptions = defineOptions({
|
|
327
|
+
verbose: {
|
|
328
|
+
schema: z.boolean().optional(),
|
|
329
|
+
coerce: coerce.boolean,
|
|
330
|
+
meta: {
|
|
331
|
+
description: "Enable verbose mode.",
|
|
332
|
+
},
|
|
333
|
+
},
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
export const sharedArguments = defineArguments({
|
|
337
|
+
// ...
|
|
338
|
+
});
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
```ts
|
|
342
|
+
// add-command.ts
|
|
343
|
+
import * as z from "zod";
|
|
344
|
+
import { defineSubcommand, coerce } from "zod-args-parser";
|
|
345
|
+
|
|
346
|
+
import { sharedOptions, sharedArguments } from "./shared.ts";
|
|
347
|
+
|
|
348
|
+
export const addCommand = defineSubcommand({
|
|
349
|
+
//...
|
|
350
|
+
|
|
351
|
+
options: {
|
|
352
|
+
// ...
|
|
353
|
+
...sharedOptions,
|
|
354
|
+
},
|
|
355
|
+
|
|
356
|
+
arguments: {
|
|
357
|
+
// ...
|
|
358
|
+
...sharedArguments,
|
|
359
|
+
},
|
|
360
|
+
});
|
|
361
|
+
```
|
|
362
|
+
|
|
332
363
|
### Using schemas
|
|
333
364
|
|
|
334
365
|
Other validation libraries can be used as long as they support [`StandardSchemaV1`](https://github.com/standard-schema/standard-schema) and allow primitive types to be optional or have default values.
|
|
@@ -392,17 +423,130 @@ Both options and typed arguments support rules to control valid combinations:
|
|
|
392
423
|
|
|
393
424
|
### Negating a boolean option
|
|
394
425
|
|
|
395
|
-
Boolean
|
|
426
|
+
Boolean flags are `true` when they appear on the command line.
|
|
427
|
+
Prefixing a flag with `--no-` inverts its final value.
|
|
428
|
+
|
|
429
|
+
When a value is explicitly assigned (`=true` or `=false`), the assignment is applied first, then the `--no-` prefix flips the result.
|
|
430
|
+
|
|
431
|
+
Examples:
|
|
432
|
+
|
|
433
|
+
```sh
|
|
434
|
+
--bool true
|
|
435
|
+
--no-bool false
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
```sh
|
|
439
|
+
--bool=true true
|
|
440
|
+
--bool=false false
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
```sh
|
|
444
|
+
--no-bool=true false # assigned true → inverted
|
|
445
|
+
--no-bool=false true # assigned false → inverted
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
Short-form flags follow the same logic, but do **not** accept `=value` syntax:
|
|
449
|
+
|
|
450
|
+
```sh
|
|
451
|
+
-v true
|
|
452
|
+
--no-v false
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
```sh
|
|
456
|
+
-v=true ERROR
|
|
457
|
+
-v=false ERROR
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
```sh
|
|
461
|
+
--no-v=true false
|
|
462
|
+
--no-v=false true
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
### Structured Object Options
|
|
466
|
+
|
|
467
|
+
Options using `coerce.object` receive **stringified JSON** and are parsed with `JSON.parse`.
|
|
468
|
+
They also support **dotted flags** to assign nested fields without writing full JSON.
|
|
469
|
+
|
|
470
|
+
See [Coerce Helpers](./docs/api-reference.md#coerce-helpers).
|
|
471
|
+
|
|
472
|
+
```ts
|
|
473
|
+
import * as z from "zod";
|
|
474
|
+
import { defineCLI, coerce } from "zod-args-parser";
|
|
475
|
+
|
|
476
|
+
const cli = defineCLI({
|
|
477
|
+
cliName: "listy",
|
|
478
|
+
options: {
|
|
479
|
+
db: {
|
|
480
|
+
schema: z
|
|
481
|
+
.object({
|
|
482
|
+
host: z.string().default("localhost"),
|
|
483
|
+
port: z.number().default(5432),
|
|
484
|
+
https: z.boolean().default(false),
|
|
485
|
+
credentials: z.object({
|
|
486
|
+
user: z.string(),
|
|
487
|
+
pass: z.string(),
|
|
488
|
+
}),
|
|
489
|
+
})
|
|
490
|
+
.optional(),
|
|
491
|
+
|
|
492
|
+
// Accepts either a full JSON string or individual "dotted" flags,
|
|
493
|
+
// parsed with JSON.parse.
|
|
494
|
+
coerce: coerce.object({ coerceBoolean: true, coerceNumber: ["port"] }),
|
|
495
|
+
|
|
496
|
+
meta: {
|
|
497
|
+
placeholder: "<.host,.port,.credentials.user,.credentials.pass>",
|
|
498
|
+
description: "Database configuration object. Parsed as JSON; supports dotted flags.",
|
|
499
|
+
example: "--db.host=prod-db --db.credentials.user=alice --db.credentials.pass=secret",
|
|
500
|
+
},
|
|
501
|
+
},
|
|
502
|
+
},
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
cli.onExecute(({ options }) => {
|
|
506
|
+
console.log(options.db);
|
|
507
|
+
});
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
#### Usage Examples
|
|
396
511
|
|
|
397
512
|
```sh
|
|
398
|
-
|
|
399
|
-
--
|
|
513
|
+
# Dotted flags for nested values using `=`
|
|
514
|
+
listy --db.https=true --db.host=db.local --db.port=3306 --db.credentials.user=root --db.credentials.pass=toor
|
|
515
|
+
|
|
516
|
+
# Dotted flags for nested values without `=`
|
|
517
|
+
listy --db.https true --db.host db.local --db.port 3306 --db.credentials.user root --db.credentials.pass toor
|
|
518
|
+
|
|
519
|
+
# Full JSON input (stringified)
|
|
520
|
+
listy --db '{"host":"db.local","https":true,"credentials":{"user":"root","pass":"toor"}}'
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
### Execute commands programmatically
|
|
524
|
+
|
|
525
|
+
You can execute the main CLI or a specific subcommand directly from code.
|
|
526
|
+
The input is provided as an object (`{ options, arguments, positionals }`) and is validated using the defined schemas.
|
|
527
|
+
Invalid input throws an error. Use `.executeAsync()` if your `onExecute` handler is asynchronous.
|
|
528
|
+
|
|
529
|
+
> [!NOTE]
|
|
530
|
+
> `run()` is like calling the CLI from the terminal.
|
|
531
|
+
> `execute()` is like calling a function directly.
|
|
400
532
|
|
|
401
|
-
|
|
402
|
-
|
|
533
|
+
```ts
|
|
534
|
+
import { InferOptionsInputType } from "zod-args-parser";
|
|
535
|
+
|
|
536
|
+
import { listyCLI } from "./cli.ts";
|
|
537
|
+
|
|
538
|
+
// In this example, Listy only defines options — no typed arguments or positionals.
|
|
539
|
+
// To keep the function simple, we accept only the options as input.
|
|
540
|
+
|
|
541
|
+
/** @throws {CliError} */
|
|
542
|
+
export function executeListy(options: InferOptionsInputType<typeof listyCLI>) {
|
|
543
|
+
listyCLI.execute({ options });
|
|
544
|
+
}
|
|
403
545
|
|
|
404
|
-
|
|
405
|
-
|
|
546
|
+
/** @throws {CliError} */
|
|
547
|
+
export async function executeListyAsync(options: InferOptionsInputType<typeof listyCLI>) {
|
|
548
|
+
await listyCLI.executeAsync({ options });
|
|
549
|
+
}
|
|
406
550
|
```
|
|
407
551
|
|
|
408
552
|
### Creating a Custom Help Message Style
|
|
@@ -452,257 +596,75 @@ span._markdown * {
|
|
|
452
596
|
}
|
|
453
597
|
```
|
|
454
598
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
### Type Utilities
|
|
458
|
-
|
|
459
|
-
#### `InferInputType<T extends Cli | Subcommand>`
|
|
599
|
+
### Handling and Inspecting Errors
|
|
460
600
|
|
|
461
|
-
|
|
601
|
+
The library processes input in four stages. Errors can occur at any step:
|
|
462
602
|
|
|
463
|
-
|
|
603
|
+
1. **Definition Validation** — Ensures the CLI and subcommand definitions are valid.
|
|
604
|
+
2. **Argument Parsing** — Reads terminal input and builds the initial parse result.
|
|
605
|
+
3. **Context Validation** — Applies schema validation and dependency rules.
|
|
606
|
+
4. **Execution** — Runs the command or subcommand once all checks succeed.
|
|
464
607
|
|
|
465
|
-
|
|
608
|
+
After running your CLI, the returned result may contain an error. You can narrow down the error by its **cause** or **code** to handle it specifically.
|
|
466
609
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
Infer options input type from the CLI/subcommand definition.
|
|
470
|
-
|
|
471
|
-
#### `InferOptionsOutputType<T extends Cli | Subcommand>`
|
|
472
|
-
|
|
473
|
-
Infer options output type from the CLI/subcommand definition.
|
|
474
|
-
|
|
475
|
-
#### `InferArgumentsInputType<T extends Cli | Subcommand>`
|
|
476
|
-
|
|
477
|
-
Infer arguments input type from the CLI/subcommand definition.
|
|
478
|
-
|
|
479
|
-
#### `InferArgumentsOutputType<T extends Cli | Subcommand>`
|
|
480
|
-
|
|
481
|
-
Infer arguments output type from the CLI/subcommand definition.
|
|
610
|
+
See [Error Reference](./docs/api-reference.md#error-types)
|
|
482
611
|
|
|
483
612
|
```ts
|
|
484
|
-
import
|
|
485
|
-
|
|
486
|
-
const subcommand = defineSubcommand({
|
|
487
|
-
// ...
|
|
488
|
-
});
|
|
489
|
-
|
|
490
|
-
type InputType = InferInputType<typeof subcommand>;
|
|
491
|
-
type OutputType = InferOutputType<typeof subcommand>;
|
|
492
|
-
```
|
|
493
|
-
|
|
494
|
-
### Coerce Helpers
|
|
495
|
-
|
|
496
|
-
- `coerce.string`
|
|
497
|
-
- `coerce.number`
|
|
498
|
-
- `coerce.boolean`
|
|
499
|
-
- `coerce.stringArray(separator: string)`
|
|
500
|
-
- `coerce.numberArray(separator: string)`
|
|
501
|
-
- `coerce.booleanArray(separator: string)`
|
|
502
|
-
- `coerce.stringSet(separator: string)`
|
|
503
|
-
- `coerce.numberSet(separator: string)`
|
|
504
|
-
- `coerce.booleanSet(separator: string)`
|
|
505
|
-
- `coerce.json<T>()`
|
|
506
|
-
|
|
507
|
-
### Markdown Generation
|
|
508
|
-
|
|
509
|
-
#### generateMarkdown
|
|
510
|
-
|
|
511
|
-
`(cliDefinition: Cli) => string`
|
|
512
|
-
|
|
513
|
-
Generate markdown documentation for a **CLI definition** and return it as a `string`.
|
|
514
|
-
|
|
515
|
-
### Autocomplete Script Generation
|
|
516
|
-
|
|
517
|
-
#### generateBashAutocompleteScript
|
|
518
|
-
|
|
519
|
-
`(cliDefinition: Cli) => string`
|
|
520
|
-
|
|
521
|
-
Generate a Bash autocomplete script for a **CLI definition** and return it as a `string`.
|
|
522
|
-
|
|
523
|
-
#### generateZshAutocompleteScript
|
|
524
|
-
|
|
525
|
-
`(cliDefinition: Cli) => string`
|
|
526
|
-
|
|
527
|
-
Generate a zsh autocomplete script for a **CLI definition** and return it as a `string`.
|
|
528
|
-
|
|
529
|
-
#### generatePowerShellAutocompleteScript
|
|
530
|
-
|
|
531
|
-
`(cliDefinition: Cli) => string`
|
|
613
|
+
import { ErrorCause, ValidationErrorCode } from "zod-args-parser";
|
|
532
614
|
|
|
533
|
-
|
|
615
|
+
const results = listyCLI.run(input);
|
|
534
616
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
Generate a help message for a **CLI definition** and return it as a `string`.
|
|
542
|
-
See [`PrintHelpOptions`](#printhelpoptions) and [`Cli`](#cli).
|
|
543
|
-
|
|
544
|
-
#### generateSubcommandHelpMessage
|
|
545
|
-
|
|
546
|
-
`(commandDefinition: Subcommand, options?: PrintHelpOptions, cliName?: string) => string`
|
|
547
|
-
|
|
548
|
-
Generate a help message for a **subcommand definition** and return it as a `string`.
|
|
549
|
-
See [`PrintHelpOptions`](#printhelpoptions) and [`Subcommand`](#subcommand).
|
|
550
|
-
|
|
551
|
-
#### printCliHelp
|
|
552
|
-
|
|
553
|
-
`(cliDefinition: Cli, options?: PrintHelpOptions) => void`
|
|
554
|
-
|
|
555
|
-
Print a help message for a **CLI definition**.
|
|
556
|
-
See [`PrintHelpOptions`](#printhelpoptions) and [`Cli`](#cli).
|
|
617
|
+
if (results.error) {
|
|
618
|
+
// Check the type of error by its cause
|
|
619
|
+
if (results.error.cause === ErrorCause.Parse) {
|
|
620
|
+
// Handle parsing-related errors
|
|
621
|
+
}
|
|
557
622
|
|
|
558
|
-
|
|
623
|
+
// Check for a specific error code
|
|
624
|
+
if (results.error.code === ValidationErrorCode.SchemaValidationFailed) {
|
|
625
|
+
const { commandKind, commandName, kind, name, inputValue, issues } = results.error.context;
|
|
559
626
|
|
|
560
|
-
|
|
627
|
+
console.error(
|
|
628
|
+
"validation error:",
|
|
629
|
+
`the ${kind} "${name}"`,
|
|
630
|
+
`for ${commandKind} "${commandName}" failed to validate the input:`,
|
|
631
|
+
inputValue,
|
|
632
|
+
);
|
|
561
633
|
|
|
562
|
-
|
|
563
|
-
|
|
634
|
+
// Detailed validation issues
|
|
635
|
+
console.log(issues);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
```
|
|
564
639
|
|
|
565
|
-
###
|
|
640
|
+
### Loading from a CDN
|
|
566
641
|
|
|
567
|
-
|
|
568
|
-
| ----------------------- | ---------------------- | --------------------------- | ----------------------------------------------------------------------------------- |
|
|
569
|
-
| style | `HelpMessageStyle` | `helpMessageStyles.default` | The style to use for the help message. |
|
|
570
|
-
| kebabCaseArgumentName | `boolean` | `true` | Whether to transform the argument (not option) name to kebab case. |
|
|
571
|
-
| markdownRenderer | `"terminal" \| "html"` | `"terminal"` | The renderer to use for the markdown. |
|
|
572
|
-
| indentBeforeName | `number` | `2` | The number of spaces before the name of option/argument/subcommand. |
|
|
573
|
-
| indentAfterName | `number` | `4` | Spaces after the name, between the name and description (space between columns). |
|
|
574
|
-
| indentBeforePlaceholder | `number` | `1` | The number of spaces to put before the placeholder. |
|
|
575
|
-
| newLineIndent | `number` | `0` | Spaces before a new line for description or example under description. |
|
|
576
|
-
| emptyLines | `number` | `0` | Number of empty lines between lines. |
|
|
577
|
-
| emptyLinesBeforeTitle | `number` | `1` | Number of empty lines before the title. |
|
|
578
|
-
| emptyLinesAfterTitle | `number` | `0` | Number of empty lines after the title. |
|
|
579
|
-
| exampleKeyword | `string` | `"Example:"` | The keyword to use for examples. |
|
|
580
|
-
| optionalKeyword | `string` | `"(optional)"` | The keyword to use for optional values. |
|
|
581
|
-
| defaultKeyword | `string` | `"(default: {{ value }})"` | The keyword to indicate default values, with `{{ value }}` replaced by the default. |
|
|
582
|
-
| usageTitle | `string` | `"USAGE"` | The title to use for the usage section. |
|
|
583
|
-
| descriptionTitle | `string` | `"DESCRIPTION"` | The title to use for the description section. |
|
|
584
|
-
| commandsTitle | `string` | `"COMMANDS"` | The title to use for the commands section. |
|
|
585
|
-
| optionsTitle | `string` | `"OPTIONS"` | The title to use for the options section. |
|
|
586
|
-
| argumentsTitle | `string` | `"ARGUMENTS"` | The title to use for the arguments section. |
|
|
587
|
-
| exampleTitle | `string` | `"EXAMPLE"` | The title to use for the examples section. |
|
|
642
|
+
**Global IIFE**
|
|
588
643
|
|
|
589
|
-
|
|
644
|
+
```html
|
|
645
|
+
<!-- using jsdelivr -->
|
|
646
|
+
<script src="https://cdn.jsdelivr.net/npm/zod-args-parser"></script>
|
|
590
647
|
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
| `cliName` | `string` | The name of the CLI program (main command). |
|
|
594
|
-
| `subcommands?` | `Subcommand[]` | Array of subcommands. Do not manually construct subcommand objects; always create them via `defineSubcommand()` and pass the returned object. See [`Subcommand Definition`](#subcommand-definition). |
|
|
595
|
-
| `allowPositionals?` | `boolean` | When `true`, enables positional arguments for the CLI; positionals are untyped `string[]`. If typed `arguments` are present, they are parsed first and any remaining args become `positionals`. |
|
|
596
|
-
| `options?` | `Record<string, Option>` | A dictionary of option definitions keyed by a valid JavaScript variable name (e.g., `inputDir` → `--input-dir`). See [`Option Definition`](#option-definition). |
|
|
597
|
-
| `arguments?` | `Record<string, Argument>` | Strictly ordered typed arguments. See [`Argument Definition`](#argument-definition). |
|
|
598
|
-
| `meta?` | `CliMeta` | Metadata for the CLI used for help messages and documentation generation. |
|
|
648
|
+
<!-- using unpkg -->
|
|
649
|
+
<script src="https://unpkg.com/zod-args-parser"></script>
|
|
599
650
|
|
|
600
|
-
|
|
651
|
+
<script>
|
|
652
|
+
// Access the library as a global
|
|
653
|
+
const { defineCLI, coerce } = ZodArgsParser;
|
|
654
|
+
</script>
|
|
655
|
+
```
|
|
601
656
|
|
|
602
|
-
|
|
603
|
-
| ---------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------- |
|
|
604
|
-
| `usage?` | `string` | Usage string example (e.g., `cliName subcommand [options] <arg1> <arg2>`). |
|
|
605
|
-
| `description?` | `string` | Short explanation. Supports multi-line text and ANSI colors. Preferred for terminal output when present. |
|
|
606
|
-
| `descriptionMarkdown?` | `string` | Markdown-formatted description used for generated documentation and terminal markdown. Used for Markdown generation if present. |
|
|
607
|
-
| `example?` | `string` | Examples shown to the user (displayed as a code block in Markdown). |
|
|
657
|
+
**ESM Module**
|
|
608
658
|
|
|
609
|
-
|
|
659
|
+
```html
|
|
660
|
+
<script type="module">
|
|
661
|
+
import { defineCLI, coerce } from "https://cdn.jsdelivr.net/npm/zod-args-parser/+esm";
|
|
662
|
+
</script>
|
|
663
|
+
```
|
|
610
664
|
|
|
611
|
-
|
|
612
|
-
| ------------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
613
|
-
| `name` | `string` | The subcommand name. Must be unique within a CLI across names and aliases. |
|
|
614
|
-
| `aliases?` | `string[]` | A list of aliases that can be used to invoke this subcommand. Must not collide with other names or aliases in the same CLI. |
|
|
615
|
-
| `allowPositionals?` | `boolean` | When `true`, enables positional arguments for this subcommand. Positionals are untyped `string[]`. If typed `arguments` are present, they are parsed first and any remaining args become `positionals`. |
|
|
616
|
-
| `options?` | `Record<string, Option>` | A dictionary of option definitions keyed by a valid JavaScript variable name (e.g., `inputDir` → `--input-dir`). See [`Option Definition`](#option-definition). |
|
|
617
|
-
| `arguments?` | `Record<string, Argument>` | Strictly ordered, typed arguments (the order matters). [`Argument Definition`](#argument-definition). |
|
|
618
|
-
| `meta?` | `SubcommandMeta` | Metadata used for help messages and documentation generation. Inlined in the table below. |
|
|
665
|
+
## API Reference
|
|
619
666
|
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
| Property | Type | Description |
|
|
623
|
-
| ---------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
624
|
-
| `placeholder?` | `string` | Text displayed after the subcommand name to show expected arguments (e.g., `<list> <items>`). |
|
|
625
|
-
| `usage?` | `string` | Usage string example (e.g. `cliName subcommand [options] <arg1> <arg2>`). |
|
|
626
|
-
| `description?` | `string` | Short explanation. Supports multi-line text and ANSI color styles. Preferred for terminal output if both `description` and `descriptionMarkdown` are provided. |
|
|
627
|
-
| `descriptionMarkdown?` | `string` | Markdown-formatted description used for generated documentation and terminal markdown. If both `description` and `descriptionMarkdown` are provided, `descriptionMarkdown` is used for Markdown generation. |
|
|
628
|
-
| `example?` | `string` | Examples shown to the user (displayed inside a code block in markdown). |
|
|
629
|
-
| `hidden?` | `boolean` | When `true`, hide this item from documentation/help output. Useful for internal or undocumented commands/options. |
|
|
630
|
-
|
|
631
|
-
### Option
|
|
632
|
-
|
|
633
|
-
| Property | Type | Description |
|
|
634
|
-
| --------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
|
|
635
|
-
| `aliases?` | `string[]` | A list of short alias keys (JavaScript variable names) that map to short CLI flags (e.g., `i` → `-i`). |
|
|
636
|
-
| `schema` | `Schema` | A schema to validate the user input. (e.g., Zod: `z.string().optional()`). |
|
|
637
|
-
| `coerce?` | `CoerceMethod<...>` | Coercion function used to convert `string` input to the schema's output type. Not required when the expected input type is `string`. |
|
|
638
|
-
| `exclusive?` | `boolean` | When `true`, this option must appear on its own (except for entries listed in `requires`). |
|
|
639
|
-
| `requires?` | `string[]` | Names of other options/arguments that must be explicitly provided when this option is used. |
|
|
640
|
-
| `conflictWith?` | `string[]` | Names of other options/arguments that conflict with this option. |
|
|
641
|
-
| `meta?` | `OptionMeta` | Metadata used for help messages and documentation generation. Inlined in the table below. |
|
|
642
|
-
|
|
643
|
-
### OptionMeta
|
|
644
|
-
|
|
645
|
-
| Property | Type | Description |
|
|
646
|
-
| -------------- | --------- | ---------------------------------------------------------------------------------------------- |
|
|
647
|
-
| `placeholder?` | `string` | Text to display as a placeholder for the expected value (e.g., `<path>`). |
|
|
648
|
-
| `default?` | `string` | Custom default value shown in docs/help. Use an empty string to intentionally show no default. |
|
|
649
|
-
| `optional?` | `boolean` | Override whether this option is considered optional in the generated help documentation. |
|
|
650
|
-
|
|
651
|
-
### Argument
|
|
652
|
-
|
|
653
|
-
| Property | Type | Description |
|
|
654
|
-
| --------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
|
|
655
|
-
| `schema` | `Schema` | Schema to validate the user input. |
|
|
656
|
-
| `coerce?` | `CoerceMethod<...>` | Coercion function used to convert `string` input to the schema's output type. Not required when the expected input type is `string`. |
|
|
657
|
-
| `exclusive?` | `boolean` | When `true`, this argument must appear on its own (except for items listed in `requires`). |
|
|
658
|
-
| `requires?` | `string[]` | Names of other options/arguments that must be explicitly provided when this argument is used. |
|
|
659
|
-
| `conflictWith?` | `string[]` | Names of other options/arguments that conflict with this argument. |
|
|
660
|
-
| `meta?` | `ArgumentMeta` | Metadata used for help messages and documentation generation. Inlined in the table below. |
|
|
661
|
-
|
|
662
|
-
### ArgumentMeta
|
|
663
|
-
|
|
664
|
-
| Property | Type | Description |
|
|
665
|
-
| ----------- | --------- | ---------------------------------------------------------------------------------------------- |
|
|
666
|
-
| `name?` | `string` | Override the argument name in the help message and documentation. |
|
|
667
|
-
| `default?` | `string` | Custom default value shown in help/docs. Use an empty string to intentionally show no default. |
|
|
668
|
-
| `optional?` | `boolean` | Override whether this argument is considered optional in the generated help documentation. |
|
|
669
|
-
|
|
670
|
-
### Context Type
|
|
671
|
-
|
|
672
|
-
Represents detailed information about how each option or argument was provided (terminal, default, or programmatic).
|
|
673
|
-
Useful for inspecting where values came from and what raw input was used.
|
|
674
|
-
|
|
675
|
-
#### Context
|
|
676
|
-
|
|
677
|
-
| Field | Type | Description |
|
|
678
|
-
| ------------- | --------------------------------- | ------------------------------------------------- |
|
|
679
|
-
| `subcommand` | `string` \| `undefined` | Name of the executed subcommand, if any. |
|
|
680
|
-
| `options` | `Record<string, OptionContext>` | Per-option context, with source and raw values. |
|
|
681
|
-
| `arguments` | `Record<string, ArgumentContext>` | Per-argument context, with source and raw values. |
|
|
682
|
-
| `positionals` | `string[]` \| `never` | Raw positional arguments when allowed. |
|
|
683
|
-
|
|
684
|
-
#### OptionContext
|
|
685
|
-
|
|
686
|
-
| Property | Description |
|
|
687
|
-
| -------------- | ------------------------------------------------------------------------------------ |
|
|
688
|
-
| `schema` | Schema used to validate the option. |
|
|
689
|
-
| `optional` | Whether the option schema is optional. |
|
|
690
|
-
| `defaultValue` | Default value from the schema, if any. |
|
|
691
|
-
| `flag` | CLI flag used (e.g., `--foo`, `-f`) when source is `terminal`. |
|
|
692
|
-
| `stringValue` | Raw string provided from CLI when source is `terminal`. |
|
|
693
|
-
| `passedValue` | Value passed programmatically when source is `programmatic`. |
|
|
694
|
-
| `source` | `"terminal"`, `"default"`, or `"programmatic"` indicates how the value was supplied. |
|
|
695
|
-
|
|
696
|
-
#### ArgumentContext
|
|
697
|
-
|
|
698
|
-
| Property | Description |
|
|
699
|
-
| -------------- | ------------------------------------------------------------------------------------ |
|
|
700
|
-
| `schema` | Schema used to validate the argument. |
|
|
701
|
-
| `optional` | Whether the argument schema is optional. |
|
|
702
|
-
| `defaultValue` | Default value from the schema, if any. |
|
|
703
|
-
| `stringValue` | Raw string from CLI when source is `terminal`. |
|
|
704
|
-
| `passedValue` | Value passed programmatically when source is `programmatic`. |
|
|
705
|
-
| `source` | `"terminal"`, `"default"`, or `"programmatic"` indicates how the value was supplied. |
|
|
667
|
+
See the [API Reference](./docs/api-reference.md) for more information.
|
|
706
668
|
|
|
707
669
|
## License
|
|
708
670
|
|