zod-args-parser 1.2.8 → 2.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +525 -588
- package/lib/cjs/autocomplete-scripts/bash-autocomplete-script.cjs +2 -0
- package/lib/cjs/autocomplete-scripts/bash-autocomplete-script.cjs.map +1 -0
- package/lib/cjs/autocomplete-scripts/powershell-autocomplete-script.cjs +2 -0
- package/lib/cjs/autocomplete-scripts/powershell-autocomplete-script.cjs.map +1 -0
- package/lib/cjs/autocomplete-scripts/zsh-autocomplete-script.cjs +42 -0
- package/lib/cjs/autocomplete-scripts/zsh-autocomplete-script.cjs.map +1 -0
- package/lib/cjs/coerce/coerce-methods.cjs +2 -0
- package/lib/cjs/coerce/coerce-methods.cjs.map +1 -0
- package/lib/cjs/coerce/string-to-array.cjs +2 -0
- package/lib/cjs/coerce/string-to-array.cjs.map +1 -0
- package/lib/cjs/coerce/string-to-primitive.cjs +2 -0
- package/lib/cjs/coerce/string-to-primitive.cjs.map +1 -0
- package/lib/cjs/coerce/string-to-set.cjs +2 -0
- package/lib/cjs/coerce/string-to-set.cjs.map +1 -0
- package/lib/cjs/definitions/define-arguments.cjs +2 -0
- package/lib/cjs/definitions/define-arguments.cjs.map +1 -0
- package/lib/cjs/definitions/define-cli.cjs +2 -0
- package/lib/cjs/definitions/define-cli.cjs.map +1 -0
- package/lib/cjs/definitions/define-options.cjs +2 -0
- package/lib/cjs/definitions/define-options.cjs.map +1 -0
- package/lib/cjs/definitions/define-subcommand.cjs +2 -0
- package/lib/cjs/definitions/define-subcommand.cjs.map +1 -0
- package/lib/cjs/definitions/validate-cli-definition.cjs +2 -0
- package/lib/cjs/definitions/validate-cli-definition.cjs.map +1 -0
- package/lib/cjs/help-message/format-arguments.cjs +2 -0
- package/lib/cjs/help-message/format-arguments.cjs.map +1 -0
- package/lib/cjs/help-message/format-options.cjs +2 -0
- package/lib/cjs/help-message/format-options.cjs.map +1 -0
- package/lib/cjs/help-message/format-subcommands.cjs +2 -0
- package/lib/cjs/help-message/format-subcommands.cjs.map +1 -0
- package/lib/cjs/help-message/generate-for-cli.cjs +2 -0
- package/lib/cjs/help-message/generate-for-cli.cjs.map +1 -0
- package/lib/cjs/help-message/generate-for-subcommand.cjs +2 -0
- package/lib/cjs/help-message/generate-for-subcommand.cjs.map +1 -0
- package/lib/cjs/help-message/print-help.cjs +2 -0
- package/lib/cjs/help-message/print-help.cjs.map +1 -0
- package/lib/cjs/help-message/set-defaults.cjs +2 -0
- package/lib/cjs/help-message/set-defaults.cjs.map +1 -0
- package/lib/cjs/help-message/styles.cjs +2 -0
- package/lib/cjs/help-message/styles.cjs.map +1 -0
- package/lib/cjs/help-message/terminal-markdown.cjs +2 -0
- package/lib/cjs/help-message/terminal-markdown.cjs.map +1 -0
- package/lib/cjs/index.cjs +2 -0
- package/lib/cjs/index.cjs.map +1 -0
- package/lib/cjs/markdown/generate-markdown.cjs +2 -0
- package/lib/cjs/markdown/generate-markdown.cjs.map +1 -0
- package/lib/cjs/metadata/arguments-metadata.cjs +2 -0
- package/lib/cjs/metadata/arguments-metadata.cjs.map +1 -0
- package/lib/cjs/metadata/cli-metadata.cjs +2 -0
- package/lib/cjs/metadata/cli-metadata.cjs.map +1 -0
- package/lib/cjs/metadata/options-metadata.cjs +2 -0
- package/lib/cjs/metadata/options-metadata.cjs.map +1 -0
- package/lib/cjs/metadata/subcommands-metadata.cjs +2 -0
- package/lib/cjs/metadata/subcommands-metadata.cjs.map +1 -0
- package/lib/cjs/parse/context/cli-context-builder.cjs +2 -0
- package/lib/cjs/parse/context/cli-context-builder.cjs.map +1 -0
- package/lib/cjs/parse/context/object-context-builder.cjs +2 -0
- package/lib/cjs/parse/context/object-context-builder.cjs.map +1 -0
- package/lib/cjs/parse/parser-utilities.cjs +2 -0
- package/lib/cjs/parse/parser-utilities.cjs.map +1 -0
- package/lib/cjs/parse/safe-parse.cjs +2 -0
- package/lib/cjs/parse/safe-parse.cjs.map +1 -0
- package/lib/cjs/parse/validation/validate-context.cjs +2 -0
- package/lib/cjs/parse/validation/validate-context.cjs.map +1 -0
- package/lib/cjs/parse/validation/validators/arguments.cjs +2 -0
- package/lib/cjs/parse/validation/validators/arguments.cjs.map +1 -0
- package/lib/cjs/parse/validation/validators/conflict.cjs +2 -0
- package/lib/cjs/parse/validation/validators/conflict.cjs.map +1 -0
- package/lib/cjs/parse/validation/validators/exclusive.cjs +2 -0
- package/lib/cjs/parse/validation/validators/exclusive.cjs.map +1 -0
- package/lib/cjs/parse/validation/validators/explicitly-passed.cjs +2 -0
- package/lib/cjs/parse/validation/validators/explicitly-passed.cjs.map +1 -0
- package/lib/cjs/parse/validation/validators/options.cjs +2 -0
- package/lib/cjs/parse/validation/validators/options.cjs.map +1 -0
- package/lib/cjs/parse/validation/validators/requires.cjs +2 -0
- package/lib/cjs/parse/validation/validators/requires.cjs.map +1 -0
- package/lib/cjs/utilities.cjs +2 -0
- package/lib/cjs/utilities.cjs.map +1 -0
- package/lib/esm/autocomplete-scripts/bash-autocomplete-script.js +2 -0
- package/lib/esm/autocomplete-scripts/bash-autocomplete-script.js.map +1 -0
- package/lib/esm/autocomplete-scripts/powershell-autocomplete-script.js +2 -0
- package/lib/esm/autocomplete-scripts/powershell-autocomplete-script.js.map +1 -0
- package/lib/esm/autocomplete-scripts/zsh-autocomplete-script.js +42 -0
- package/lib/esm/autocomplete-scripts/zsh-autocomplete-script.js.map +1 -0
- package/lib/esm/coerce/coerce-methods.js +2 -0
- package/lib/esm/coerce/coerce-methods.js.map +1 -0
- package/lib/esm/coerce/string-to-array.js +2 -0
- package/lib/esm/coerce/string-to-array.js.map +1 -0
- package/lib/esm/coerce/string-to-primitive.js +2 -0
- package/lib/esm/coerce/string-to-primitive.js.map +1 -0
- package/lib/esm/coerce/string-to-set.js +2 -0
- package/lib/esm/coerce/string-to-set.js.map +1 -0
- package/lib/esm/definitions/define-arguments.js +2 -0
- package/lib/esm/definitions/define-arguments.js.map +1 -0
- package/lib/esm/definitions/define-cli.js +2 -0
- package/lib/esm/definitions/define-cli.js.map +1 -0
- package/lib/esm/definitions/define-options.js +2 -0
- package/lib/esm/definitions/define-options.js.map +1 -0
- package/lib/esm/definitions/define-subcommand.js +2 -0
- package/lib/esm/definitions/define-subcommand.js.map +1 -0
- package/lib/esm/definitions/validate-cli-definition.js +2 -0
- package/lib/esm/definitions/validate-cli-definition.js.map +1 -0
- package/lib/esm/help-message/format-arguments.js +2 -0
- package/lib/esm/help-message/format-arguments.js.map +1 -0
- package/lib/esm/help-message/format-options.js +2 -0
- package/lib/esm/help-message/format-options.js.map +1 -0
- package/lib/esm/help-message/format-subcommands.js +2 -0
- package/lib/esm/help-message/format-subcommands.js.map +1 -0
- package/lib/esm/help-message/generate-for-cli.js +2 -0
- package/lib/esm/help-message/generate-for-cli.js.map +1 -0
- package/lib/esm/help-message/generate-for-subcommand.js +2 -0
- package/lib/esm/help-message/generate-for-subcommand.js.map +1 -0
- package/lib/esm/help-message/print-help.js +2 -0
- package/lib/esm/help-message/print-help.js.map +1 -0
- package/lib/esm/help-message/set-defaults.js +2 -0
- package/lib/esm/help-message/set-defaults.js.map +1 -0
- package/lib/esm/help-message/styles.js +2 -0
- package/lib/esm/help-message/styles.js.map +1 -0
- package/lib/esm/help-message/terminal-markdown.js +2 -0
- package/lib/esm/help-message/terminal-markdown.js.map +1 -0
- package/lib/esm/index.js +2 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/markdown/generate-markdown.js +2 -0
- package/lib/esm/markdown/generate-markdown.js.map +1 -0
- package/lib/esm/metadata/arguments-metadata.js +2 -0
- package/lib/esm/metadata/arguments-metadata.js.map +1 -0
- package/lib/esm/metadata/cli-metadata.js +2 -0
- package/lib/esm/metadata/cli-metadata.js.map +1 -0
- package/lib/esm/metadata/options-metadata.js +2 -0
- package/lib/esm/metadata/options-metadata.js.map +1 -0
- package/lib/esm/metadata/subcommands-metadata.js +2 -0
- package/lib/esm/metadata/subcommands-metadata.js.map +1 -0
- package/lib/esm/parse/context/cli-context-builder.js +2 -0
- package/lib/esm/parse/context/cli-context-builder.js.map +1 -0
- package/lib/esm/parse/context/object-context-builder.js +2 -0
- package/lib/esm/parse/context/object-context-builder.js.map +1 -0
- package/lib/esm/parse/parser-utilities.js +2 -0
- package/lib/esm/parse/parser-utilities.js.map +1 -0
- package/lib/esm/parse/safe-parse.js +2 -0
- package/lib/esm/parse/safe-parse.js.map +1 -0
- package/lib/esm/parse/validation/validate-context.js +2 -0
- package/lib/esm/parse/validation/validate-context.js.map +1 -0
- package/lib/esm/parse/validation/validators/arguments.js +2 -0
- package/lib/esm/parse/validation/validators/arguments.js.map +1 -0
- package/lib/esm/parse/validation/validators/conflict.js +2 -0
- package/lib/esm/parse/validation/validators/conflict.js.map +1 -0
- package/lib/esm/parse/validation/validators/exclusive.js +2 -0
- package/lib/esm/parse/validation/validators/exclusive.js.map +1 -0
- package/lib/esm/parse/validation/validators/explicitly-passed.js +2 -0
- package/lib/esm/parse/validation/validators/explicitly-passed.js.map +1 -0
- package/lib/esm/parse/validation/validators/options.js +2 -0
- package/lib/esm/parse/validation/validators/options.js.map +1 -0
- package/lib/esm/parse/validation/validators/requires.js +2 -0
- package/lib/esm/parse/validation/validators/requires.js.map +1 -0
- package/lib/esm/utilities.js +2 -0
- package/lib/esm/utilities.js.map +1 -0
- package/lib/iife/index.js +2 -0
- package/lib/iife/index.js.map +1 -0
- package/lib/mjs/autocomplete-scripts/bash-autocomplete-script.mjs +2 -0
- package/lib/mjs/autocomplete-scripts/bash-autocomplete-script.mjs.map +1 -0
- package/lib/mjs/autocomplete-scripts/powershell-autocomplete-script.mjs +2 -0
- package/lib/mjs/autocomplete-scripts/powershell-autocomplete-script.mjs.map +1 -0
- package/lib/mjs/autocomplete-scripts/zsh-autocomplete-script.mjs +42 -0
- package/lib/mjs/autocomplete-scripts/zsh-autocomplete-script.mjs.map +1 -0
- package/lib/mjs/coerce/coerce-methods.mjs +2 -0
- package/lib/mjs/coerce/coerce-methods.mjs.map +1 -0
- package/lib/mjs/coerce/string-to-array.mjs +2 -0
- package/lib/mjs/coerce/string-to-array.mjs.map +1 -0
- package/lib/mjs/coerce/string-to-primitive.mjs +2 -0
- package/lib/mjs/coerce/string-to-primitive.mjs.map +1 -0
- package/lib/mjs/coerce/string-to-set.mjs +2 -0
- package/lib/mjs/coerce/string-to-set.mjs.map +1 -0
- package/lib/mjs/definitions/define-arguments.mjs +2 -0
- package/lib/mjs/definitions/define-arguments.mjs.map +1 -0
- package/lib/mjs/definitions/define-cli.mjs +2 -0
- package/lib/mjs/definitions/define-cli.mjs.map +1 -0
- package/lib/mjs/definitions/define-options.mjs +2 -0
- package/lib/mjs/definitions/define-options.mjs.map +1 -0
- package/lib/mjs/definitions/define-subcommand.mjs +2 -0
- package/lib/mjs/definitions/define-subcommand.mjs.map +1 -0
- package/lib/mjs/definitions/validate-cli-definition.mjs +2 -0
- package/lib/mjs/definitions/validate-cli-definition.mjs.map +1 -0
- package/lib/mjs/help-message/format-arguments.mjs +2 -0
- package/lib/mjs/help-message/format-arguments.mjs.map +1 -0
- package/lib/mjs/help-message/format-options.mjs +2 -0
- package/lib/mjs/help-message/format-options.mjs.map +1 -0
- package/lib/mjs/help-message/format-subcommands.mjs +2 -0
- package/lib/mjs/help-message/format-subcommands.mjs.map +1 -0
- package/lib/mjs/help-message/generate-for-cli.mjs +2 -0
- package/lib/mjs/help-message/generate-for-cli.mjs.map +1 -0
- package/lib/mjs/help-message/generate-for-subcommand.mjs +2 -0
- package/lib/mjs/help-message/generate-for-subcommand.mjs.map +1 -0
- package/lib/mjs/help-message/print-help.mjs +2 -0
- package/lib/mjs/help-message/print-help.mjs.map +1 -0
- package/lib/mjs/help-message/set-defaults.mjs +2 -0
- package/lib/mjs/help-message/set-defaults.mjs.map +1 -0
- package/lib/mjs/help-message/styles.mjs +2 -0
- package/lib/mjs/help-message/styles.mjs.map +1 -0
- package/lib/mjs/help-message/terminal-markdown.mjs +2 -0
- package/lib/mjs/help-message/terminal-markdown.mjs.map +1 -0
- package/lib/mjs/index.mjs +2 -0
- package/lib/mjs/index.mjs.map +1 -0
- package/lib/mjs/markdown/generate-markdown.mjs +2 -0
- package/lib/mjs/markdown/generate-markdown.mjs.map +1 -0
- package/lib/mjs/metadata/arguments-metadata.mjs +2 -0
- package/lib/mjs/metadata/arguments-metadata.mjs.map +1 -0
- package/lib/mjs/metadata/cli-metadata.mjs +2 -0
- package/lib/mjs/metadata/cli-metadata.mjs.map +1 -0
- package/lib/mjs/metadata/options-metadata.mjs +2 -0
- package/lib/mjs/metadata/options-metadata.mjs.map +1 -0
- package/lib/mjs/metadata/subcommands-metadata.mjs +2 -0
- package/lib/mjs/metadata/subcommands-metadata.mjs.map +1 -0
- package/lib/mjs/parse/context/cli-context-builder.mjs +2 -0
- package/lib/mjs/parse/context/cli-context-builder.mjs.map +1 -0
- package/lib/mjs/parse/context/object-context-builder.mjs +2 -0
- package/lib/mjs/parse/context/object-context-builder.mjs.map +1 -0
- package/lib/mjs/parse/parser-utilities.mjs +2 -0
- package/lib/mjs/parse/parser-utilities.mjs.map +1 -0
- package/lib/mjs/parse/safe-parse.mjs +2 -0
- package/lib/mjs/parse/safe-parse.mjs.map +1 -0
- package/lib/mjs/parse/validation/validate-context.mjs +2 -0
- package/lib/mjs/parse/validation/validate-context.mjs.map +1 -0
- package/lib/mjs/parse/validation/validators/arguments.mjs +2 -0
- package/lib/mjs/parse/validation/validators/arguments.mjs.map +1 -0
- package/lib/mjs/parse/validation/validators/conflict.mjs +2 -0
- package/lib/mjs/parse/validation/validators/conflict.mjs.map +1 -0
- package/lib/mjs/parse/validation/validators/exclusive.mjs +2 -0
- package/lib/mjs/parse/validation/validators/exclusive.mjs.map +1 -0
- package/lib/mjs/parse/validation/validators/explicitly-passed.mjs +2 -0
- package/lib/mjs/parse/validation/validators/explicitly-passed.mjs.map +1 -0
- package/lib/mjs/parse/validation/validators/options.mjs +2 -0
- package/lib/mjs/parse/validation/validators/options.mjs.map +1 -0
- package/lib/mjs/parse/validation/validators/requires.mjs +2 -0
- package/lib/mjs/parse/validation/validators/requires.mjs.map +1 -0
- package/lib/mjs/utilities.mjs +2 -0
- package/lib/mjs/utilities.mjs.map +1 -0
- package/lib/typescript/autocomplete-scripts/bash-autocomplete-script.d.ts +2 -2
- package/lib/typescript/autocomplete-scripts/bash-autocomplete-script.d.ts.map +1 -1
- package/lib/typescript/autocomplete-scripts/powershell-autocomplete-script.d.ts +2 -2
- package/lib/typescript/autocomplete-scripts/powershell-autocomplete-script.d.ts.map +1 -1
- package/lib/typescript/autocomplete-scripts/zsh-autocomplete-script.d.ts +2 -2
- package/lib/typescript/autocomplete-scripts/zsh-autocomplete-script.d.ts.map +1 -1
- package/lib/typescript/coerce/coerce-methods.d.ts +20 -0
- package/lib/typescript/coerce/coerce-methods.d.ts.map +1 -0
- package/lib/typescript/coerce/string-to-array.d.ts +6 -0
- package/lib/typescript/coerce/string-to-array.d.ts.map +1 -0
- package/lib/typescript/coerce/string-to-primitive.d.ts +5 -0
- package/lib/typescript/coerce/string-to-primitive.d.ts.map +1 -0
- package/lib/typescript/coerce/string-to-set.d.ts +6 -0
- package/lib/typescript/coerce/string-to-set.d.ts.map +1 -0
- package/lib/typescript/definitions/define-arguments.d.ts +7 -0
- package/lib/typescript/definitions/define-arguments.d.ts.map +1 -0
- package/lib/typescript/definitions/define-cli.d.ts +24 -0
- package/lib/typescript/definitions/define-cli.d.ts.map +1 -0
- package/lib/typescript/definitions/define-options.d.ts +7 -0
- package/lib/typescript/definitions/define-options.d.ts.map +1 -0
- package/lib/typescript/definitions/define-subcommand.d.ts +17 -0
- package/lib/typescript/definitions/define-subcommand.d.ts.map +1 -0
- package/lib/typescript/definitions/validate-cli-definition.d.ts +4 -0
- package/lib/typescript/definitions/validate-cli-definition.d.ts.map +1 -0
- package/lib/typescript/help-message/format-arguments.d.ts +3 -3
- package/lib/typescript/help-message/format-arguments.d.ts.map +1 -1
- package/lib/typescript/help-message/format-options.d.ts +3 -3
- package/lib/typescript/help-message/format-options.d.ts.map +1 -1
- package/lib/typescript/help-message/format-subcommands.d.ts +3 -3
- package/lib/typescript/help-message/format-subcommands.d.ts.map +1 -1
- package/lib/typescript/help-message/generate-for-cli.d.ts +8 -0
- package/lib/typescript/help-message/generate-for-cli.d.ts.map +1 -0
- package/lib/typescript/help-message/generate-for-subcommand.d.ts +4 -0
- package/lib/typescript/help-message/generate-for-subcommand.d.ts.map +1 -0
- package/lib/typescript/help-message/print-help.d.ts +5 -0
- package/lib/typescript/help-message/print-help.d.ts.map +1 -0
- package/lib/typescript/help-message/set-defaults.d.ts +4 -0
- package/lib/typescript/help-message/set-defaults.d.ts.map +1 -0
- package/lib/typescript/help-message/styles.d.ts +30 -106
- package/lib/typescript/help-message/styles.d.ts.map +1 -1
- package/lib/typescript/help-message/terminal-markdown.d.ts +3 -0
- package/lib/typescript/help-message/terminal-markdown.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +23 -35
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/markdown/generate-markdown.d.ts +2 -2
- package/lib/typescript/markdown/generate-markdown.d.ts.map +1 -1
- package/lib/typescript/metadata/arguments-metadata.d.ts +4 -0
- package/lib/typescript/metadata/arguments-metadata.d.ts.map +1 -0
- package/lib/typescript/metadata/cli-metadata.d.ts +4 -0
- package/lib/typescript/metadata/cli-metadata.d.ts.map +1 -0
- package/lib/typescript/metadata/options-metadata.d.ts +4 -0
- package/lib/typescript/metadata/options-metadata.d.ts.map +1 -0
- package/lib/typescript/metadata/subcommands-metadata.d.ts +4 -0
- package/lib/typescript/metadata/subcommands-metadata.d.ts.map +1 -0
- package/lib/typescript/parse/context/cli-context-builder.d.ts +9 -0
- package/lib/typescript/parse/context/cli-context-builder.d.ts.map +1 -0
- package/lib/typescript/parse/context/object-context-builder.d.ts +6 -0
- package/lib/typescript/parse/context/object-context-builder.d.ts.map +1 -0
- package/lib/typescript/{parser/parse/parser-helpers.d.ts → parse/parser-utilities.d.ts} +18 -9
- package/lib/typescript/parse/parser-utilities.d.ts.map +1 -0
- package/lib/typescript/parse/safe-parse.d.ts +5 -0
- package/lib/typescript/parse/safe-parse.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validate-context.d.ts +6 -0
- package/lib/typescript/parse/validation/validate-context.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validators/arguments.d.ts +12 -0
- package/lib/typescript/parse/validation/validators/arguments.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validators/conflict.d.ts +16 -0
- package/lib/typescript/parse/validation/validators/conflict.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validators/exclusive.d.ts +16 -0
- package/lib/typescript/parse/validation/validators/exclusive.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validators/explicitly-passed.d.ts +5 -0
- package/lib/typescript/parse/validation/validators/explicitly-passed.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validators/options.d.ts +12 -0
- package/lib/typescript/parse/validation/validators/options.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validators/requires.d.ts +18 -0
- package/lib/typescript/parse/validation/validators/requires.d.ts.map +1 -0
- package/lib/typescript/types/context-types.d.ts +135 -0
- package/lib/typescript/types/context-types.d.ts.map +1 -0
- package/lib/typescript/types/definitions-types.d.ts +294 -0
- package/lib/typescript/types/definitions-types.d.ts.map +1 -0
- package/lib/typescript/types/help-message-types.d.ts +134 -0
- package/lib/typescript/types/help-message-types.d.ts.map +1 -0
- package/lib/typescript/types/io-types.d.ts +96 -0
- package/lib/typescript/types/io-types.d.ts.map +1 -0
- package/lib/typescript/types/metadata-types.d.ts +75 -0
- package/lib/typescript/types/metadata-types.d.ts.map +1 -0
- package/lib/typescript/types/schema-types.d.ts +6 -0
- package/lib/typescript/types/schema-types.d.ts.map +1 -0
- package/lib/typescript/types/types.d.ts +61 -0
- package/lib/typescript/types/types.d.ts.map +1 -0
- package/lib/typescript/types/utilities-types.d.ts +17 -0
- package/lib/typescript/types/utilities-types.d.ts.map +1 -0
- package/lib/typescript/utilities.d.ts +24 -10
- package/lib/typescript/utilities.d.ts.map +1 -1
- package/package.json +29 -26
- package/src/autocomplete-scripts/bash-autocomplete-script.ts +13 -9
- package/src/autocomplete-scripts/powershell-autocomplete-script.ts +21 -13
- package/src/autocomplete-scripts/zsh-autocomplete-script.ts +27 -23
- package/src/coerce/coerce-methods.ts +75 -0
- package/src/coerce/string-to-array.ts +18 -0
- package/src/coerce/string-to-primitive.ts +31 -0
- package/src/coerce/string-to-set.ts +15 -0
- package/src/definitions/define-arguments.ts +10 -0
- package/src/definitions/define-cli.ts +105 -0
- package/src/definitions/define-options.ts +12 -0
- package/src/definitions/define-subcommand.ts +57 -0
- package/src/definitions/validate-cli-definition.ts +331 -0
- package/src/help-message/format-arguments.ts +57 -33
- package/src/help-message/format-options.ts +59 -34
- package/src/help-message/format-subcommands.ts +43 -21
- package/src/help-message/generate-for-cli.ts +114 -0
- package/src/help-message/generate-for-subcommand.ts +32 -0
- package/src/help-message/print-help.ts +13 -0
- package/src/help-message/set-defaults.ts +34 -0
- package/src/help-message/styles.ts +148 -103
- package/src/help-message/terminal-markdown.ts +147 -0
- package/src/index.ts +28 -97
- package/src/markdown/generate-markdown.ts +47 -58
- package/src/metadata/arguments-metadata.ts +28 -0
- package/src/metadata/cli-metadata.ts +26 -0
- package/src/metadata/options-metadata.ts +38 -0
- package/src/metadata/subcommands-metadata.ts +35 -0
- package/src/parse/context/cli-context-builder.ts +246 -0
- package/src/parse/context/object-context-builder.ts +63 -0
- package/src/{parser/parse/parser-helpers.ts → parse/parser-utilities.ts} +46 -25
- package/src/parse/safe-parse.ts +76 -0
- package/src/parse/validation/validate-context.ts +23 -0
- package/src/parse/validation/validators/arguments.ts +59 -0
- package/src/parse/validation/validators/conflict.ts +68 -0
- package/src/parse/validation/validators/exclusive.ts +70 -0
- package/src/parse/validation/validators/explicitly-passed.ts +15 -0
- package/src/parse/validation/validators/options.ts +59 -0
- package/src/parse/validation/validators/requires.ts +82 -0
- package/src/types/context-types.ts +171 -0
- package/src/types/definitions-types.ts +340 -0
- package/src/types/help-message-types.ts +153 -0
- package/src/types/io-types.ts +131 -0
- package/src/types/metadata-types.ts +104 -0
- package/src/types/schema-types.ts +9 -0
- package/src/types/types.ts +72 -0
- package/src/types/utilities-types.ts +26 -0
- package/src/utilities.ts +200 -23
- package/lib/commonjs/autocomplete-scripts/bash-autocomplete-script.cjs +0 -42
- package/lib/commonjs/autocomplete-scripts/bash-autocomplete-script.cjs.map +0 -1
- package/lib/commonjs/autocomplete-scripts/powershell-autocomplete-script.cjs +0 -31
- package/lib/commonjs/autocomplete-scripts/powershell-autocomplete-script.cjs.map +0 -1
- package/lib/commonjs/autocomplete-scripts/zsh-autocomplete-script.cjs +0 -41
- package/lib/commonjs/autocomplete-scripts/zsh-autocomplete-script.cjs.map +0 -1
- package/lib/commonjs/help-message/format-arguments.cjs +0 -1
- package/lib/commonjs/help-message/format-arguments.cjs.map +0 -1
- package/lib/commonjs/help-message/format-cli.cjs +0 -1
- package/lib/commonjs/help-message/format-cli.cjs.map +0 -1
- package/lib/commonjs/help-message/format-options.cjs +0 -1
- package/lib/commonjs/help-message/format-options.cjs.map +0 -1
- package/lib/commonjs/help-message/format-subcommands.cjs +0 -1
- package/lib/commonjs/help-message/format-subcommands.cjs.map +0 -1
- package/lib/commonjs/help-message/styles.cjs +0 -1
- package/lib/commonjs/help-message/styles.cjs.map +0 -1
- package/lib/commonjs/index.cjs +0 -1
- package/lib/commonjs/index.cjs.map +0 -1
- package/lib/commonjs/markdown/generate-markdown.cjs +0 -1
- package/lib/commonjs/markdown/generate-markdown.cjs.map +0 -1
- package/lib/commonjs/metadata/get-arguments-metadata.cjs +0 -1
- package/lib/commonjs/metadata/get-arguments-metadata.cjs.map +0 -1
- package/lib/commonjs/metadata/get-cli-metadata.cjs +0 -1
- package/lib/commonjs/metadata/get-cli-metadata.cjs.map +0 -1
- package/lib/commonjs/metadata/get-options-metadata.cjs +0 -1
- package/lib/commonjs/metadata/get-options-metadata.cjs.map +0 -1
- package/lib/commonjs/metadata/get-subcommands-metadata.cjs +0 -1
- package/lib/commonjs/metadata/get-subcommands-metadata.cjs.map +0 -1
- package/lib/commonjs/parser/parse/parse.cjs +0 -1
- package/lib/commonjs/parser/parse/parse.cjs.map +0 -1
- package/lib/commonjs/parser/parse/parser-helpers.cjs +0 -1
- package/lib/commonjs/parser/parse/parser-helpers.cjs.map +0 -1
- package/lib/commonjs/parser/safe-parse.cjs +0 -1
- package/lib/commonjs/parser/safe-parse.cjs.map +0 -1
- package/lib/commonjs/parser/unsafe-parse.cjs +0 -1
- package/lib/commonjs/parser/unsafe-parse.cjs.map +0 -1
- package/lib/commonjs/parser/validate/validate-type.cjs +0 -1
- package/lib/commonjs/parser/validate/validate-type.cjs.map +0 -1
- package/lib/commonjs/parser/validate/validate.cjs +0 -1
- package/lib/commonjs/parser/validate/validate.cjs.map +0 -1
- package/lib/commonjs/utilities.cjs +0 -1
- package/lib/commonjs/utilities.cjs.map +0 -1
- package/lib/commonjs/zod-utilities.cjs +0 -1
- package/lib/commonjs/zod-utilities.cjs.map +0 -1
- package/lib/module/autocomplete-scripts/bash-autocomplete-script.mjs +0 -42
- package/lib/module/autocomplete-scripts/bash-autocomplete-script.mjs.map +0 -1
- package/lib/module/autocomplete-scripts/powershell-autocomplete-script.mjs +0 -31
- package/lib/module/autocomplete-scripts/powershell-autocomplete-script.mjs.map +0 -1
- package/lib/module/autocomplete-scripts/zsh-autocomplete-script.mjs +0 -41
- package/lib/module/autocomplete-scripts/zsh-autocomplete-script.mjs.map +0 -1
- package/lib/module/help-message/format-arguments.mjs +0 -1
- package/lib/module/help-message/format-arguments.mjs.map +0 -1
- package/lib/module/help-message/format-cli.mjs +0 -1
- package/lib/module/help-message/format-cli.mjs.map +0 -1
- package/lib/module/help-message/format-options.mjs +0 -1
- package/lib/module/help-message/format-options.mjs.map +0 -1
- package/lib/module/help-message/format-subcommands.mjs +0 -1
- package/lib/module/help-message/format-subcommands.mjs.map +0 -1
- package/lib/module/help-message/styles.mjs +0 -1
- package/lib/module/help-message/styles.mjs.map +0 -1
- package/lib/module/index.mjs +0 -1
- package/lib/module/index.mjs.map +0 -1
- package/lib/module/markdown/generate-markdown.mjs +0 -1
- package/lib/module/markdown/generate-markdown.mjs.map +0 -1
- package/lib/module/metadata/get-arguments-metadata.mjs +0 -1
- package/lib/module/metadata/get-arguments-metadata.mjs.map +0 -1
- package/lib/module/metadata/get-cli-metadata.mjs +0 -1
- package/lib/module/metadata/get-cli-metadata.mjs.map +0 -1
- package/lib/module/metadata/get-options-metadata.mjs +0 -1
- package/lib/module/metadata/get-options-metadata.mjs.map +0 -1
- package/lib/module/metadata/get-subcommands-metadata.mjs +0 -1
- package/lib/module/metadata/get-subcommands-metadata.mjs.map +0 -1
- package/lib/module/parser/parse/parse.mjs +0 -1
- package/lib/module/parser/parse/parse.mjs.map +0 -1
- package/lib/module/parser/parse/parser-helpers.mjs +0 -1
- package/lib/module/parser/parse/parser-helpers.mjs.map +0 -1
- package/lib/module/parser/safe-parse.mjs +0 -1
- package/lib/module/parser/safe-parse.mjs.map +0 -1
- package/lib/module/parser/unsafe-parse.mjs +0 -1
- package/lib/module/parser/unsafe-parse.mjs.map +0 -1
- package/lib/module/parser/validate/validate-type.mjs +0 -1
- package/lib/module/parser/validate/validate-type.mjs.map +0 -1
- package/lib/module/parser/validate/validate.mjs +0 -1
- package/lib/module/parser/validate/validate.mjs.map +0 -1
- package/lib/module/utilities.mjs +0 -1
- package/lib/module/utilities.mjs.map +0 -1
- package/lib/module/zod-utilities.mjs +0 -1
- package/lib/module/zod-utilities.mjs.map +0 -1
- package/lib/typescript/help-message/format-cli.d.ts +0 -6
- package/lib/typescript/help-message/format-cli.d.ts.map +0 -1
- package/lib/typescript/metadata/get-arguments-metadata.d.ts +0 -4
- package/lib/typescript/metadata/get-arguments-metadata.d.ts.map +0 -1
- package/lib/typescript/metadata/get-cli-metadata.d.ts +0 -4
- package/lib/typescript/metadata/get-cli-metadata.d.ts.map +0 -1
- package/lib/typescript/metadata/get-options-metadata.d.ts +0 -4
- package/lib/typescript/metadata/get-options-metadata.d.ts.map +0 -1
- package/lib/typescript/metadata/get-subcommands-metadata.d.ts +0 -4
- package/lib/typescript/metadata/get-subcommands-metadata.d.ts.map +0 -1
- package/lib/typescript/metadata/metadata-types.d.ts +0 -80
- package/lib/typescript/metadata/metadata-types.d.ts.map +0 -1
- package/lib/typescript/parser/parse/parse-types.d.ts +0 -85
- package/lib/typescript/parser/parse/parse-types.d.ts.map +0 -1
- package/lib/typescript/parser/parse/parse.d.ts +0 -4
- package/lib/typescript/parser/parse/parse.d.ts.map +0 -1
- package/lib/typescript/parser/parse/parser-helpers.d.ts.map +0 -1
- package/lib/typescript/parser/safe-parse.d.ts +0 -4
- package/lib/typescript/parser/safe-parse.d.ts.map +0 -1
- package/lib/typescript/parser/unsafe-parse.d.ts +0 -4
- package/lib/typescript/parser/unsafe-parse.d.ts.map +0 -1
- package/lib/typescript/parser/validate/validate-type.d.ts +0 -22
- package/lib/typescript/parser/validate/validate-type.d.ts.map +0 -1
- package/lib/typescript/parser/validate/validate.d.ts +0 -11
- package/lib/typescript/parser/validate/validate.d.ts.map +0 -1
- package/lib/typescript/types.d.ts +0 -294
- package/lib/typescript/types.d.ts.map +0 -1
- package/lib/typescript/zod-utilities.d.ts +0 -28
- package/lib/typescript/zod-utilities.d.ts.map +0 -1
- package/src/help-message/format-cli.ts +0 -141
- package/src/metadata/get-arguments-metadata.ts +0 -25
- package/src/metadata/get-cli-metadata.ts +0 -23
- package/src/metadata/get-options-metadata.ts +0 -35
- package/src/metadata/get-subcommands-metadata.ts +0 -32
- package/src/metadata/metadata-types.ts +0 -114
- package/src/parser/parse/parse-types.ts +0 -89
- package/src/parser/parse/parse.ts +0 -230
- package/src/parser/safe-parse.ts +0 -103
- package/src/parser/unsafe-parse.ts +0 -98
- package/src/parser/validate/validate-type.ts +0 -21
- package/src/parser/validate/validate.ts +0 -66
- package/src/types.ts +0 -365
- package/src/zod-utilities.ts +0 -214
package/README.md
CHANGED
|
@@ -4,768 +4,705 @@
|
|
|
4
4
|
[](https://github.com/alabsi91/zod-args-parser/blob/main/LICENSE)
|
|
5
5
|
[](https://github.com/alabsi91/zod-args-parser/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc)
|
|
6
6
|
|
|
7
|
-
A strictly typed command-line arguments parser powered by
|
|
7
|
+
A strictly typed command-line arguments parser powered by schema validation.
|
|
8
8
|
|
|
9
9
|
## Table of Contents
|
|
10
10
|
|
|
11
11
|
- [Features](#features)
|
|
12
12
|
- [Installation](#installation)
|
|
13
13
|
- [Usage](#usage)
|
|
14
|
+
- [Example](#example)
|
|
14
15
|
- [Guide](#guide)
|
|
15
|
-
- [
|
|
16
|
-
- [
|
|
17
|
-
- [
|
|
18
|
-
- [
|
|
19
|
-
- [
|
|
20
|
-
- [
|
|
21
|
-
- [
|
|
22
|
-
- [
|
|
23
|
-
- [
|
|
16
|
+
- [Creating a subcommand](#creating-a-subcommand)
|
|
17
|
+
- [Creating options](#creating-options)
|
|
18
|
+
- [Creating typed arguments](#creating-typed-arguments)
|
|
19
|
+
- [Using Schemas](#using-schemas)
|
|
20
|
+
- [Default Values and Optional Inputs](#default-values-and-optional-inputs)
|
|
21
|
+
- [Positionals vs Typed Arguments](#positionals-vs-typed-arguments)
|
|
22
|
+
- [Option and Argument Constraints](#option-and-argument-constraints)
|
|
23
|
+
- [Negating a boolean option](#negating-a-boolean-option)
|
|
24
|
+
- [Creating a Custom Help Message Style](#creating-a-custom-help-message-style)
|
|
25
|
+
- [Help Message as HTML](#help-message-as-html)
|
|
24
26
|
- [API Reference](#api-reference)
|
|
25
|
-
- [
|
|
26
|
-
- [
|
|
27
|
-
- [
|
|
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)
|
|
28
38
|
- [License](#license)
|
|
29
39
|
|
|
30
40
|
## Features
|
|
31
41
|
|
|
32
|
-
- **
|
|
33
|
-
- **
|
|
34
|
-
- **
|
|
35
|
-
- **
|
|
36
|
-
- **
|
|
37
|
-
- **
|
|
38
|
-
- **
|
|
42
|
+
- **Strictly typed & validated**: Fully TypeScript-typed CLI arguments, backed by schema validation.
|
|
43
|
+
- **Flexible option syntax**: Supports both `--option value` and `--option=value`.
|
|
44
|
+
- **Boolean flags**: Handles negation (`--no-verbose`) and short flag coupling (`-rf`).
|
|
45
|
+
- **Typed subcommands**: Define subcommands with their own typed options and arguments.
|
|
46
|
+
- **Automatic help & docs**: Generate user-friendly CLI help messages and Markdown documentation.
|
|
47
|
+
- **Shell autocompletion**: Auto-generate scripts for Bash, Zsh, and PowerShell.
|
|
48
|
+
- **Schema-agnostic**: Works with any validation library supporting [`StandardSchemaV1`](https://github.com/standard-schema/standard-schema) and default/optional primitives.
|
|
49
|
+
- **Cross-platform**: Fully supports Node.js, Bun, Deno, and modern browsers.
|
|
39
50
|
|
|
40
51
|
## Installation
|
|
41
52
|
|
|
42
53
|
> [!IMPORTANT]
|
|
43
|
-
>
|
|
54
|
+
> A validation library is required that supports [`StandardSchemaV1`](https://github.com/standard-schema/standard-schema) and allows primitive types to be optional or have default values.
|
|
44
55
|
|
|
45
56
|
```bash
|
|
46
|
-
npm install zod
|
|
57
|
+
npm install zod zod-args-parser
|
|
47
58
|
```
|
|
48
59
|
|
|
49
60
|
## Usage
|
|
50
61
|
|
|
62
|
+
The following example uses `zod` as the validation library, but you can use any library that supports [`StandardSchemaV1`](https://github.com/standard-schema/standard-schema), as long as it allows primitive types to be optional or have default values.
|
|
63
|
+
|
|
51
64
|
```ts
|
|
52
65
|
import * as z from "zod";
|
|
53
|
-
import {
|
|
54
|
-
|
|
55
|
-
// Share options between schemas.
|
|
56
|
-
const sharedOptions = createOptions([
|
|
57
|
-
{
|
|
58
|
-
name: "verbose",
|
|
59
|
-
description: "Verbose mode",
|
|
60
|
-
type: z.boolean().optional(),
|
|
61
|
-
},
|
|
62
|
-
]);
|
|
63
|
-
|
|
64
|
-
// Create the CLI program schema
|
|
65
|
-
// This will be used when no subcommands are run
|
|
66
|
-
const cliSchema = createCli({
|
|
67
|
-
cliName: "my-cli",
|
|
68
|
-
description: "A description for my CLI",
|
|
69
|
-
example: "example of how to use my cli\nmy-cli --help",
|
|
70
|
-
options: [
|
|
71
|
-
{
|
|
72
|
-
name: "help",
|
|
73
|
-
aliases: ["h"],
|
|
74
|
-
type: z.boolean().optional().describe("Show this help message"),
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
name: "version",
|
|
78
|
-
aliases: ["v"],
|
|
79
|
-
description: "Show version",
|
|
80
|
-
type: z.boolean().optional(),
|
|
81
|
-
},
|
|
82
|
-
...sharedOptions,
|
|
83
|
-
],
|
|
84
|
-
});
|
|
66
|
+
import { defineCLI, coerce } from "zod-args-parser";
|
|
85
67
|
|
|
86
|
-
//
|
|
87
|
-
|
|
88
|
-
|
|
68
|
+
// Define the CLI program (main command)
|
|
69
|
+
const listyCLI = defineCLI({
|
|
70
|
+
cliName: "listy",
|
|
89
71
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
72
|
+
subcommands: [
|
|
73
|
+
// ...
|
|
74
|
+
],
|
|
94
75
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
76
|
+
options: {
|
|
77
|
+
help: {
|
|
78
|
+
schema: z.boolean().optional(),
|
|
79
|
+
coerce: coerce.boolean,
|
|
80
|
+
},
|
|
81
|
+
},
|
|
99
82
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
83
|
+
arguments: {
|
|
84
|
+
// ...
|
|
85
|
+
},
|
|
103
86
|
});
|
|
104
87
|
|
|
105
|
-
//
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
placeholder: "<command>",
|
|
109
|
-
description: "Print help message for command",
|
|
110
|
-
arguments: [
|
|
111
|
-
{
|
|
112
|
-
name: "command",
|
|
113
|
-
description: "Command to print help for",
|
|
114
|
-
type: z.enum(["build", "help", "init"]).optional(),
|
|
115
|
-
},
|
|
116
|
-
],
|
|
117
|
-
});
|
|
88
|
+
// When the CLI (main command) is executed
|
|
89
|
+
listyCLI.onExecute(results => {
|
|
90
|
+
const { help } = results.options;
|
|
118
91
|
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (command) {
|
|
123
|
-
results.printSubcommandHelp(command);
|
|
92
|
+
// print help for the CLI
|
|
93
|
+
if (help && listyCLI.generateCliHelpMessage) {
|
|
94
|
+
console.log(listyCLI.generateCliHelpMessage());
|
|
124
95
|
return;
|
|
125
96
|
}
|
|
126
97
|
|
|
127
|
-
|
|
98
|
+
console.error("Please try `listy --help`");
|
|
128
99
|
});
|
|
129
100
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const results = safeParse(process.argv.slice(2), ...schemas);
|
|
101
|
+
// Run the CLI and pass in the command line arguments
|
|
102
|
+
const results = listyCLI.run(process.argv.slice(2));
|
|
133
103
|
|
|
134
|
-
//
|
|
135
|
-
if (
|
|
104
|
+
// Inspect parsed results
|
|
105
|
+
if (results.error) {
|
|
136
106
|
console.error(results.error.message);
|
|
137
|
-
console.log("\n`
|
|
138
|
-
process.exit(1);
|
|
107
|
+
console.log("\n`listy --help` for more information");
|
|
139
108
|
}
|
|
140
109
|
```
|
|
141
110
|
|
|
111
|
+
## Example
|
|
112
|
+
|
|
113
|
+
- [Listy CLI Example](https://github.com/alabsi91/zod-args-parser/tree/main/example)
|
|
114
|
+
|
|
142
115
|
## Guide
|
|
143
116
|
|
|
144
|
-
###
|
|
117
|
+
### Creating a subcommand
|
|
145
118
|
|
|
146
|
-
|
|
147
|
-
- The following properties are optional and used only for **metadata** such as help messages and documentation:
|
|
148
|
-
- `description`
|
|
149
|
-
- `usage`
|
|
150
|
-
- `example`
|
|
151
|
-
- `placeholder`
|
|
152
|
-
- Do not reuse the same subcommand name within the same CLI. TypeScript will throw a type error if a duplicate exist.
|
|
119
|
+
Subcommands are defined using the `defineSubcommand` function, which accepts a [`Subcommand`](#subcommand) definition object.
|
|
153
120
|
|
|
154
121
|
```ts
|
|
155
|
-
import {
|
|
156
|
-
|
|
157
|
-
const subcommand = createSubcommand({
|
|
158
|
-
name: "subcommand",
|
|
159
|
-
description: "Description for the subcommand",
|
|
160
|
-
usage: "my-cli subcommand [options] [arguments]",
|
|
161
|
-
example: "subcommand --help",
|
|
162
|
-
placeholder: "[options] [arguments]",
|
|
163
|
-
allowPositional: false, // default: false
|
|
164
|
-
options: [
|
|
165
|
-
/* options */
|
|
166
|
-
],
|
|
167
|
-
arguments: [
|
|
168
|
-
/* arguments */
|
|
169
|
-
],
|
|
170
|
-
});
|
|
122
|
+
import { defineSubcommand, helpMessageStyles } from "zod-args-parser";
|
|
171
123
|
|
|
172
|
-
|
|
173
|
-
subcommand.setPreValidationHook(ctx => {
|
|
174
|
-
// ...
|
|
175
|
-
});
|
|
124
|
+
import type { InferInputType, InferOutputType } from "zod-args-parser";
|
|
176
125
|
|
|
177
|
-
|
|
178
|
-
subcommand
|
|
179
|
-
|
|
180
|
-
});
|
|
181
|
-
```
|
|
126
|
+
const createListCommand = defineSubcommand({
|
|
127
|
+
// The name used to call this subcommand from the CLI
|
|
128
|
+
name: "add",
|
|
182
129
|
|
|
183
|
-
|
|
130
|
+
// Additional names that can be used to run the same subcommand
|
|
131
|
+
aliases: ["cl", "create"],
|
|
184
132
|
|
|
185
|
-
|
|
186
|
-
|
|
133
|
+
// When true: positional (untyped) arguments are allowed and parsed as string[]
|
|
134
|
+
// When typed arguments exist: they are parsed first, and leftover arguments become `positionals`
|
|
135
|
+
allowPositionals: false,
|
|
187
136
|
|
|
188
|
-
|
|
189
|
-
|
|
137
|
+
// Extra information used for CLI help output and generated documentation
|
|
138
|
+
meta: {
|
|
139
|
+
// Shown in the terminal when displaying the help text for this subcommand
|
|
140
|
+
// Ignored in Markdown docs
|
|
141
|
+
usage: "listy add --list <list> --items <items> --tags <tags>",
|
|
190
142
|
|
|
191
|
-
|
|
192
|
-
|
|
143
|
+
// Shown in terminal help alongside the subcommand name
|
|
144
|
+
// Also shown in Markdown docs next to the subcommand name
|
|
145
|
+
placeholder: "<list> <items> <tags>",
|
|
193
146
|
|
|
194
|
-
//
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
z.string().default("hello"); // optional -> string
|
|
147
|
+
// Shown in terminal help if both description and descriptionMarkdown exist
|
|
148
|
+
// Not preferred in Markdown docs
|
|
149
|
+
description: "Plain text description shown in terminal help when both formats are provided.",
|
|
198
150
|
|
|
199
|
-
//
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
z.boolean().default(true); // optional -> boolean
|
|
151
|
+
// Used as-is in Markdown docs and preferred over `description`
|
|
152
|
+
// When printed in the terminal, it will be parsed by `marked` and formatted for the terminal output
|
|
153
|
+
descriptionMarkdown: "**Formatted** for terminal and preferred when generating **Markdown documentation**.",
|
|
203
154
|
|
|
204
|
-
//
|
|
205
|
-
|
|
206
|
-
|
|
155
|
+
// Displayed at the bottom of terminal help
|
|
156
|
+
// In Markdown docs, it is output inside a code block
|
|
157
|
+
example:
|
|
158
|
+
"listy add --list groceries --items egg,milk,bread --tags food\n" +
|
|
159
|
+
"listy add --list todos --items clean,cook --tags chores|work",
|
|
207
160
|
|
|
208
|
-
//
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
});
|
|
161
|
+
// If true, this subcommand is hidden from both help output and documentation
|
|
162
|
+
// Useful for internal commands
|
|
163
|
+
hidden: false,
|
|
164
|
+
},
|
|
213
165
|
|
|
214
|
-
//
|
|
215
|
-
|
|
166
|
+
// Available CLI options for this subcommand
|
|
167
|
+
options: {
|
|
168
|
+
// ...
|
|
169
|
+
},
|
|
216
170
|
|
|
217
|
-
//
|
|
218
|
-
|
|
171
|
+
// Typed command-line arguments for this subcommand
|
|
172
|
+
arguments: {
|
|
173
|
+
// ...
|
|
174
|
+
},
|
|
175
|
+
});
|
|
219
176
|
|
|
220
|
-
//
|
|
221
|
-
|
|
177
|
+
// Runs when the subcommand is executed
|
|
178
|
+
// Multiple handlers can be attached if needed
|
|
179
|
+
const unsubscribe = createListCommand.onExecute(results => {
|
|
180
|
+
const { ...options } = results.options;
|
|
181
|
+
const { ...args } = results.arguments;
|
|
182
|
+
const positionals = results.positionals;
|
|
183
|
+
|
|
184
|
+
// Inspect parsed results in detail
|
|
185
|
+
console.log(results.context.options);
|
|
186
|
+
|
|
187
|
+
// Print help for this subcommand
|
|
188
|
+
if (createListCommand.generateSubcommandHelpMessage) {
|
|
189
|
+
console.log(
|
|
190
|
+
createListCommand.generateSubcommandHelpMessage(results.subcommand, { style: helpMessageStyles.default }),
|
|
191
|
+
);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
222
194
|
|
|
223
|
-
//
|
|
224
|
-
|
|
195
|
+
// Print help for the CLI
|
|
196
|
+
if (listyCLI.generateCliHelpMessage) {
|
|
197
|
+
console.log(listyCLI.generateCliHelpMessage({ style: helpMessageStyles.default }));
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
225
201
|
|
|
226
|
-
//
|
|
227
|
-
|
|
228
|
-
(value: string) => stringToArray(value, ";"), // second arg is the separator (default: ",")
|
|
229
|
-
z.tuple([z.string(), z.coerce.number(), z.coerce.boolean()]),
|
|
230
|
-
);
|
|
202
|
+
// Programmatic API for executing this subcommand
|
|
203
|
+
export const executeCreateListCommand = createListCommand.execute;
|
|
231
204
|
|
|
232
|
-
//
|
|
233
|
-
|
|
205
|
+
// Useful inferred types for input/output payloads
|
|
206
|
+
type CreateListInput = InferInputType<typeof createListCommand>;
|
|
207
|
+
type CreateListOutput = InferOutputType<typeof createListCommand>;
|
|
234
208
|
```
|
|
235
209
|
|
|
236
|
-
###
|
|
210
|
+
### Creating options
|
|
237
211
|
|
|
238
|
-
|
|
239
|
-
- **Supports:** `camelCase`, `PascalCase`, `snake_case`, and `SCREAMING_SNAKE_CASE`.
|
|
240
|
-
- **Examples:**
|
|
241
|
-
- `I` or `i` ➡️ `-i`
|
|
242
|
-
- `InputDir`, `inputDir`, or `INPUT_DIR` ➡️ `--input-dir`
|
|
243
|
-
- `Help`, `help`, or `HELP` ➡️ `--help`
|
|
244
|
-
- Do not use same options/aliases name with different casing.
|
|
245
|
-
- Do not reuse the option/alias name within the same CLI/subcommand. TypeScript will throw a type error if duplicates exist.
|
|
246
|
-
- The following properties are optional and used only for **metadata** such as help messages and documentation:
|
|
247
|
-
- `description`
|
|
248
|
-
- `example`
|
|
249
|
-
- `placeholder`
|
|
212
|
+
Options can be defined directly inside the CLI or subcommand definition. Or using the `defineOptions` function.
|
|
250
213
|
|
|
251
|
-
|
|
214
|
+
Option names can use any common case style:
|
|
215
|
+
`camelCase`, `PascalCase`, `snake_case`, or `SCREAMING_SNAKE_CASE`.
|
|
216
|
+
|
|
217
|
+
- ListName `=>` --list-name
|
|
218
|
+
- list-name `=>` --list-name
|
|
219
|
+
- listName `=>` --list-name
|
|
220
|
+
- LIST_NAME `=>` --list-name
|
|
252
221
|
|
|
253
222
|
```ts
|
|
254
|
-
import
|
|
255
|
-
import { createCli } from "zod-args-parser";
|
|
256
|
-
|
|
257
|
-
// Define the CLI schema
|
|
258
|
-
const cliSchema = createCli({
|
|
259
|
-
cliName: "my-cli",
|
|
260
|
-
options: [
|
|
261
|
-
{
|
|
262
|
-
name: "inputDir", // camelCase option name becomes `--input-dir`
|
|
263
|
-
aliases: ["i"], // single-letter alias becomes `-i`
|
|
264
|
-
type: z.boolean().default(false), // optional because of default
|
|
265
|
-
description: "Input directory",
|
|
266
|
-
placeholder: "<dir>",
|
|
267
|
-
example: "-i /path/to/dir",
|
|
268
|
-
},
|
|
269
|
-
{
|
|
270
|
-
name: "verbose", // another option
|
|
271
|
-
aliases: ["v"], // alias `-v`
|
|
272
|
-
type: z.boolean().optional().describe("Enable verbose mode"), // using describe() instead of description
|
|
273
|
-
},
|
|
274
|
-
],
|
|
275
|
-
});
|
|
223
|
+
import { defineSubcommand, coerce } from "zod-args-parser";
|
|
276
224
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
const { inputDir, verbose } = results.options;
|
|
225
|
+
const createListCommand = defineSubcommand({
|
|
226
|
+
// ...
|
|
280
227
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
228
|
+
options: {
|
|
229
|
+
// The key is the option name
|
|
230
|
+
listName: {
|
|
231
|
+
// Aliases generate equivalent flags (e.g. -n, --name)
|
|
232
|
+
aliases: ["list", "name", "n"],
|
|
285
233
|
|
|
286
|
-
|
|
234
|
+
// Required string for this option
|
|
235
|
+
schema: z.string(),
|
|
287
236
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
- `description`
|
|
292
|
-
- `example`
|
|
237
|
+
// Converts the raw terminal input into a string.
|
|
238
|
+
// In this case, because the schema already expects a string, this coercion is redundant
|
|
239
|
+
coerce: coerce.string,
|
|
293
240
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
> - Only the **last argument** may be optional (when `allowPositional` is disabled).
|
|
298
|
-
> - Mixing required and optional arguments (e.g., required → optional → required) will cause parsing errors because the parser cannot determine which value belongs to which argument.
|
|
299
|
-
> - This means you **cannot have any optional arguments** if `allowPositional` is enabled.
|
|
300
|
-
> - TypeScript will throw a type error if required and optional arguments are mixed, or when using `allowPositional: true` with optional arguments.
|
|
241
|
+
// When true: this option cannot appear alongside other options/arguments,
|
|
242
|
+
// except those listed in `requires`
|
|
243
|
+
exclusive: false,
|
|
301
244
|
|
|
302
|
-
|
|
245
|
+
// If this option is used, the listed options/arguments must also be provided
|
|
246
|
+
requires: [],
|
|
303
247
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
// Define the CLI schema
|
|
309
|
-
const cliSchema = createCli({
|
|
310
|
-
cliName: "my-cli",
|
|
311
|
-
arguments: [
|
|
312
|
-
{
|
|
313
|
-
name: "inputFile", // argument name (camelCase for consistency)
|
|
314
|
-
type: z.string(), // required
|
|
315
|
-
description: "Input file",
|
|
316
|
-
example: "input.txt",
|
|
317
|
-
},
|
|
318
|
-
{
|
|
319
|
-
name: "outputFile", // second argument
|
|
320
|
-
type: z.string().optional(), // optional (only allowed as the last arg)
|
|
321
|
-
description: "Output file",
|
|
322
|
-
example: "output.txt",
|
|
323
|
-
},
|
|
324
|
-
],
|
|
325
|
-
});
|
|
248
|
+
// Options/arguments that cannot be used together with this one
|
|
249
|
+
// Avoid using `conflictWith` when `exclusive` is true
|
|
250
|
+
conflictWith: [],
|
|
326
251
|
|
|
327
|
-
//
|
|
328
|
-
|
|
329
|
-
|
|
252
|
+
// Extra metadata used for help output and documentation
|
|
253
|
+
meta: {
|
|
254
|
+
// Shown next to the option name in terminal help and Markdown docs
|
|
255
|
+
placeholder: "<list> <items> <tags>",
|
|
330
256
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
```
|
|
257
|
+
// Displayed in terminal help if both descriptions exist
|
|
258
|
+
// Not preferred in Markdown
|
|
259
|
+
description: "Plain text description shown in terminal help when both formats are provided.",
|
|
335
260
|
|
|
336
|
-
|
|
261
|
+
// Preferred in Markdown and kept formatted when printed in terminal output
|
|
262
|
+
descriptionMarkdown: "**Formatted** for terminal and preferred when generating **Markdown documentation**.",
|
|
337
263
|
|
|
338
|
-
|
|
339
|
-
|
|
264
|
+
// Appears at the end of this option’s description in terminal help
|
|
265
|
+
// Rendered inside a code block in Markdown
|
|
266
|
+
example:
|
|
267
|
+
"listy add --list groceries --items egg,milk,bread --tags food\n" +
|
|
268
|
+
"listy add --list todos --items clean,cook --tags chores|work",
|
|
340
269
|
|
|
341
|
-
|
|
342
|
-
|
|
270
|
+
// Shows this value as the default in help/docs (does not change runtime default)
|
|
271
|
+
default: `"default-list"`,
|
|
343
272
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
// Define the subcommand schema
|
|
348
|
-
export const countSchema = createSubcommand({
|
|
349
|
-
name: "count",
|
|
350
|
-
aliases: ["list"],
|
|
351
|
-
description: "Print a list of items provided by the user",
|
|
352
|
-
allowPositional: true, // enable positionals
|
|
353
|
-
});
|
|
273
|
+
// Shows this option as optional/required in help/docs (visual override only)
|
|
274
|
+
optional: false,
|
|
354
275
|
|
|
355
|
-
//
|
|
356
|
-
|
|
357
|
-
|
|
276
|
+
// When true, hides this option from both help output and docs
|
|
277
|
+
hidden: false,
|
|
278
|
+
},
|
|
279
|
+
},
|
|
358
280
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
281
|
+
items: {
|
|
282
|
+
schema: z.string().array(),
|
|
283
|
+
// Parses comma-separated lists into string[]
|
|
284
|
+
coerce: coerce.stringArray(","),
|
|
285
|
+
},
|
|
363
286
|
|
|
364
|
-
|
|
287
|
+
tags: {
|
|
288
|
+
schema: z.enum(["food", "work", "chores"]).array(),
|
|
289
|
+
// Parses pipe-separated tags into Set<string>
|
|
290
|
+
coerce: coerce.stringSet("|"),
|
|
291
|
+
},
|
|
292
|
+
},
|
|
365
293
|
});
|
|
366
294
|
```
|
|
367
295
|
|
|
368
|
-
###
|
|
296
|
+
### Creating typed arguments
|
|
369
297
|
|
|
370
|
-
|
|
371
|
-
- The provided context object can be modified before validation for advanced use cases.
|
|
372
|
-
- When using **async** hooks, make sure to call [`parseAsync`](#parseasync) or [`safeParseAsync`](#parseasync).
|
|
298
|
+
Arguments can be defined directly inside the CLI or subcommand definition. Or using the `defineArguments` function.
|
|
373
299
|
|
|
374
|
-
|
|
300
|
+
The order of argument definitions matters.
|
|
375
301
|
|
|
376
|
-
|
|
377
|
-
import * as z from "zod";
|
|
378
|
-
import { createCli } from "zod-args-parser";
|
|
379
|
-
|
|
380
|
-
// Define the CLI schema
|
|
381
|
-
const cliSchema = createCli({
|
|
382
|
-
cliName: "my-cli",
|
|
383
|
-
options: [
|
|
384
|
-
{ name: "inputDir", type: z.string() },
|
|
385
|
-
{ name: "verbose", type: z.boolean().default(false) },
|
|
386
|
-
],
|
|
387
|
-
arguments: [
|
|
388
|
-
{ name: "first-argument", type: z.string() },
|
|
389
|
-
{ name: "second-argument", type: z.string().optional() },
|
|
390
|
-
],
|
|
391
|
-
});
|
|
302
|
+
**Rules**:
|
|
392
303
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
ctx.options.verbose.rawValue = "true";
|
|
397
|
-
}
|
|
304
|
+
1. If `allowPositionals: true` → typed arguments cannot be optional.
|
|
305
|
+
2. If `allowPositionals: false` → only the last typed argument may be optional.
|
|
306
|
+
3. Argument names cannot be numeric, because it affects argument ordering.
|
|
398
307
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
//
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
308
|
+
```ts
|
|
309
|
+
import { defineSubcommand, coerce } from "zod-args-parser";
|
|
310
|
+
|
|
311
|
+
const createListCommand = defineSubcommand({
|
|
312
|
+
arguments: {
|
|
313
|
+
// In help output, argument names are automatically converted to kebab-case by default.
|
|
314
|
+
argumentName: {
|
|
315
|
+
// Same fields as options, but arguments do not support aliases
|
|
316
|
+
schema: z.string(),
|
|
317
|
+
coerce: coerce.string, // redundant (the input is already a string)
|
|
318
|
+
exclusive: false,
|
|
319
|
+
requires: [],
|
|
320
|
+
conflictWith: [],
|
|
321
|
+
meta: {
|
|
322
|
+
// Overrides the displayed argument name in help and documentation
|
|
323
|
+
name: "argument-name",
|
|
324
|
+
|
|
325
|
+
// Other meta fields work the same way as option metadata
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
},
|
|
408
329
|
});
|
|
409
330
|
```
|
|
410
331
|
|
|
411
|
-
###
|
|
332
|
+
### Using schemas
|
|
412
333
|
|
|
413
|
-
|
|
334
|
+
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.
|
|
414
335
|
|
|
415
|
-
|
|
336
|
+
Here are some examples:
|
|
416
337
|
|
|
417
|
-
|
|
338
|
+
| Vendor | `string?` | `string="value"` | coerce |
|
|
339
|
+
| -------- | ------------------------ | --------------------------------- | --------------- |
|
|
340
|
+
| Zod | `z.string().optional()` | `z.string().default("value")` | `coerce.string` |
|
|
341
|
+
| Valibot | `v.optional(v.string())` | `v.optional(v.string(), "value")` | `coerce.string` |
|
|
342
|
+
| Decoders | `d.optional(v.string())` | `d.optional(v.string(), "value")` | `coerce.string` |
|
|
343
|
+
| Sury | `S.optional(v.string())` | `S.optional(v.string(), "value")` | `coerce.string` |
|
|
418
344
|
|
|
419
|
-
|
|
345
|
+
| Vendor | `string[]?` | `string[]=["value"]` | coerce |
|
|
346
|
+
| -------- | --------------------------------- | -------------------------------------------- | ------------------------- |
|
|
347
|
+
| Zod | `z.array(z.string()).optional()` | `z.array(z.string()).default(["value"])` | `coerce.stringArray(",")` |
|
|
348
|
+
| Valibot | `v.optional(v.array(v.string()))` | `v.optional(v.array(v.string()), ["value"])` | `coerce.stringArray(",")` |
|
|
349
|
+
| Decoders | `d.optional(d.array(d.string))` | `d.optional(d.array(d.string), ["value"])` | `coerce.stringArray(",")` |
|
|
350
|
+
| Sury | `S.optional(S.array(S.string))` | `S.optional(S.array(S.string), ["value"])` | `coerce.stringArray(",")` |
|
|
420
351
|
|
|
421
|
-
|
|
352
|
+
### Default Values and Optional Inputs
|
|
422
353
|
|
|
423
|
-
|
|
424
|
-
|
|
354
|
+
- Optional values and defaults for **options and typed arguments** are controlled by the schema used for validation.
|
|
355
|
+
- `meta.optional` and `meta.default` only affect help/documentation output; they do **not** affect runtime behavior.
|
|
356
|
+
- The CLI parser enforces types and applies defaults according to the schema.
|
|
357
|
+
- Example schemas:
|
|
358
|
+
- `z.string().optional()` → optional input
|
|
359
|
+
- `z.string().default("value")` → input with default value
|
|
425
360
|
|
|
426
|
-
|
|
427
|
-
Print the help message for a specific subcommand.
|
|
428
|
-
|
|
429
|
-
See the [HelpMessageStyle](#helpmsgstyle) type for more details.
|
|
430
|
-
|
|
431
|
-
```ts
|
|
432
|
-
import chalk from "chalk";
|
|
433
|
-
import { formatCliHelpMsg, formatSubcommandHelpMsg, helpMessageStyles } from "zod-args-parser";
|
|
361
|
+
### Positionals vs Typed Arguments
|
|
434
362
|
|
|
435
|
-
|
|
436
|
-
const cliSchema = createCli(/* ... */);
|
|
363
|
+
Think of typed arguments as **reserved seats** at the front of the line, and positionals as **everyone standing behind them**.
|
|
437
364
|
|
|
438
|
-
|
|
439
|
-
|
|
365
|
+
- Typed arguments are filled **in order from left to right**.
|
|
366
|
+
- Any remaining inputs become positionals **only if `allowPositionals: true`**.
|
|
440
367
|
|
|
441
|
-
|
|
442
|
-
// print help for CLI (without colors)
|
|
443
|
-
results.printCliHelp(helpMessageStyles.noColors);
|
|
368
|
+
#### Rules
|
|
444
369
|
|
|
445
|
-
|
|
446
|
-
|
|
370
|
+
| Setting | Behavior |
|
|
371
|
+
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
|
|
372
|
+
| `allowPositionals: true` | Typed arguments are parsed first. Remaining inputs go into `positionals`. Typed arguments **cannot** be optional in this mode. |
|
|
373
|
+
| `allowPositionals: false` | All inputs must match typed arguments. Only the **last** typed argument may be optional. Extra inputs cause an error. |
|
|
447
374
|
|
|
448
|
-
|
|
449
|
-
results.printSubcommandHelp("build", { title: chalk.red });
|
|
450
|
-
});
|
|
375
|
+
### Option and Argument Constraints
|
|
451
376
|
|
|
452
|
-
|
|
377
|
+
Both options and typed arguments support rules to control valid combinations:
|
|
453
378
|
|
|
454
|
-
|
|
455
|
-
const results = safeParse(args, ...schemas);
|
|
456
|
-
if (results.success) {
|
|
457
|
-
results.printCliHelp();
|
|
458
|
-
}
|
|
379
|
+
#### `exclusive: boolean`
|
|
459
380
|
|
|
460
|
-
|
|
461
|
-
const cliHelp = formatCliHelpMsg(schemas, helpMessageStyles.html);
|
|
462
|
-
console.log(`<pre style="background-color: #1e1e2e">${cliHelp}</pre>`);
|
|
381
|
+
- Cannot be used together with other options or arguments, except those explicitly listed in `requires`.
|
|
463
382
|
|
|
464
|
-
|
|
465
|
-
console.log(`<pre style="background-color: #1e1e2e">${subcommandHelp}</pre>`);
|
|
466
|
-
```
|
|
383
|
+
#### `requires: string[]`
|
|
467
384
|
|
|
468
|
-
|
|
385
|
+
- Lists other options/arguments names (not aliases) that **must be provided** if this one is used.
|
|
386
|
+
- Helps enforce dependencies between flags or arguments.
|
|
469
387
|
|
|
470
|
-
|
|
471
|
-
Check if a schema is optional or has a default value.
|
|
388
|
+
#### `conflictWith: string[]`
|
|
472
389
|
|
|
473
|
-
-
|
|
474
|
-
|
|
390
|
+
- Lists other options/arguments names (not aliases) that **cannot be used together** with this one.
|
|
391
|
+
- Prevents incompatible combinations and avoids ambiguous behavior.
|
|
475
392
|
|
|
476
|
-
|
|
477
|
-
A preprocessing handle to convert a string to an array.
|
|
393
|
+
### Negating a boolean option
|
|
478
394
|
|
|
479
|
-
|
|
480
|
-
A preprocessing handle to convert a string to a set.
|
|
395
|
+
Boolean options can be negated by prefixing them with `no-` or by using the equals sign `=`.
|
|
481
396
|
|
|
482
|
-
```
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
const cliSchema = createCli({
|
|
487
|
-
cliName: "my-cli",
|
|
488
|
-
options: [
|
|
489
|
-
{
|
|
490
|
-
name: "tags",
|
|
491
|
-
aliases: ["t"],
|
|
492
|
-
placeholder: "<list>",
|
|
493
|
-
description: "tags separated by semicolon (;)",
|
|
494
|
-
example: "--tags tag1;tag2;tag3",
|
|
495
|
-
type: z.preprocess((value: string) => stringToArray(value, ";"), z.array(z.string())),
|
|
496
|
-
},
|
|
497
|
-
{
|
|
498
|
-
name: "verbose",
|
|
499
|
-
aliases: ["v"],
|
|
500
|
-
description: "Verbose mode",
|
|
501
|
-
type: z.boolean().default(false),
|
|
502
|
-
},
|
|
503
|
-
],
|
|
504
|
-
});
|
|
397
|
+
```sh
|
|
398
|
+
--bool true
|
|
399
|
+
--no-bool false
|
|
505
400
|
|
|
506
|
-
|
|
507
|
-
|
|
401
|
+
--bool=true true
|
|
402
|
+
--bool=false false
|
|
508
403
|
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
schemaDefaultValue(ctxOptions.verbose.schema), // false
|
|
512
|
-
);
|
|
513
|
-
});
|
|
404
|
+
-v true
|
|
405
|
+
--no-v false
|
|
514
406
|
```
|
|
515
407
|
|
|
516
|
-
###
|
|
517
|
-
|
|
518
|
-
- `InferOptionsInput<Cli | Subcommand>`
|
|
519
|
-
Infer the options input type (before zod validation) from the Cli or subcommand schema.
|
|
520
|
-
|
|
521
|
-
- `InferOptionsOutput<Cli | Subcommand>`
|
|
522
|
-
Infer the options Output type (after zod validation) from the Cli or subcommand schema.
|
|
408
|
+
### Creating a Custom Help Message Style
|
|
523
409
|
|
|
524
|
-
|
|
525
|
-
Infer the arguments input type (before zod validation) from the Cli or subcommand schema.
|
|
526
|
-
|
|
527
|
-
- `InferArgumentsOutput<Cli | Subcommand>`
|
|
528
|
-
Infer the arguments Output type (after zod validation) from the Cli or subcommand schema.
|
|
410
|
+
You can define a custom style for CLI help messages by implementing the `HelpMessageStyle` interface. A common approach is to start from an existing style and override only the parts you want.
|
|
529
411
|
|
|
530
412
|
```ts
|
|
531
|
-
import
|
|
532
|
-
import
|
|
533
|
-
|
|
534
|
-
const subcommand = createSubcommand({
|
|
535
|
-
name: "subcommand",
|
|
536
|
-
options: [
|
|
537
|
-
{ name: "numberOption", type: z.coerce.number() },
|
|
538
|
-
{ name: "stringOption", type: z.string() },
|
|
539
|
-
{ name: "booleanOption", type: z.boolean() },
|
|
540
|
-
{ name: "optionalOption", type: z.boolean().optional() },
|
|
541
|
-
],
|
|
542
|
-
arguments: [
|
|
543
|
-
{ name: "stringArgument", type: z.string() },
|
|
544
|
-
{ name: "numberArgument", type: z.coerce.number() },
|
|
545
|
-
{ name: "booleanArgument", type: z.boolean() },
|
|
546
|
-
],
|
|
547
|
-
});
|
|
413
|
+
import chalk from "chalk";
|
|
414
|
+
import { HelpMessageStyle, helpMessageStyles } from "zod-args-parser";
|
|
548
415
|
|
|
549
|
-
|
|
550
|
-
|
|
416
|
+
// Example: create a new style based on the default style
|
|
417
|
+
const myCustomStyle = new HelpMessageStyle(
|
|
418
|
+
{
|
|
419
|
+
title: chalk.bold.magenta,
|
|
420
|
+
option: chalk.yellow,
|
|
421
|
+
argument: chalk.green,
|
|
422
|
+
},
|
|
423
|
+
// optionally use default style as base
|
|
424
|
+
helpMessageStyles.default,
|
|
425
|
+
);
|
|
551
426
|
|
|
552
|
-
|
|
553
|
-
|
|
427
|
+
// Use the custom style when generating help
|
|
428
|
+
console.log(myCli.generateCliHelpMessage({ style: myCustomStyle }));
|
|
554
429
|
```
|
|
555
430
|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
### Methods
|
|
559
|
-
|
|
560
|
-
#### createCli
|
|
431
|
+
### Help Message as HTML
|
|
561
432
|
|
|
562
|
-
`
|
|
433
|
+
You can generate the CLI help message as HTML using the `html` style and insert it into a `<pre>` element.
|
|
563
434
|
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
See [Cli](#cli) object type.
|
|
435
|
+
```ts
|
|
436
|
+
import { listyCLI, helpMessageStyles, generateCliHelpMessage } from "zod-args-parser";
|
|
567
437
|
|
|
568
|
-
|
|
438
|
+
// Generate help message as HTML string
|
|
439
|
+
const htmlHelp = generateCliHelpMessage(listyCLI, { style: helpMessageStyles.html, markdownRenderer: "html" });
|
|
569
440
|
|
|
570
|
-
|
|
441
|
+
// Insert into a <pre> element in your page
|
|
442
|
+
const pre = document.createElement("pre");
|
|
443
|
+
pre.innerHTML = htmlHelp;
|
|
444
|
+
document.body.appendChild(pre);
|
|
445
|
+
```
|
|
571
446
|
|
|
572
|
-
|
|
447
|
+
You can style Markdown content using CSS:
|
|
573
448
|
|
|
574
|
-
|
|
449
|
+
```css
|
|
450
|
+
span._markdown * {
|
|
451
|
+
white-space: initial;
|
|
452
|
+
}
|
|
453
|
+
```
|
|
575
454
|
|
|
576
|
-
|
|
455
|
+
## API Reference
|
|
577
456
|
|
|
578
|
-
|
|
457
|
+
### Type Utilities
|
|
579
458
|
|
|
580
|
-
|
|
459
|
+
#### `InferInputType<T extends Cli | Subcommand>`
|
|
581
460
|
|
|
582
|
-
|
|
461
|
+
Infer options, arguments, and positionals input types from the CLI/subcommand definition.
|
|
583
462
|
|
|
584
|
-
####
|
|
463
|
+
#### `InferOutputType<T extends Cli | Subcommand>`
|
|
585
464
|
|
|
586
|
-
|
|
465
|
+
Infer options, arguments, and positionals output types from the CLI/subcommand definition.
|
|
587
466
|
|
|
588
|
-
|
|
467
|
+
#### `InferOptionsInputType<T extends Cli | Subcommand>`
|
|
589
468
|
|
|
590
|
-
|
|
469
|
+
Infer options input type from the CLI/subcommand definition.
|
|
591
470
|
|
|
592
|
-
####
|
|
471
|
+
#### `InferOptionsOutputType<T extends Cli | Subcommand>`
|
|
593
472
|
|
|
594
|
-
|
|
473
|
+
Infer options output type from the CLI/subcommand definition.
|
|
595
474
|
|
|
596
|
-
|
|
475
|
+
#### `InferArgumentsInputType<T extends Cli | Subcommand>`
|
|
597
476
|
|
|
598
|
-
|
|
477
|
+
Infer arguments input type from the CLI/subcommand definition.
|
|
599
478
|
|
|
600
|
-
####
|
|
479
|
+
#### `InferArgumentsOutputType<T extends Cli | Subcommand>`
|
|
601
480
|
|
|
602
|
-
|
|
481
|
+
Infer arguments output type from the CLI/subcommand definition.
|
|
603
482
|
|
|
604
|
-
|
|
605
|
-
|
|
483
|
+
```ts
|
|
484
|
+
import type { defineSubcommand, InferInputType, InferOutputType } from "zod-args-parser";
|
|
606
485
|
|
|
607
|
-
|
|
486
|
+
const subcommand = defineSubcommand({
|
|
487
|
+
// ...
|
|
488
|
+
});
|
|
608
489
|
|
|
609
|
-
|
|
490
|
+
type InputType = InferInputType<typeof subcommand>;
|
|
491
|
+
type OutputType = InferOutputType<typeof subcommand>;
|
|
492
|
+
```
|
|
610
493
|
|
|
611
|
-
|
|
494
|
+
### Coerce Helpers
|
|
612
495
|
|
|
613
|
-
|
|
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>()`
|
|
614
506
|
|
|
615
|
-
|
|
507
|
+
### Markdown Generation
|
|
616
508
|
|
|
617
|
-
####
|
|
509
|
+
#### generateMarkdown
|
|
618
510
|
|
|
619
|
-
`(
|
|
511
|
+
`(cliDefinition: Cli) => string`
|
|
620
512
|
|
|
621
|
-
|
|
622
|
-
Use this when you have async actions or hooks.
|
|
513
|
+
Generate markdown documentation for a **CLI definition** and return it as a `string`.
|
|
623
514
|
|
|
624
|
-
|
|
515
|
+
### Autocomplete Script Generation
|
|
625
516
|
|
|
626
517
|
#### generateBashAutocompleteScript
|
|
627
518
|
|
|
628
|
-
`(
|
|
629
|
-
|
|
630
|
-
Generates an autocomplete script for `bash`.
|
|
631
|
-
|
|
632
|
-
See [Cli](#cli) and [Subcommand](#subcommand)
|
|
519
|
+
`(cliDefinition: Cli) => string`
|
|
633
520
|
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
`(...params: [Cli, ...Subcommand[]]) => string`
|
|
637
|
-
|
|
638
|
-
Generates an autocomplete script for `powershell`.
|
|
639
|
-
|
|
640
|
-
See [Cli](#cli) and [Subcommand](#subcommand)
|
|
521
|
+
Generate a Bash autocomplete script for a **CLI definition** and return it as a `string`.
|
|
641
522
|
|
|
642
523
|
#### generateZshAutocompleteScript
|
|
643
524
|
|
|
644
|
-
`(
|
|
645
|
-
|
|
646
|
-
Generates an autocomplete script for `zsh`.
|
|
647
|
-
|
|
648
|
-
See [Cli](#cli) and [Subcommand](#subcommand)
|
|
649
|
-
|
|
650
|
-
#### generateMarkdown
|
|
651
|
-
|
|
652
|
-
`(...params: [Cli, ...Subcommand[]]) => string`
|
|
653
|
-
|
|
654
|
-
Generates a markdown documentation for your CLI.
|
|
525
|
+
`(cliDefinition: Cli) => string`
|
|
655
526
|
|
|
656
|
-
|
|
527
|
+
Generate a zsh autocomplete script for a **CLI definition** and return it as a `string`.
|
|
657
528
|
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
#### Cli
|
|
661
|
-
|
|
662
|
-
| Name | Type | Description | Example |
|
|
663
|
-
| --------------- | -------------------------- | ---------------------------------------------- | ------------------------------ |
|
|
664
|
-
| cliName | `string` | The name of the CLI program. | `"my-cli"` |
|
|
665
|
-
| description | `string?` | A description of the CLI for the help message. | `"Build the project"` |
|
|
666
|
-
| usage | `string?` | The usage of the CLI for the help message. | `"my-cli build"` |
|
|
667
|
-
| example | `string?` | An example of CLI usage for the help message. | `"my-cli <command> [options]"` |
|
|
668
|
-
| options | [`Option[]?`](#option) | An array of options for the CLI. | |
|
|
669
|
-
| arguments | [`Argument[]?`](#argument) | An array of arguments for the CLI. | |
|
|
670
|
-
| allowPositional | `boolean?` | Allows positional arguments for the CLI. | |
|
|
671
|
-
|
|
672
|
-
#### Subcommand
|
|
673
|
-
|
|
674
|
-
| Name | Type | Description | Example |
|
|
675
|
-
| --------------- | -------------------------- | ----------------------------------------------------- | -------------------------- |
|
|
676
|
-
| name | `string` | The name of the subcommand. | `"build"` |
|
|
677
|
-
| aliases | `string[]?` | An array of aliases for the subcommand. | `["b", "build"]` |
|
|
678
|
-
| description | `string?` | A description of the subcommand for the help message. | `"Build the project"` |
|
|
679
|
-
| usage | `string?` | The usage of the subcommand for the help message. | `"my-cli build"` |
|
|
680
|
-
| placeholder | `string?` | A placeholder displayed in the help message. | `"[options]"` |
|
|
681
|
-
| example | `string?` | An example of subcommand usage for the help message. | `"my-cli build [options]"` |
|
|
682
|
-
| options | [`Option[]?`](#option) | An array of options for the subcommand. | |
|
|
683
|
-
| arguments | [`Argument[]?`](#argument) | An array of arguments for the subcommand. | |
|
|
684
|
-
| allowPositional | `boolean?` | Allows positional arguments for this subcommand. | |
|
|
529
|
+
#### generatePowerShellAutocompleteScript
|
|
685
530
|
|
|
686
|
-
|
|
531
|
+
`(cliDefinition: Cli) => string`
|
|
687
532
|
|
|
688
|
-
|
|
689
|
-
| ----------- | ----------- | ---------------------------------------------------- | ------------------------------- |
|
|
690
|
-
| name | `string` | The name of the option. camelCase is recommended. | `"inputDir"` -> `--input-dir` |
|
|
691
|
-
| type | `ZodType` | Specifies the type of the option using Zod schema. | `z.boolean().default(false)` |
|
|
692
|
-
| aliases | `string[]?` | An array of aliases for the option. | `["i", "dir"]` -> `-i`, `--dir` |
|
|
693
|
-
| description | `string?` | A description of the option for the help message. | `"Input directory"` |
|
|
694
|
-
| placeholder | `string?` | Placeholder text for the option in the help message. | `"<dir>"` or `"<path>"` |
|
|
695
|
-
| example | `string?` | An example of option usage for the help message. | `"-i /path/to/dir"` |
|
|
533
|
+
Generate a PowerShell autocomplete script for a **CLI definition** and return it as a `string`.
|
|
696
534
|
|
|
697
|
-
|
|
535
|
+
### Help Message
|
|
698
536
|
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
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. |
|
|
599
|
+
|
|
600
|
+
### CliMeta
|
|
601
|
+
|
|
602
|
+
| Property | Type | Description |
|
|
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). |
|
|
608
|
+
|
|
609
|
+
### Subcommand
|
|
610
|
+
|
|
611
|
+
| Property | Type | Description |
|
|
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. |
|
|
619
|
+
|
|
620
|
+
### SubcommandMeta
|
|
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.
|
|
705
674
|
|
|
706
675
|
#### Context
|
|
707
676
|
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
|
711
|
-
|
|
|
712
|
-
|
|
|
713
|
-
|
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
|
720
|
-
|
|
|
721
|
-
|
|
|
722
|
-
| flag
|
|
723
|
-
|
|
|
724
|
-
|
|
|
725
|
-
| source
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
|
730
|
-
|
|
|
731
|
-
| schema
|
|
732
|
-
|
|
|
733
|
-
|
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
| Name | Type | Description |
|
|
738
|
-
| ---------------------- | ---------------------------------------------------- | ------------------------------------------------------------------------------------- |
|
|
739
|
-
| subcommand | `string \| undefined` | The name of the executed subcommand. |
|
|
740
|
-
| `[optionName: string]` | `unknown` | Validated options for the CLI/subcommand. |
|
|
741
|
-
| arguments | `unknown[] \| undefined` | Validated arguments for the CLI/subcommand. |
|
|
742
|
-
| positional | `string[] \| undefined` | Positional array for the CLI/subcommand. |
|
|
743
|
-
| printCliHelp | `(style?: HelpMessageStyle) => void` | Prints the CLI help message. See [HelpMessageStyle](#helpmsgstyle) |
|
|
744
|
-
| printSubcommandHelp | `(subcommand: string, style?: HelpMessageStyle) => void` | Prints the help message for a specified subcommand. See [HelpMessageStyle](#helpmsgstyle) |
|
|
745
|
-
|
|
746
|
-
#### HelpMessageStyle
|
|
747
|
-
|
|
748
|
-
Available styles: `default`, `dracula`, `solarizedDark`, `nord`, `html`, `gruvboxDark`, `monokai`, `oneDark`, `noColors`
|
|
749
|
-
|
|
750
|
-
Each style has the following properties:
|
|
751
|
-
|
|
752
|
-
| Key | Type | Default |
|
|
753
|
-
| ------------ | -------------------------------- | ---------------------- |
|
|
754
|
-
| title | `(...text: unknown[]) => string` | `chalk.bold.blue` |
|
|
755
|
-
| description | `(...text: unknown[]) => string` | `chalk.white` |
|
|
756
|
-
| default | `(...text: unknown[]) => string` | `chalk.dim.italic` |
|
|
757
|
-
| optional | `(...text: unknown[]) => string` | `chalk.dim.italic` |
|
|
758
|
-
| exampleTitle | `(...text: unknown[]) => string` | `chalk.yellow` |
|
|
759
|
-
| example | `(...text: unknown[]) => string` | `chalk.dim` |
|
|
760
|
-
| command | `(...text: unknown[]) => string` | `chalk.yellow` |
|
|
761
|
-
| option | `(...text: unknown[]) => string` | `chalk.cyan` |
|
|
762
|
-
| argument | `(...text: unknown[]) => string` | `chalk.green` |
|
|
763
|
-
| placeholder | `(...text: unknown[]) => string` | `chalk.hex("#FF9800")` |
|
|
764
|
-
| punctuation | `(...text: unknown[]) => string` | `chalk.white.dim` |
|
|
765
|
-
|
|
766
|
-
## Example
|
|
767
|
-
|
|
768
|
-
- [Example code](https://github.com/alabsi91/zod-args-parser/tree/main/example)
|
|
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. |
|
|
769
706
|
|
|
770
707
|
## License
|
|
771
708
|
|