zod-args-parser 2.0.0-beta.0 → 2.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -0
- package/README.md +230 -289
- package/lib/esm/autocomplete-scripts/bash-autocomplete-script.js +74 -2
- package/lib/esm/autocomplete-scripts/bash-autocomplete-script.js.map +7 -1
- package/lib/esm/autocomplete-scripts/powershell-autocomplete-script.js +90 -2
- package/lib/esm/autocomplete-scripts/powershell-autocomplete-script.js.map +7 -1
- package/lib/esm/autocomplete-scripts/zsh-autocomplete-script.js +39 -13
- package/lib/esm/autocomplete-scripts/zsh-autocomplete-script.js.map +7 -1
- package/lib/esm/cli-error/cli-error.js +38 -0
- package/lib/esm/cli-error/cli-error.js.map +7 -0
- package/lib/esm/cli-error/error-cause.js +12 -0
- package/lib/esm/cli-error/error-cause.js.map +7 -0
- package/lib/esm/cli-error/error-code/definition-error-code.js +23 -0
- package/lib/esm/cli-error/error-code/definition-error-code.js.map +7 -0
- package/lib/esm/cli-error/error-code/internal-error-code.js +10 -0
- package/lib/esm/cli-error/error-code/internal-error-code.js.map +7 -0
- package/lib/esm/cli-error/error-code/parse-error-code.js +18 -0
- package/lib/esm/cli-error/error-code/parse-error-code.js.map +7 -0
- package/lib/esm/cli-error/error-code/validation-error-code.js +17 -0
- package/lib/esm/cli-error/error-code/validation-error-code.js.map +7 -0
- package/lib/esm/cli-error/error-message/definition-error-message.js +70 -0
- package/lib/esm/cli-error/error-message/definition-error-message.js.map +7 -0
- package/lib/esm/cli-error/error-message/internal-error-message.js +16 -0
- package/lib/esm/cli-error/error-message/internal-error-message.js.map +7 -0
- package/lib/esm/cli-error/error-message/parse-error-message.js +40 -0
- package/lib/esm/cli-error/error-message/parse-error-message.js.map +7 -0
- package/lib/esm/cli-error/error-message/validation-error-message.js +60 -0
- package/lib/esm/cli-error/error-message/validation-error-message.js.map +7 -0
- package/lib/esm/coerce/coerce-methods.js +197 -2
- package/lib/esm/coerce/coerce-methods.js.map +7 -1
- package/lib/esm/coerce/string-to-array.js +17 -2
- package/lib/esm/coerce/string-to-array.js.map +7 -1
- package/lib/esm/coerce/string-to-primitive.js +73 -2
- package/lib/esm/coerce/string-to-primitive.js.map +7 -1
- package/lib/esm/coerce/string-to-set.js +17 -2
- package/lib/esm/coerce/string-to-set.js.map +7 -1
- package/lib/esm/definitions/define-arguments.js +10 -2
- package/lib/esm/definitions/define-arguments.js.map +7 -1
- package/lib/esm/definitions/define-cli.js +89 -2
- package/lib/esm/definitions/define-cli.js.map +7 -1
- package/lib/esm/definitions/define-options.js +10 -2
- package/lib/esm/definitions/define-options.js.map +7 -1
- package/lib/esm/definitions/define-subcommand.js +56 -2
- package/lib/esm/definitions/define-subcommand.js.map +7 -1
- package/lib/esm/definitions/validate-cli-definition.js +360 -2
- package/lib/esm/definitions/validate-cli-definition.js.map +7 -1
- package/lib/esm/help-message/format-arguments.js +48 -2
- package/lib/esm/help-message/format-arguments.js.map +7 -1
- package/lib/esm/help-message/format-options.js +50 -2
- package/lib/esm/help-message/format-options.js.map +7 -1
- package/lib/esm/help-message/format-subcommands.js +37 -2
- package/lib/esm/help-message/format-subcommands.js.map +7 -1
- package/lib/esm/help-message/generate-for-cli.js +71 -2
- package/lib/esm/help-message/generate-for-cli.js.map +7 -1
- package/lib/esm/help-message/generate-for-subcommand.js +23 -2
- package/lib/esm/help-message/generate-for-subcommand.js.map +7 -1
- package/lib/esm/help-message/print-help.js +14 -2
- package/lib/esm/help-message/print-help.js.map +7 -1
- package/lib/esm/help-message/set-defaults.js +29 -2
- package/lib/esm/help-message/set-defaults.js.map +7 -1
- package/lib/esm/help-message/styles.js +154 -2
- package/lib/esm/help-message/styles.js.map +7 -1
- package/lib/esm/help-message/terminal-markdown.js +121 -2
- package/lib/esm/help-message/terminal-markdown.js.map +7 -1
- package/lib/esm/index.js +52 -2
- package/lib/esm/index.js.map +7 -1
- package/lib/esm/markdown/generate-markdown.js +153 -2
- package/lib/esm/markdown/generate-markdown.js.map +7 -1
- package/lib/esm/metadata/arguments-metadata.js +26 -2
- package/lib/esm/metadata/arguments-metadata.js.map +7 -1
- package/lib/esm/metadata/cli-metadata.js +24 -2
- package/lib/esm/metadata/cli-metadata.js.map +7 -1
- package/lib/esm/metadata/options-metadata.js +35 -2
- package/lib/esm/metadata/options-metadata.js.map +7 -1
- package/lib/esm/metadata/subcommands-metadata.js +32 -2
- package/lib/esm/metadata/subcommands-metadata.js.map +7 -1
- package/lib/esm/parse/context/cli-context-builder.js +283 -2
- package/lib/esm/parse/context/cli-context-builder.js.map +7 -1
- package/lib/esm/parse/context/object-context-builder.js +62 -2
- package/lib/esm/parse/context/object-context-builder.js.map +7 -1
- package/lib/esm/parse/parser-utilities.js +108 -2
- package/lib/esm/parse/parser-utilities.js.map +7 -1
- package/lib/esm/parse/safe-parse.js +57 -2
- package/lib/esm/parse/safe-parse.js.map +7 -1
- package/lib/esm/parse/validation/validate-context.js +17 -2
- package/lib/esm/parse/validation/validate-context.js.map +7 -1
- package/lib/esm/parse/validation/validators/arguments.js +67 -2
- package/lib/esm/parse/validation/validators/arguments.js.map +7 -1
- package/lib/esm/parse/validation/validators/conflict.js +38 -2
- package/lib/esm/parse/validation/validators/conflict.js.map +7 -1
- package/lib/esm/parse/validation/validators/exclusive.js +39 -2
- package/lib/esm/parse/validation/validators/exclusive.js.map +7 -1
- package/lib/esm/parse/validation/validators/explicitly-passed.js +18 -2
- package/lib/esm/parse/validation/validators/explicitly-passed.js.map +7 -1
- package/lib/esm/parse/validation/validators/options.js +67 -2
- package/lib/esm/parse/validation/validators/options.js.map +7 -1
- package/lib/esm/parse/validation/validators/requires.js +43 -2
- package/lib/esm/parse/validation/validators/requires.js.map +7 -1
- package/lib/esm/utilities/parse-argv.js +61 -0
- package/lib/esm/utilities/parse-argv.js.map +7 -0
- package/lib/esm/utilities/schema-utilities.js +57 -0
- package/lib/esm/utilities/schema-utilities.js.map +7 -0
- package/lib/esm/utilities/utilities.js +122 -0
- package/lib/esm/utilities/utilities.js.map +7 -0
- package/lib/iife/index.js +1 -1
- package/lib/iife/index.js.map +1 -1
- package/lib/mjs/autocomplete-scripts/bash-autocomplete-script.mjs +74 -2
- package/lib/mjs/autocomplete-scripts/bash-autocomplete-script.mjs.map +7 -1
- package/lib/mjs/autocomplete-scripts/powershell-autocomplete-script.mjs +90 -2
- package/lib/mjs/autocomplete-scripts/powershell-autocomplete-script.mjs.map +7 -1
- package/lib/mjs/autocomplete-scripts/zsh-autocomplete-script.mjs +39 -13
- package/lib/mjs/autocomplete-scripts/zsh-autocomplete-script.mjs.map +7 -1
- package/lib/mjs/cli-error/cli-error.mjs +38 -0
- package/lib/mjs/cli-error/cli-error.mjs.map +7 -0
- package/lib/mjs/cli-error/error-cause.mjs +12 -0
- package/lib/mjs/cli-error/error-cause.mjs.map +7 -0
- package/lib/mjs/cli-error/error-code/definition-error-code.mjs +23 -0
- package/lib/mjs/cli-error/error-code/definition-error-code.mjs.map +7 -0
- package/lib/mjs/cli-error/error-code/internal-error-code.mjs +10 -0
- package/lib/mjs/cli-error/error-code/internal-error-code.mjs.map +7 -0
- package/lib/mjs/cli-error/error-code/parse-error-code.mjs +18 -0
- package/lib/mjs/cli-error/error-code/parse-error-code.mjs.map +7 -0
- package/lib/mjs/cli-error/error-code/validation-error-code.mjs +17 -0
- package/lib/mjs/cli-error/error-code/validation-error-code.mjs.map +7 -0
- package/lib/mjs/cli-error/error-message/definition-error-message.mjs +70 -0
- package/lib/mjs/cli-error/error-message/definition-error-message.mjs.map +7 -0
- package/lib/mjs/cli-error/error-message/internal-error-message.mjs +16 -0
- package/lib/mjs/cli-error/error-message/internal-error-message.mjs.map +7 -0
- package/lib/mjs/cli-error/error-message/parse-error-message.mjs +40 -0
- package/lib/mjs/cli-error/error-message/parse-error-message.mjs.map +7 -0
- package/lib/mjs/cli-error/error-message/validation-error-message.mjs +60 -0
- package/lib/mjs/cli-error/error-message/validation-error-message.mjs.map +7 -0
- package/lib/mjs/coerce/coerce-methods.mjs +197 -2
- package/lib/mjs/coerce/coerce-methods.mjs.map +7 -1
- package/lib/mjs/coerce/string-to-array.mjs +17 -2
- package/lib/mjs/coerce/string-to-array.mjs.map +7 -1
- package/lib/mjs/coerce/string-to-primitive.mjs +73 -2
- package/lib/mjs/coerce/string-to-primitive.mjs.map +7 -1
- package/lib/mjs/coerce/string-to-set.mjs +17 -2
- package/lib/mjs/coerce/string-to-set.mjs.map +7 -1
- package/lib/mjs/definitions/define-arguments.mjs +10 -2
- package/lib/mjs/definitions/define-arguments.mjs.map +7 -1
- package/lib/mjs/definitions/define-cli.mjs +89 -2
- package/lib/mjs/definitions/define-cli.mjs.map +7 -1
- package/lib/mjs/definitions/define-options.mjs +10 -2
- package/lib/mjs/definitions/define-options.mjs.map +7 -1
- package/lib/mjs/definitions/define-subcommand.mjs +56 -2
- package/lib/mjs/definitions/define-subcommand.mjs.map +7 -1
- package/lib/mjs/definitions/validate-cli-definition.mjs +360 -2
- package/lib/mjs/definitions/validate-cli-definition.mjs.map +7 -1
- package/lib/mjs/help-message/format-arguments.mjs +48 -2
- package/lib/mjs/help-message/format-arguments.mjs.map +7 -1
- package/lib/mjs/help-message/format-options.mjs +50 -2
- package/lib/mjs/help-message/format-options.mjs.map +7 -1
- package/lib/mjs/help-message/format-subcommands.mjs +37 -2
- package/lib/mjs/help-message/format-subcommands.mjs.map +7 -1
- package/lib/mjs/help-message/generate-for-cli.mjs +71 -2
- package/lib/mjs/help-message/generate-for-cli.mjs.map +7 -1
- package/lib/mjs/help-message/generate-for-subcommand.mjs +23 -2
- package/lib/mjs/help-message/generate-for-subcommand.mjs.map +7 -1
- package/lib/mjs/help-message/print-help.mjs +14 -2
- package/lib/mjs/help-message/print-help.mjs.map +7 -1
- package/lib/mjs/help-message/set-defaults.mjs +29 -2
- package/lib/mjs/help-message/set-defaults.mjs.map +7 -1
- package/lib/mjs/help-message/styles.mjs +154 -2
- package/lib/mjs/help-message/styles.mjs.map +7 -1
- package/lib/mjs/help-message/terminal-markdown.mjs +121 -2
- package/lib/mjs/help-message/terminal-markdown.mjs.map +7 -1
- package/lib/mjs/index.mjs +52 -2
- package/lib/mjs/index.mjs.map +7 -1
- package/lib/mjs/markdown/generate-markdown.mjs +153 -2
- package/lib/mjs/markdown/generate-markdown.mjs.map +7 -1
- package/lib/mjs/metadata/arguments-metadata.mjs +26 -2
- package/lib/mjs/metadata/arguments-metadata.mjs.map +7 -1
- package/lib/mjs/metadata/cli-metadata.mjs +24 -2
- package/lib/mjs/metadata/cli-metadata.mjs.map +7 -1
- package/lib/mjs/metadata/options-metadata.mjs +35 -2
- package/lib/mjs/metadata/options-metadata.mjs.map +7 -1
- package/lib/mjs/metadata/subcommands-metadata.mjs +32 -2
- package/lib/mjs/metadata/subcommands-metadata.mjs.map +7 -1
- package/lib/mjs/parse/context/cli-context-builder.mjs +283 -2
- package/lib/mjs/parse/context/cli-context-builder.mjs.map +7 -1
- package/lib/mjs/parse/context/object-context-builder.mjs +62 -2
- package/lib/mjs/parse/context/object-context-builder.mjs.map +7 -1
- package/lib/mjs/parse/parser-utilities.mjs +108 -2
- package/lib/mjs/parse/parser-utilities.mjs.map +7 -1
- package/lib/mjs/parse/safe-parse.mjs +57 -2
- package/lib/mjs/parse/safe-parse.mjs.map +7 -1
- package/lib/mjs/parse/validation/validate-context.mjs +17 -2
- package/lib/mjs/parse/validation/validate-context.mjs.map +7 -1
- package/lib/mjs/parse/validation/validators/arguments.mjs +67 -2
- package/lib/mjs/parse/validation/validators/arguments.mjs.map +7 -1
- package/lib/mjs/parse/validation/validators/conflict.mjs +38 -2
- package/lib/mjs/parse/validation/validators/conflict.mjs.map +7 -1
- package/lib/mjs/parse/validation/validators/exclusive.mjs +39 -2
- package/lib/mjs/parse/validation/validators/exclusive.mjs.map +7 -1
- package/lib/mjs/parse/validation/validators/explicitly-passed.mjs +18 -2
- package/lib/mjs/parse/validation/validators/explicitly-passed.mjs.map +7 -1
- package/lib/mjs/parse/validation/validators/options.mjs +67 -2
- package/lib/mjs/parse/validation/validators/options.mjs.map +7 -1
- package/lib/mjs/parse/validation/validators/requires.mjs +43 -2
- package/lib/mjs/parse/validation/validators/requires.mjs.map +7 -1
- package/lib/mjs/utilities/parse-argv.mjs +61 -0
- package/lib/mjs/utilities/parse-argv.mjs.map +7 -0
- package/lib/mjs/utilities/schema-utilities.mjs +57 -0
- package/lib/mjs/utilities/schema-utilities.mjs.map +7 -0
- package/lib/mjs/utilities/utilities.mjs +122 -0
- package/lib/mjs/utilities/utilities.mjs.map +7 -0
- package/lib/{typescript → types}/autocomplete-scripts/bash-autocomplete-script.d.ts.map +1 -1
- package/lib/types/autocomplete-scripts/powershell-autocomplete-script.d.ts +15 -0
- package/lib/{typescript → types}/autocomplete-scripts/powershell-autocomplete-script.d.ts.map +1 -1
- package/lib/types/autocomplete-scripts/zsh-autocomplete-script.d.ts +4 -0
- package/lib/{typescript → types}/autocomplete-scripts/zsh-autocomplete-script.d.ts.map +1 -1
- package/lib/types/cli-error/cli-error.d.ts +152 -0
- package/lib/types/cli-error/cli-error.d.ts.map +1 -0
- package/lib/types/cli-error/error-cause.d.ts +5 -0
- package/lib/types/cli-error/error-cause.d.ts.map +1 -0
- package/lib/types/cli-error/error-code/definition-error-code.d.ts +5 -0
- package/lib/types/cli-error/error-code/definition-error-code.d.ts.map +1 -0
- package/lib/types/cli-error/error-code/internal-error-code.d.ts +5 -0
- package/lib/types/cli-error/error-code/internal-error-code.d.ts.map +1 -0
- package/lib/types/cli-error/error-code/parse-error-code.d.ts +5 -0
- package/lib/types/cli-error/error-code/parse-error-code.d.ts.map +1 -0
- package/lib/types/cli-error/error-code/validation-error-code.d.ts +5 -0
- package/lib/types/cli-error/error-code/validation-error-code.d.ts.map +1 -0
- package/lib/types/cli-error/error-message/definition-error-message.d.ts +3 -0
- package/lib/types/cli-error/error-message/definition-error-message.d.ts.map +1 -0
- package/lib/types/cli-error/error-message/internal-error-message.d.ts +3 -0
- package/lib/types/cli-error/error-message/internal-error-message.d.ts.map +1 -0
- package/lib/types/cli-error/error-message/parse-error-message.d.ts +3 -0
- package/lib/types/cli-error/error-message/parse-error-message.d.ts.map +1 -0
- package/lib/types/cli-error/error-message/validation-error-message.d.ts +3 -0
- package/lib/types/cli-error/error-message/validation-error-message.d.ts.map +1 -0
- package/lib/types/coerce/coerce-methods.d.ts +122 -0
- package/lib/types/coerce/coerce-methods.d.ts.map +1 -0
- package/lib/{typescript → types}/coerce/string-to-array.d.ts +2 -2
- package/lib/types/coerce/string-to-array.d.ts.map +1 -0
- package/lib/types/coerce/string-to-primitive.d.ts +21 -0
- package/lib/types/coerce/string-to-primitive.d.ts.map +1 -0
- package/lib/{typescript → types}/coerce/string-to-set.d.ts +2 -2
- package/lib/{typescript → types}/coerce/string-to-set.d.ts.map +1 -1
- package/lib/{typescript → types}/definitions/define-cli.d.ts +2 -6
- package/lib/types/definitions/define-cli.d.ts.map +1 -0
- package/lib/{typescript → types}/definitions/define-subcommand.d.ts +2 -4
- package/lib/types/definitions/define-subcommand.d.ts.map +1 -0
- package/lib/{typescript → types}/definitions/validate-cli-definition.d.ts +1 -1
- package/lib/types/definitions/validate-cli-definition.d.ts.map +1 -0
- package/lib/{typescript → types}/help-message/terminal-markdown.d.ts.map +1 -1
- package/lib/{typescript → types}/index.d.ts +7 -0
- package/lib/{typescript → types}/index.d.ts.map +1 -1
- package/lib/{typescript → types}/metadata/arguments-metadata.d.ts.map +1 -1
- package/lib/{typescript → types}/metadata/options-metadata.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/context/cli-context-builder.d.ts +1 -1
- package/lib/{typescript → types}/parse/context/cli-context-builder.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/context/object-context-builder.d.ts +1 -1
- package/lib/types/parse/context/object-context-builder.d.ts.map +1 -0
- package/lib/{typescript → types}/parse/parser-utilities.d.ts +9 -0
- package/lib/{typescript → types}/parse/parser-utilities.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/safe-parse.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/validation/validate-context.d.ts +1 -1
- package/lib/{typescript → types}/parse/validation/validate-context.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/validation/validators/arguments.d.ts +1 -1
- package/lib/{typescript → types}/parse/validation/validators/arguments.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/validation/validators/conflict.d.ts +3 -3
- package/lib/{typescript → types}/parse/validation/validators/conflict.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/validation/validators/exclusive.d.ts +3 -3
- package/lib/{typescript → types}/parse/validation/validators/exclusive.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/validation/validators/options.d.ts +1 -1
- package/lib/{typescript → types}/parse/validation/validators/options.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/validation/validators/requires.d.ts +3 -3
- package/lib/{typescript → types}/parse/validation/validators/requires.d.ts.map +1 -1
- package/lib/{typescript → types}/types/definitions-types.d.ts +35 -4
- package/lib/types/types/definitions-types.d.ts.map +1 -0
- package/lib/types/types/error-types.d.ts +275 -0
- package/lib/types/types/error-types.d.ts.map +1 -0
- package/lib/{typescript → types}/types/io-types.d.ts +1 -1
- package/lib/types/types/types.d.ts +146 -0
- package/lib/types/types/types.d.ts.map +1 -0
- package/lib/{typescript → types}/types/utilities-types.d.ts +0 -2
- package/lib/{typescript → types}/types/utilities-types.d.ts.map +1 -1
- package/lib/types/utilities/parse-argv.d.ts +3 -0
- package/lib/types/utilities/parse-argv.d.ts.map +1 -0
- package/lib/types/utilities/schema-utilities.d.ts +15 -0
- package/lib/types/utilities/schema-utilities.d.ts.map +1 -0
- package/lib/{typescript → types/utilities}/utilities.d.ts +12 -15
- package/lib/types/utilities/utilities.d.ts.map +1 -0
- package/package.json +7 -7
- package/src/autocomplete-scripts/bash-autocomplete-script.ts +14 -12
- package/src/autocomplete-scripts/powershell-autocomplete-script.ts +67 -33
- package/src/autocomplete-scripts/zsh-autocomplete-script.ts +39 -31
- package/src/cli-error/cli-error.ts +44 -0
- package/src/cli-error/error-cause.ts +10 -0
- package/src/cli-error/error-code/definition-error-code.ts +21 -0
- package/src/cli-error/error-code/internal-error-code.ts +8 -0
- package/src/cli-error/error-code/parse-error-code.ts +16 -0
- package/src/cli-error/error-code/validation-error-code.ts +15 -0
- package/src/cli-error/error-message/definition-error-message.ts +144 -0
- package/src/cli-error/error-message/internal-error-message.ts +19 -0
- package/src/cli-error/error-message/parse-error-message.ts +76 -0
- package/src/cli-error/error-message/validation-error-message.ts +104 -0
- package/src/coerce/coerce-methods.ts +194 -39
- package/src/coerce/string-to-array.ts +2 -2
- package/src/coerce/string-to-primitive.ts +72 -13
- package/src/coerce/string-to-set.ts +2 -2
- package/src/definitions/define-arguments.ts +1 -1
- package/src/definitions/define-cli.ts +65 -30
- package/src/definitions/define-options.ts +1 -1
- package/src/definitions/define-subcommand.ts +47 -17
- package/src/definitions/validate-cli-definition.ts +287 -172
- package/src/help-message/format-arguments.ts +1 -1
- package/src/help-message/format-options.ts +1 -1
- package/src/help-message/format-subcommands.ts +1 -1
- package/src/help-message/generate-for-cli.ts +1 -1
- package/src/help-message/terminal-markdown.ts +3 -4
- package/src/index.ts +16 -0
- package/src/markdown/generate-markdown.ts +5 -4
- package/src/metadata/arguments-metadata.ts +2 -1
- package/src/metadata/options-metadata.ts +2 -1
- package/src/parse/context/cli-context-builder.ts +166 -39
- package/src/parse/context/object-context-builder.ts +37 -11
- package/src/parse/parser-utilities.ts +24 -10
- package/src/parse/safe-parse.ts +3 -6
- package/src/parse/validation/validate-context.ts +1 -1
- package/src/parse/validation/validators/arguments.ts +42 -14
- package/src/parse/validation/validators/conflict.ts +11 -20
- package/src/parse/validation/validators/exclusive.ts +16 -25
- package/src/parse/validation/validators/options.ts +40 -12
- package/src/parse/validation/validators/requires.ts +11 -20
- package/src/types/definitions-types.ts +36 -8
- package/src/types/error-types.ts +326 -0
- package/src/types/io-types.ts +1 -1
- 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.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,30 @@ 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)
|
|
26
30
|
- [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)
|
|
31
|
+
- [Type Utilities](docs/api-reference.md#type-utilities)
|
|
32
|
+
- [Coerce Helpers](docs/api-reference.md#coerce-helpers)
|
|
33
|
+
- [Markdown Generation](docs/api-reference.md#markdown-generation)
|
|
34
|
+
- [Autocompletion Script Generation](docs/api-reference.md#autocompletion-script-generation)
|
|
35
|
+
- [Help Message](docs/api-reference.md#help-message)
|
|
36
|
+
- [PrintHelpOptions](docs/api-reference.md#printhelpoptions)
|
|
37
|
+
- [Cli](docs/api-reference.md#cli)
|
|
38
|
+
- [Subcommand](docs/api-reference.md#subcommand)
|
|
39
|
+
- [Option](docs/api-reference.md#option)
|
|
40
|
+
- [Argument](docs/api-reference.md#argument)
|
|
41
|
+
- [Context Type](docs/api-reference.md#context-type)
|
|
42
|
+
- [Error Types](docs/api-reference.md#error-types)
|
|
38
43
|
- [License](#license)
|
|
39
44
|
|
|
40
45
|
## Features
|
|
@@ -65,46 +70,29 @@ The following example uses `zod` as the validation library, but you can use any
|
|
|
65
70
|
import * as z from "zod";
|
|
66
71
|
import { defineCLI, coerce } from "zod-args-parser";
|
|
67
72
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
cliName: "listy",
|
|
71
|
-
|
|
72
|
-
subcommands: [
|
|
73
|
-
// ...
|
|
74
|
-
],
|
|
75
|
-
|
|
73
|
+
const cli = defineCLI({
|
|
74
|
+
cliName: "hello",
|
|
76
75
|
options: {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
/**
|
|
77
|
+
* 💡 **Tip:** Adding a **JSDoc** comment here will be displayed in IDE hovers alongside the TypeScript type.
|
|
78
|
+
*
|
|
79
|
+
* `--name` or `-n`
|
|
80
|
+
*/
|
|
81
|
+
name: {
|
|
82
|
+
aliases: ["n"],
|
|
83
|
+
schema: z.string().default("world"),
|
|
80
84
|
},
|
|
81
85
|
},
|
|
82
|
-
|
|
83
|
-
arguments: {
|
|
84
|
-
// ...
|
|
85
|
-
},
|
|
86
86
|
});
|
|
87
87
|
|
|
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`");
|
|
88
|
+
cli.onExecute(({ options }) => {
|
|
89
|
+
console.log(`Hello, ${options.name}!`);
|
|
99
90
|
});
|
|
100
91
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (results.error) {
|
|
106
|
-
console.error(results.error.message);
|
|
107
|
-
console.log("\n`listy --help` for more information");
|
|
92
|
+
const result = cli.run(process.argv.slice(2));
|
|
93
|
+
if (result.error) {
|
|
94
|
+
console.error(result.error.message);
|
|
95
|
+
process.exit(1);
|
|
108
96
|
}
|
|
109
97
|
```
|
|
110
98
|
|
|
@@ -220,6 +208,7 @@ Option names can use any common case style:
|
|
|
220
208
|
- LIST_NAME `=>` --list-name
|
|
221
209
|
|
|
222
210
|
```ts
|
|
211
|
+
import * as z from "zod";
|
|
223
212
|
import { defineSubcommand, coerce } from "zod-args-parser";
|
|
224
213
|
|
|
225
214
|
const createListCommand = defineSubcommand({
|
|
@@ -329,6 +318,52 @@ const createListCommand = defineSubcommand({
|
|
|
329
318
|
});
|
|
330
319
|
```
|
|
331
320
|
|
|
321
|
+
### Sharing options and typed arguments
|
|
322
|
+
|
|
323
|
+
Options and typed arguments can be shared between subcommands/main CLI.
|
|
324
|
+
|
|
325
|
+
```ts
|
|
326
|
+
// shared.ts
|
|
327
|
+
import * as z from "zod";
|
|
328
|
+
import { defineArguments, defineOptions, coerce } from "zod-args-parser";
|
|
329
|
+
|
|
330
|
+
export const sharedOptions = defineOptions({
|
|
331
|
+
verbose: {
|
|
332
|
+
schema: z.boolean().optional(),
|
|
333
|
+
coerce: coerce.boolean,
|
|
334
|
+
meta: {
|
|
335
|
+
description: "Enable verbose mode.",
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
export const sharedArguments = defineArguments({
|
|
341
|
+
// ...
|
|
342
|
+
});
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
```ts
|
|
346
|
+
// add-command.ts
|
|
347
|
+
import * as z from "zod";
|
|
348
|
+
import { defineSubcommand, coerce } from "zod-args-parser";
|
|
349
|
+
|
|
350
|
+
import { sharedOptions, sharedArguments } from "./shared.ts";
|
|
351
|
+
|
|
352
|
+
export const addCommand = defineSubcommand({
|
|
353
|
+
//...
|
|
354
|
+
|
|
355
|
+
options: {
|
|
356
|
+
// ...
|
|
357
|
+
...sharedOptions,
|
|
358
|
+
},
|
|
359
|
+
|
|
360
|
+
arguments: {
|
|
361
|
+
// ...
|
|
362
|
+
...sharedArguments,
|
|
363
|
+
},
|
|
364
|
+
});
|
|
365
|
+
```
|
|
366
|
+
|
|
332
367
|
### Using schemas
|
|
333
368
|
|
|
334
369
|
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 +427,130 @@ Both options and typed arguments support rules to control valid combinations:
|
|
|
392
427
|
|
|
393
428
|
### Negating a boolean option
|
|
394
429
|
|
|
395
|
-
Boolean
|
|
430
|
+
Boolean flags are `true` when they appear on the command line.
|
|
431
|
+
Prefixing a flag with `--no-` inverts its final value.
|
|
432
|
+
|
|
433
|
+
When a value is explicitly assigned (`=true` or `=false`), the assignment is applied first, then the `--no-` prefix flips the result.
|
|
434
|
+
|
|
435
|
+
Examples:
|
|
396
436
|
|
|
397
437
|
```sh
|
|
398
|
-
--bool
|
|
399
|
-
--no-bool
|
|
438
|
+
--bool true
|
|
439
|
+
--no-bool false
|
|
440
|
+
```
|
|
400
441
|
|
|
401
|
-
|
|
402
|
-
--bool=
|
|
442
|
+
```sh
|
|
443
|
+
--bool=true true
|
|
444
|
+
--bool=false false
|
|
445
|
+
```
|
|
403
446
|
|
|
404
|
-
|
|
405
|
-
--no-
|
|
447
|
+
```sh
|
|
448
|
+
--no-bool=true false # assigned true → inverted
|
|
449
|
+
--no-bool=false true # assigned false → inverted
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
Short-form flags follow the same logic, but do **not** accept `=value` syntax:
|
|
453
|
+
|
|
454
|
+
```sh
|
|
455
|
+
-v true
|
|
456
|
+
--no-v false
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
```sh
|
|
460
|
+
-v=true ERROR
|
|
461
|
+
-v=false ERROR
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
```sh
|
|
465
|
+
--no-v=true false
|
|
466
|
+
--no-v=false true
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
### Structured Object Options
|
|
470
|
+
|
|
471
|
+
Options using `coerce.object` receive **stringified JSON** and are parsed with `JSON.parse`.
|
|
472
|
+
They also support **dotted flags** to assign nested fields without writing full JSON.
|
|
473
|
+
|
|
474
|
+
See [Coerce Helpers](./docs/api-reference.md#coerce-helpers).
|
|
475
|
+
|
|
476
|
+
```ts
|
|
477
|
+
import * as z from "zod";
|
|
478
|
+
import { defineCLI, coerce } from "zod-args-parser";
|
|
479
|
+
|
|
480
|
+
const cli = defineCLI({
|
|
481
|
+
cliName: "listy",
|
|
482
|
+
options: {
|
|
483
|
+
db: {
|
|
484
|
+
schema: z
|
|
485
|
+
.object({
|
|
486
|
+
host: z.string().default("localhost"),
|
|
487
|
+
port: z.number().default(5432),
|
|
488
|
+
https: z.boolean().default(false),
|
|
489
|
+
credentials: z.object({
|
|
490
|
+
user: z.string(),
|
|
491
|
+
pass: z.string(),
|
|
492
|
+
}),
|
|
493
|
+
})
|
|
494
|
+
.optional(),
|
|
495
|
+
|
|
496
|
+
// Accepts either a full JSON string or individual "dotted" flags,
|
|
497
|
+
// parsed with JSON.parse.
|
|
498
|
+
coerce: coerce.object({ coerceBoolean: true, coerceNumber: ["port"] }),
|
|
499
|
+
|
|
500
|
+
meta: {
|
|
501
|
+
placeholder: "<.host,.port,.credentials.user,.credentials.pass>",
|
|
502
|
+
description: "Database configuration object. Parsed as JSON; supports dotted flags.",
|
|
503
|
+
example: "--db.host=prod-db --db.credentials.user=alice --db.credentials.pass=secret",
|
|
504
|
+
},
|
|
505
|
+
},
|
|
506
|
+
},
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
cli.onExecute(({ options }) => {
|
|
510
|
+
console.log(options.db);
|
|
511
|
+
});
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
#### Usage Examples
|
|
515
|
+
|
|
516
|
+
```sh
|
|
517
|
+
# Dotted flags for nested values using `=`
|
|
518
|
+
listy --db.https=true --db.host=db.local --db.port=3306 --db.credentials.user=root --db.credentials.pass=toor
|
|
519
|
+
|
|
520
|
+
# Dotted flags for nested values without `=`
|
|
521
|
+
listy --db.https true --db.host db.local --db.port 3306 --db.credentials.user root --db.credentials.pass toor
|
|
522
|
+
|
|
523
|
+
# Full JSON input (stringified)
|
|
524
|
+
listy --db '{"host":"db.local","https":true,"credentials":{"user":"root","pass":"toor"}}'
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
### Execute commands programmatically
|
|
528
|
+
|
|
529
|
+
You can execute the main CLI or a specific subcommand directly from code.
|
|
530
|
+
The input is provided as an object (`{ options, arguments, positionals }`) and is validated using the defined schemas.
|
|
531
|
+
Invalid input throws an error. Use `.executeAsync()` if your `onExecute` handler is asynchronous.
|
|
532
|
+
|
|
533
|
+
> [!NOTE]
|
|
534
|
+
> `run()` is like calling the CLI from the terminal.
|
|
535
|
+
> `execute()` is like calling a function directly.
|
|
536
|
+
|
|
537
|
+
```ts
|
|
538
|
+
import { InferOptionsInputType } from "zod-args-parser";
|
|
539
|
+
|
|
540
|
+
import { listyCLI } from "./cli.ts";
|
|
541
|
+
|
|
542
|
+
// In this example, Listy only defines options — no typed arguments or positionals.
|
|
543
|
+
// To keep the function simple, we accept only the options as input.
|
|
544
|
+
|
|
545
|
+
/** @throws {CliError} */
|
|
546
|
+
export function executeListy(options: InferOptionsInputType<typeof listyCLI>) {
|
|
547
|
+
listyCLI.execute({ options });
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/** @throws {CliError} */
|
|
551
|
+
export async function executeListyAsync(options: InferOptionsInputType<typeof listyCLI>) {
|
|
552
|
+
await listyCLI.executeAsync({ options });
|
|
553
|
+
}
|
|
406
554
|
```
|
|
407
555
|
|
|
408
556
|
### Creating a Custom Help Message Style
|
|
@@ -452,257 +600,50 @@ span._markdown * {
|
|
|
452
600
|
}
|
|
453
601
|
```
|
|
454
602
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
### Type Utilities
|
|
458
|
-
|
|
459
|
-
#### `InferInputType<T extends Cli | Subcommand>`
|
|
460
|
-
|
|
461
|
-
Infer options, arguments, and positionals input types from the CLI/subcommand definition.
|
|
462
|
-
|
|
463
|
-
#### `InferOutputType<T extends Cli | Subcommand>`
|
|
464
|
-
|
|
465
|
-
Infer options, arguments, and positionals output types from the CLI/subcommand definition.
|
|
466
|
-
|
|
467
|
-
#### `InferOptionsInputType<T extends Cli | Subcommand>`
|
|
603
|
+
### Handling and Inspecting Errors
|
|
468
604
|
|
|
469
|
-
|
|
605
|
+
The library processes input in four stages. Errors can occur at any step:
|
|
470
606
|
|
|
471
|
-
|
|
607
|
+
1. **Definition Validation** — Ensures the CLI and subcommand definitions are valid.
|
|
608
|
+
2. **Argument Parsing** — Reads terminal input and builds the initial parse result.
|
|
609
|
+
3. **Context Validation** — Applies schema validation and dependency rules.
|
|
610
|
+
4. **Execution** — Runs the command or subcommand once all checks succeed.
|
|
472
611
|
|
|
473
|
-
|
|
612
|
+
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.
|
|
474
613
|
|
|
475
|
-
|
|
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.
|
|
614
|
+
See [Error Reference](./docs/api-reference.md#error-types)
|
|
482
615
|
|
|
483
616
|
```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
|
|
617
|
+
import { ErrorCause, ValidationErrorCode } from "zod-args-parser";
|
|
495
618
|
|
|
496
|
-
|
|
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>()`
|
|
619
|
+
const results = listyCLI.run(input);
|
|
506
620
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
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`
|
|
532
|
-
|
|
533
|
-
Generate a PowerShell autocomplete script for a **CLI definition** and return it as a `string`.
|
|
534
|
-
|
|
535
|
-
### Help Message
|
|
536
|
-
|
|
537
|
-
#### generateCliHelpMessage
|
|
538
|
-
|
|
539
|
-
`(cliDefinition: Cli, printOptions?: PrintHelpOptions) => string`
|
|
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).
|
|
557
|
-
|
|
558
|
-
#### printSubcommandHelp
|
|
559
|
-
|
|
560
|
-
`(commandDefinition: Subcommand, options?: PrintHelpOptions, cliName?: string) => void`
|
|
561
|
-
|
|
562
|
-
Print a help message for a **subcommand definition**.
|
|
563
|
-
See [`PrintHelpOptions`](#printhelpoptions) and [`Subcommand`](#subcommand).
|
|
564
|
-
|
|
565
|
-
### PrintHelpOptions
|
|
566
|
-
|
|
567
|
-
| Option | Type | Default | Description |
|
|
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. |
|
|
588
|
-
|
|
589
|
-
### Cli
|
|
590
|
-
|
|
591
|
-
| Property | Type | Description |
|
|
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. |
|
|
621
|
+
if (results.error) {
|
|
622
|
+
// Check the type of error by its cause
|
|
623
|
+
if (results.error.cause === ErrorCause.Parse) {
|
|
624
|
+
// Handle parsing-related errors
|
|
625
|
+
}
|
|
599
626
|
|
|
600
|
-
|
|
627
|
+
// Check for a specific error code
|
|
628
|
+
if (results.error.code === ValidationErrorCode.SchemaValidationFailed) {
|
|
629
|
+
const { commandKind, commandName, kind, name, inputValue, issues } = results.error.context;
|
|
601
630
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
631
|
+
console.error(
|
|
632
|
+
"validation error:",
|
|
633
|
+
`the ${kind} "${name}"`,
|
|
634
|
+
`for ${commandKind} "${commandName}" failed to validate the input:`,
|
|
635
|
+
inputValue,
|
|
636
|
+
);
|
|
608
637
|
|
|
609
|
-
|
|
638
|
+
// Detailed validation issues
|
|
639
|
+
console.log(issues);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
```
|
|
610
643
|
|
|
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. |
|
|
644
|
+
## API Reference
|
|
619
645
|
|
|
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. |
|
|
646
|
+
See the [API Reference](docs/api-reference.md) for more information.
|
|
706
647
|
|
|
707
648
|
## License
|
|
708
649
|
|