zod-args-parser 2.0.0-alpha.0 → 2.0.0-beta.1
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 -23
- package/lib/typescript/parser/validate/validate-type.d.ts.map +0 -1
- package/lib/typescript/parser/validate/validate.d.ts +0 -12
- 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 -235
- package/src/parser/safe-parse.ts +0 -103
- package/src/parser/unsafe-parse.ts +0 -98
- package/src/parser/validate/validate-type.ts +0 -20
- package/src/parser/validate/validate.ts +0 -71
- package/src/types.ts +0 -365
- package/src/zod-utilities.ts +0 -214
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import type { Schema } from "../types.js";
|
|
2
|
-
|
|
3
|
-
export interface CliMetadata {
|
|
4
|
-
/** The name of the cli program. */
|
|
5
|
-
readonly name: string;
|
|
6
|
-
|
|
7
|
-
/** - The description of the cli program. Empty string if not provided */
|
|
8
|
-
readonly description: string;
|
|
9
|
-
|
|
10
|
-
/** - The usage of the cli program. Empty string if not provided */
|
|
11
|
-
readonly usage: string;
|
|
12
|
-
|
|
13
|
-
/** - The example of the cli program. Empty string if not provided */
|
|
14
|
-
readonly example: string;
|
|
15
|
-
|
|
16
|
-
/** - Whether the cli program allows positional arguments. */
|
|
17
|
-
readonly allowPositional: boolean;
|
|
18
|
-
|
|
19
|
-
/** - The options of the cli program. Empty array if not provided */
|
|
20
|
-
readonly options: OptionMetadata[];
|
|
21
|
-
|
|
22
|
-
/** - The arguments of the cli program. Empty array if not provided */
|
|
23
|
-
readonly arguments: ArgumentMetadata[];
|
|
24
|
-
|
|
25
|
-
/** - The subcommands of the cli program. Empty array if not provided */
|
|
26
|
-
readonly subcommands: SubcommandMetadata[];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface SubcommandMetadata {
|
|
30
|
-
/** The subcommand name. */
|
|
31
|
-
readonly name: string;
|
|
32
|
-
|
|
33
|
-
/** - The aliases of the subcommand. Empty array if not provided */
|
|
34
|
-
readonly aliases: string[];
|
|
35
|
-
|
|
36
|
-
/** - The description of the subcommand. Empty string if not provided */
|
|
37
|
-
readonly description: string;
|
|
38
|
-
|
|
39
|
-
/** - The placeholder of the subcommand. Empty string if not provided */
|
|
40
|
-
readonly placeholder: string;
|
|
41
|
-
|
|
42
|
-
/** - The usage of the subcommand. Empty string if not provided */
|
|
43
|
-
readonly usage: string;
|
|
44
|
-
|
|
45
|
-
/** - The example of the subcommand. Empty string if not provided */
|
|
46
|
-
readonly example: string;
|
|
47
|
-
|
|
48
|
-
/** - Whether the subcommand allows positional arguments. */
|
|
49
|
-
readonly allowPositional: boolean;
|
|
50
|
-
|
|
51
|
-
/** - The options of the subcommand. Empty array if not provided */
|
|
52
|
-
readonly options: OptionMetadata[];
|
|
53
|
-
|
|
54
|
-
/** - The arguments of the subcommand. Empty array if not provided */
|
|
55
|
-
readonly arguments: ArgumentMetadata[];
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface OptionMetadata {
|
|
59
|
-
/** The option name in camelCase. E.g. `optionName` */
|
|
60
|
-
readonly name: string;
|
|
61
|
-
|
|
62
|
-
/** The option name in kebab-case. E.g. `--option-name` */
|
|
63
|
-
readonly nameAsArg: string;
|
|
64
|
-
|
|
65
|
-
/** - The aliases of the option in camelCase. Empty array if not provided. E.g. `[aliasName, ...]` */
|
|
66
|
-
readonly aliases: string[];
|
|
67
|
-
|
|
68
|
-
/** - The aliases of the option in kebab-case. Empty array if not provided. E.g. `[--alias-name, ...]` */
|
|
69
|
-
readonly aliasesAsArgs: string[];
|
|
70
|
-
|
|
71
|
-
/** - The description of the option. Empty string if not provided */
|
|
72
|
-
readonly description: string;
|
|
73
|
-
|
|
74
|
-
/** - The placeholder of the option. Empty string if not provided */
|
|
75
|
-
readonly placeholder: string;
|
|
76
|
-
|
|
77
|
-
/** - The example of the option. Empty string if not provided */
|
|
78
|
-
readonly example: string;
|
|
79
|
-
|
|
80
|
-
/** - The default value of the option. */
|
|
81
|
-
readonly defaultValue: unknown;
|
|
82
|
-
|
|
83
|
-
/** - The default value of the option as string. */
|
|
84
|
-
readonly defaultValueAsString: string;
|
|
85
|
-
|
|
86
|
-
/** - Whether the option is optional. */
|
|
87
|
-
readonly optional: boolean;
|
|
88
|
-
|
|
89
|
-
/** - The zod type of the option. */
|
|
90
|
-
readonly type: Schema;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export interface ArgumentMetadata {
|
|
94
|
-
/** The argument name. */
|
|
95
|
-
readonly name: string;
|
|
96
|
-
|
|
97
|
-
/** - The description of the argument. Empty string if not provided */
|
|
98
|
-
readonly description: string;
|
|
99
|
-
|
|
100
|
-
/** - The example of the argument. Empty string if not provided */
|
|
101
|
-
readonly example: string;
|
|
102
|
-
|
|
103
|
-
/** - The default value of the argument. */
|
|
104
|
-
readonly defaultValue: unknown;
|
|
105
|
-
|
|
106
|
-
/** - The default value of the argument as string. */
|
|
107
|
-
readonly defaultValueAsString: string;
|
|
108
|
-
|
|
109
|
-
/** - Whether the argument is optional. */
|
|
110
|
-
readonly optional: boolean;
|
|
111
|
-
|
|
112
|
-
/** - The zod type of the argument. */
|
|
113
|
-
readonly type: Schema;
|
|
114
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import type { Argument, Option, Prettify, Schema, Subcommand } from "../../types.js";
|
|
2
|
-
|
|
3
|
-
type ParsedOption<S extends Schema = Schema, N extends string = string> =
|
|
4
|
-
| {
|
|
5
|
-
/** The name of the option as provided by the user. */
|
|
6
|
-
name: N;
|
|
7
|
-
/** The CLI flag as provided by the user (e.g. `--foo` or `-f`). */
|
|
8
|
-
flag: string;
|
|
9
|
-
/** The schema that validates this option. */
|
|
10
|
-
schema: S;
|
|
11
|
-
/** The raw string value supplied for this option from the CLI. */
|
|
12
|
-
rawValue: string;
|
|
13
|
-
/**
|
|
14
|
-
* The source of the option:
|
|
15
|
-
*
|
|
16
|
-
* - `cli`: provided explicitly in the CLI
|
|
17
|
-
* - `default`: not provided, and the schema has a default.
|
|
18
|
-
*/
|
|
19
|
-
source: "cli";
|
|
20
|
-
}
|
|
21
|
-
| {
|
|
22
|
-
/** The name of the option as provided by the user. */
|
|
23
|
-
name: N;
|
|
24
|
-
/** Undefined when the source is `default`. */
|
|
25
|
-
flag?: never;
|
|
26
|
-
/** The schema that validates this option. */
|
|
27
|
-
schema: S;
|
|
28
|
-
/** Undefined when the source is `default`. */
|
|
29
|
-
rawValue?: string | undefined;
|
|
30
|
-
/**
|
|
31
|
-
* The source of the option:
|
|
32
|
-
*
|
|
33
|
-
* - `cli`: provided explicitly in the CLI
|
|
34
|
-
* - `default`: not provided, and the schema has a default.
|
|
35
|
-
*/
|
|
36
|
-
source: "default";
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
type ParsedArgument<S extends Schema = Schema> =
|
|
40
|
-
| {
|
|
41
|
-
/** The raw string value provided directly from the CLI. */
|
|
42
|
-
rawValue: string;
|
|
43
|
-
/** The schema that validates this argument. */
|
|
44
|
-
schema: S;
|
|
45
|
-
/**
|
|
46
|
-
* The source of the option:
|
|
47
|
-
*
|
|
48
|
-
* - `cli`: provided explicitly in the CLI
|
|
49
|
-
* - `default`: not provided, and the schema has a default.
|
|
50
|
-
*/
|
|
51
|
-
source: "cli";
|
|
52
|
-
}
|
|
53
|
-
| {
|
|
54
|
-
/** Undefined when the source is `default`. */
|
|
55
|
-
rawValue?: never;
|
|
56
|
-
/** The schema that validates this argument. */
|
|
57
|
-
schema: S;
|
|
58
|
-
/**
|
|
59
|
-
* The source of the option:
|
|
60
|
-
*
|
|
61
|
-
* - `cli`: provided explicitly in the CLI
|
|
62
|
-
* - `default`: not provided, and the schema has a default.
|
|
63
|
-
*/
|
|
64
|
-
source: "default";
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
type OptionsArray2Record<T extends Option[] | undefined> = T extends Option[]
|
|
68
|
-
? { [K in T[number]["name"]]: ParsedOption<Extract<T[number], { name: K }>["type"], K> }
|
|
69
|
-
: Record<never, never>;
|
|
70
|
-
|
|
71
|
-
type ArgumentsArray2ArrayType<T extends Argument[] | undefined> = T extends Argument[]
|
|
72
|
-
? { [K in keyof T]: ParsedArgument<T[K] extends { type: Schema } ? T[K]["type"] : never> }
|
|
73
|
-
: never;
|
|
74
|
-
|
|
75
|
-
export type ParseResult<S extends Partial<Subcommand>[]> = {
|
|
76
|
-
[K in keyof S]: Prettify<{
|
|
77
|
-
subcommand: S[K]["name"] extends string ? S[K]["name"] : undefined;
|
|
78
|
-
positional: S[K]["allowPositional"] extends true ? string[] : never;
|
|
79
|
-
options: S[K]["options"] extends Option[] ? OptionsArray2Record<S[K]["options"]> : never;
|
|
80
|
-
arguments: ArgumentsArray2ArrayType<S[K]["arguments"]>;
|
|
81
|
-
}>;
|
|
82
|
-
}[number];
|
|
83
|
-
|
|
84
|
-
export type ParsedContext = {
|
|
85
|
-
subcommand: string | undefined;
|
|
86
|
-
options?: Record<string, ParsedOption>;
|
|
87
|
-
arguments?: ParsedArgument[];
|
|
88
|
-
positional?: string[];
|
|
89
|
-
};
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import { generateOrdinalSuffix } from "../../utilities.js";
|
|
2
|
-
import { isBooleanSchema, isOptionalSchema, schemaDefaultValue } from "../../zod-utilities.js";
|
|
3
|
-
import {
|
|
4
|
-
decoupleFlags,
|
|
5
|
-
findOption,
|
|
6
|
-
findSubcommand,
|
|
7
|
-
isFlagArgument,
|
|
8
|
-
isOptionArgument,
|
|
9
|
-
transformOptionToArgument,
|
|
10
|
-
} from "./parser-helpers.js";
|
|
11
|
-
|
|
12
|
-
import type { Cli, Subcommand } from "../../types.js";
|
|
13
|
-
import type { ParsedContext } from "./parse-types.js";
|
|
14
|
-
|
|
15
|
-
export function parse(argv: string[], ...parameters: [Cli, ...Subcommand[]]) {
|
|
16
|
-
const subcommandArray = parameters as Subcommand[];
|
|
17
|
-
const allSubcommands = new Set<string>(subcommandArray.flatMap(c => [c.name, ...(c.aliases || [])]));
|
|
18
|
-
|
|
19
|
-
argv = decoupleFlags(argv); // decouple flags E.g. `-rf` -> `-r, -f`
|
|
20
|
-
|
|
21
|
-
const results: ParsedContext = {
|
|
22
|
-
subcommand: undefined,
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/** - Get current subcommand object */
|
|
26
|
-
const getSubcommandObject = () => findSubcommand(results.subcommand, subcommandArray);
|
|
27
|
-
|
|
28
|
-
for (let index = 0; index < argv.length; index++) {
|
|
29
|
-
const argument_ = argv[index];
|
|
30
|
-
|
|
31
|
-
// * Subcommand check
|
|
32
|
-
if (index === 0) {
|
|
33
|
-
results.subcommand = allSubcommands.has(argument_) ? argument_ : undefined;
|
|
34
|
-
|
|
35
|
-
// First argument is a subcommand. Skip to the next argument
|
|
36
|
-
if (results.subcommand) continue;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// * Option check
|
|
40
|
-
|
|
41
|
-
// Check for `--option=value` or `--option value`
|
|
42
|
-
const argumentAndValue = argument_.split("=").filter(Boolean);
|
|
43
|
-
const argumentWithEquals = argument_.includes("=");
|
|
44
|
-
const argument = argumentAndValue[0];
|
|
45
|
-
const argumentValue: string | undefined = argumentAndValue[1];
|
|
46
|
-
|
|
47
|
-
if (isOptionArgument(argument)) {
|
|
48
|
-
if (isFlagArgument(argument) && argumentWithEquals) {
|
|
49
|
-
throw new Error(`Flag arguments cannot be assigned using "=": "${argument_}"`, { cause: "zod-args-parser" });
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const subcommandObject = getSubcommandObject();
|
|
53
|
-
if (!subcommandObject) {
|
|
54
|
-
throw new Error(`Unknown subcommand: "${results.subcommand}"`, { cause: "zod-args-parser" });
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (!subcommandObject.options) {
|
|
58
|
-
if (!results.subcommand) {
|
|
59
|
-
throw new Error(`Error: options are not allowed here: "${argument}"`, { cause: "zod-args-parser" });
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
throw new Error(`Error: subcommand "${results.subcommand}" does not allow options: "${argument}"`, {
|
|
63
|
-
cause: "zod-args-parser",
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const option = findOption(argument, subcommandObject.options);
|
|
68
|
-
if (!option) {
|
|
69
|
-
throw new Error(`Unknown option: "${argument}"`, { cause: "zod-args-parser" });
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (results.options && option.name in results.options) {
|
|
73
|
-
throw new Error(`Duplicated option: "${argument}"`, { cause: "zod-args-parser" });
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const isTypeBoolean = isBooleanSchema(option.type);
|
|
77
|
-
const nextArgument = argv[index + 1];
|
|
78
|
-
|
|
79
|
-
let optionValue: string | boolean = argumentWithEquals ? argumentValue : nextArgument;
|
|
80
|
-
|
|
81
|
-
// infer value for boolean options
|
|
82
|
-
if (isTypeBoolean && !argumentWithEquals) {
|
|
83
|
-
optionValue = "true";
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (optionValue === undefined) {
|
|
87
|
-
throw new Error(`Expected a value for "${argument}" but got nothing`, { cause: "zod-args-parser" });
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (!argumentWithEquals && isOptionArgument(optionValue)) {
|
|
91
|
-
throw new Error(`Expected a value for "${argument}" but got an argument "${nextArgument}"`, {
|
|
92
|
-
cause: "zod-args-parser",
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (!results.options) {
|
|
97
|
-
results.options = {};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
results.options[option.name] = {
|
|
101
|
-
name: option.name,
|
|
102
|
-
schema: option.type,
|
|
103
|
-
flag: argument,
|
|
104
|
-
rawValue: optionValue.toString(),
|
|
105
|
-
source: "cli",
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
// Skip to the next argument if it is the current option’s value.
|
|
109
|
-
if (!argumentWithEquals && !isTypeBoolean) {
|
|
110
|
-
index++;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const subcommandObject = getSubcommandObject();
|
|
117
|
-
|
|
118
|
-
// * Arguments check
|
|
119
|
-
if (subcommandObject?.arguments) {
|
|
120
|
-
if (!results.arguments) {
|
|
121
|
-
results.arguments = [];
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const currentArgumentCount = results.arguments.length;
|
|
125
|
-
|
|
126
|
-
// Any extra arguments are possibly positional
|
|
127
|
-
if (currentArgumentCount < subcommandObject.arguments.length) {
|
|
128
|
-
const argumentType = subcommandObject.arguments[currentArgumentCount].type;
|
|
129
|
-
results.arguments.push({
|
|
130
|
-
schema: argumentType,
|
|
131
|
-
rawValue: argument_,
|
|
132
|
-
source: "cli",
|
|
133
|
-
});
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// * Positional check
|
|
139
|
-
if (subcommandObject?.allowPositional) {
|
|
140
|
-
if (!results.positional) {
|
|
141
|
-
results.positional = [];
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
results.positional.push(argument_);
|
|
145
|
-
continue;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// * Unexpected
|
|
149
|
-
if (!results.subcommand) {
|
|
150
|
-
throw new Error(`Unexpected argument "${argument_}": positional arguments are not allowed here`, {
|
|
151
|
-
cause: "zod-args-parser",
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
throw new Error(
|
|
156
|
-
`Unexpected argument "${argument_}": positional arguments are not allowed for subcommand "${results.subcommand}"`,
|
|
157
|
-
{ cause: "zod-args-parser" },
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// * Check for missing options - set defaults - add `source`
|
|
162
|
-
const subcommandObject = getSubcommandObject();
|
|
163
|
-
if (!subcommandObject) {
|
|
164
|
-
throw new Error(`Unknown subcommand: "${results.subcommand}"`, { cause: "zod-args-parser" });
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// Options
|
|
168
|
-
if (subcommandObject.options) {
|
|
169
|
-
if (!results.options) {
|
|
170
|
-
results.options = {};
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
for (const option of subcommandObject.options) {
|
|
174
|
-
// option already exists
|
|
175
|
-
if (results.options && option.name in results.options) continue;
|
|
176
|
-
|
|
177
|
-
const optional = isOptionalSchema(option.type);
|
|
178
|
-
const defaultValue = schemaDefaultValue(option.type);
|
|
179
|
-
|
|
180
|
-
if (optional) {
|
|
181
|
-
if (defaultValue === undefined) {
|
|
182
|
-
continue;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
results.options[option.name] = { name: option.name, schema: option.type, source: "default" };
|
|
186
|
-
continue;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
throw new Error(`Missing required option: ${transformOptionToArgument(option.name)}`, {
|
|
190
|
-
cause: "zod-args-parser",
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// Arguments
|
|
196
|
-
if (subcommandObject.arguments) {
|
|
197
|
-
if (!results.arguments) {
|
|
198
|
-
results.arguments = [];
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const currentArgumentCount = results.arguments.length ?? 0;
|
|
202
|
-
const subcommandArgumentCount = subcommandObject.arguments.length;
|
|
203
|
-
|
|
204
|
-
// missing arguments
|
|
205
|
-
if (currentArgumentCount < subcommandArgumentCount) {
|
|
206
|
-
for (let index = currentArgumentCount; index < subcommandArgumentCount; index++) {
|
|
207
|
-
const argumentType = subcommandObject.arguments[index].type;
|
|
208
|
-
const optional = isOptionalSchema(argumentType);
|
|
209
|
-
const defaultValue = schemaDefaultValue(argumentType);
|
|
210
|
-
|
|
211
|
-
if (optional) {
|
|
212
|
-
if (defaultValue === undefined) {
|
|
213
|
-
continue;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
if (!results.arguments) results.arguments = [];
|
|
217
|
-
|
|
218
|
-
results.arguments.push({ schema: argumentType, source: "default" });
|
|
219
|
-
continue;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
throw new Error(
|
|
223
|
-
`the ${generateOrdinalSuffix(index)} argument is required: "${subcommandObject.arguments[index].name}"`,
|
|
224
|
-
{ cause: "zod-args-parser" },
|
|
225
|
-
);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
if (subcommandObject.allowPositional && !results.positional) {
|
|
231
|
-
results.positional = [];
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
return results;
|
|
235
|
-
}
|
package/src/parser/safe-parse.ts
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import * as help from "../help-message/format-cli.js";
|
|
2
|
-
import { findSubcommand } from "./parse/parser-helpers.js";
|
|
3
|
-
import { unsafeParse, unsafeParseAsync } from "./unsafe-parse.js";
|
|
4
|
-
|
|
5
|
-
import type { Cli, NoSubcommand, PrintMethods, SafeParseResult, Subcommand } from "../types.js";
|
|
6
|
-
|
|
7
|
-
export function safeParse<T extends Subcommand[], U extends Cli>(
|
|
8
|
-
argsv: string[],
|
|
9
|
-
...parameters: [U, ...T]
|
|
10
|
-
): SafeParseResult<[...T, NoSubcommand & U]> {
|
|
11
|
-
const cliOptions = ("cliName" in parameters[0] ? parameters[0] : {}) as U;
|
|
12
|
-
const subcommandArray = parameters as Subcommand[];
|
|
13
|
-
|
|
14
|
-
type PrintTypes = PrintMethods<T[number]["name"]>;
|
|
15
|
-
type PrintCli = PrintTypes["printCliHelp"];
|
|
16
|
-
type PrintSubcommand = PrintTypes["printSubcommandHelp"];
|
|
17
|
-
|
|
18
|
-
const printCliHelp: PrintCli = style => help.printCliHelp(parameters, style);
|
|
19
|
-
|
|
20
|
-
const printSubcommandHelp: PrintSubcommand = (subCmdName, style) => {
|
|
21
|
-
const subcommand = findSubcommand(subCmdName, subcommandArray);
|
|
22
|
-
if (!subcommand) {
|
|
23
|
-
return console.error(`Cannot print help for subcommand "${subCmdName}" as it does not exist`);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
help.printSubcommandHelp(subcommand, style, cliOptions.cliName);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
try {
|
|
30
|
-
const data = unsafeParse(argsv, ...parameters);
|
|
31
|
-
// @ts-expect-error The operand of a 'delete' operator must be optional.
|
|
32
|
-
delete data.printCliHelp;
|
|
33
|
-
// @ts-expect-errorThe operand of a 'delete' operator must be optional.
|
|
34
|
-
delete data.printSubcommandHelp;
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
success: true,
|
|
38
|
-
data: data as Omit<typeof data, "printCliHelp" | "printSubcommandHelp">,
|
|
39
|
-
printCliHelp,
|
|
40
|
-
printSubcommandHelp,
|
|
41
|
-
} as SafeParseResult<[...T, NoSubcommand & U]>;
|
|
42
|
-
} catch (error) {
|
|
43
|
-
if (!(error instanceof Error) || error.cause !== "zod-args-parser") {
|
|
44
|
-
throw error;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
success: false,
|
|
49
|
-
error,
|
|
50
|
-
printCliHelp,
|
|
51
|
-
printSubcommandHelp,
|
|
52
|
-
} as SafeParseResult<[...T, NoSubcommand & U]>;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export async function safeParseAsync<T extends Subcommand[], U extends Cli>(
|
|
57
|
-
argsv: string[],
|
|
58
|
-
...parameters: [U, ...T]
|
|
59
|
-
): Promise<SafeParseResult<[...T, NoSubcommand & U]>> {
|
|
60
|
-
const cliOptions = ("cliName" in parameters[0] ? parameters[0] : {}) as U;
|
|
61
|
-
const subcommandArray = parameters as Subcommand[];
|
|
62
|
-
|
|
63
|
-
type PrintTypes = PrintMethods<T[number]["name"]>;
|
|
64
|
-
type PrintCli = PrintTypes["printCliHelp"];
|
|
65
|
-
type PrintSubcommand = PrintTypes["printSubcommandHelp"];
|
|
66
|
-
|
|
67
|
-
const printCliHelp: PrintCli = style => help.printCliHelp(parameters, style);
|
|
68
|
-
|
|
69
|
-
const printSubcommandHelp: PrintSubcommand = (subCmdName, style) => {
|
|
70
|
-
const subcommand = findSubcommand(subCmdName, subcommandArray);
|
|
71
|
-
if (!subcommand) {
|
|
72
|
-
return console.error(`Cannot print help for subcommand "${subCmdName}" as it does not exist`);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
help.printSubcommandHelp(subcommand, style, cliOptions.cliName);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
try {
|
|
79
|
-
const data = await unsafeParseAsync(argsv, ...parameters);
|
|
80
|
-
// @ts-expect-error The operand of a 'delete' operator must be optional.
|
|
81
|
-
delete data.printCliHelp;
|
|
82
|
-
// @ts-expect-errorThe operand of a 'delete' operator must be optional.
|
|
83
|
-
delete data.printSubcommandHelp;
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
success: true,
|
|
87
|
-
data: data as Omit<typeof data, "printCliHelp" | "printSubcommandHelp">,
|
|
88
|
-
printCliHelp,
|
|
89
|
-
printSubcommandHelp,
|
|
90
|
-
} as SafeParseResult<[...T, NoSubcommand & U]>;
|
|
91
|
-
} catch (error) {
|
|
92
|
-
if (!(error instanceof Error) || error.cause !== "zod-args-parser") {
|
|
93
|
-
throw error;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return {
|
|
97
|
-
success: false,
|
|
98
|
-
error,
|
|
99
|
-
printCliHelp,
|
|
100
|
-
printSubcommandHelp,
|
|
101
|
-
} as SafeParseResult<[...T, NoSubcommand & U]>;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import * as help from "../help-message/format-cli.js";
|
|
2
|
-
import { parse } from "./parse/parse.js";
|
|
3
|
-
import { findSubcommand } from "./parse/parser-helpers.js";
|
|
4
|
-
import { validate } from "./validate/validate.js";
|
|
5
|
-
|
|
6
|
-
import type { Cli, HelpMessageStyle, NoSubcommand, Subcommand, UnsafeParseResult } from "../types.js";
|
|
7
|
-
|
|
8
|
-
export function unsafeParse<T extends Subcommand[], U extends Cli>(
|
|
9
|
-
argv: string[],
|
|
10
|
-
...parameters: [U, ...T]
|
|
11
|
-
): UnsafeParseResult<[...T, NoSubcommand & U]> {
|
|
12
|
-
const cliOptions = ("cliName" in parameters[0] ? parameters[0] : {}) as U;
|
|
13
|
-
const subcommandArray = parameters as unknown as T;
|
|
14
|
-
|
|
15
|
-
// Parse
|
|
16
|
-
const parsedData = parse(argv, ...parameters);
|
|
17
|
-
|
|
18
|
-
const subcommandObject = findSubcommand(parsedData.subcommand, subcommandArray);
|
|
19
|
-
if (!subcommandObject) {
|
|
20
|
-
throw new Error(`Subcommand "${parsedData.subcommand}" does not exist`, { cause: "zod-args-parser" });
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Fire preValidation hook
|
|
24
|
-
if (subcommandObject.preValidation) {
|
|
25
|
-
subcommandObject.preValidation(parsedData);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Validate
|
|
29
|
-
const validateResult = validate(parsedData);
|
|
30
|
-
|
|
31
|
-
Object.assign(validateResult, {
|
|
32
|
-
printCliHelp(style?: Partial<HelpMessageStyle>) {
|
|
33
|
-
help.printCliHelp(parameters, style);
|
|
34
|
-
},
|
|
35
|
-
printSubcommandHelp(subCmdName: string, style?: Partial<HelpMessageStyle>) {
|
|
36
|
-
const subcommandObject = findSubcommand(subCmdName, subcommandArray);
|
|
37
|
-
if (!subcommandObject) {
|
|
38
|
-
console.error(`Cannot print help for subcommand "${subCmdName}" as it does not exist`);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
help.printSubcommandHelp(subcommandObject, style, cliOptions.cliName);
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// Fire action
|
|
47
|
-
if (subcommandObject.action) {
|
|
48
|
-
subcommandObject.action(validateResult);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return validateResult as UnsafeParseResult<[...T, NoSubcommand & U]>;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export async function unsafeParseAsync<T extends Subcommand[], U extends Cli>(
|
|
55
|
-
argv: string[],
|
|
56
|
-
...parameters: [U, ...T]
|
|
57
|
-
): Promise<UnsafeParseResult<[...T, NoSubcommand & U]>> {
|
|
58
|
-
const cliOptions = ("cliName" in parameters[0] ? parameters[0] : {}) as U;
|
|
59
|
-
const subcommandArray = parameters as unknown as T;
|
|
60
|
-
|
|
61
|
-
// Parse
|
|
62
|
-
const parsedData = parse(argv, ...parameters);
|
|
63
|
-
|
|
64
|
-
const subcommandObject = findSubcommand(parsedData.subcommand, subcommandArray);
|
|
65
|
-
if (!subcommandObject) {
|
|
66
|
-
throw new Error(`Subcommand "${parsedData.subcommand}" does not exist`, { cause: "zod-args-parser" });
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Fire preValidation hook
|
|
70
|
-
if (subcommandObject.preValidation) {
|
|
71
|
-
await subcommandObject.preValidation(parsedData);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Validate
|
|
75
|
-
const validateResult = validate(parsedData);
|
|
76
|
-
|
|
77
|
-
Object.assign(validateResult, {
|
|
78
|
-
printCliHelp(style?: Partial<HelpMessageStyle>) {
|
|
79
|
-
help.printCliHelp(parameters, style);
|
|
80
|
-
},
|
|
81
|
-
printSubcommandHelp(subCmdName: string, style?: Partial<HelpMessageStyle>) {
|
|
82
|
-
const subcommandObject = findSubcommand(subCmdName, subcommandArray);
|
|
83
|
-
if (!subcommandObject) {
|
|
84
|
-
console.error(`Cannot print help for subcommand "${subCmdName}" as it does not exist`);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
help.printSubcommandHelp(subcommandObject, style, cliOptions.cliName);
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
// Fire action
|
|
93
|
-
if (subcommandObject.action) {
|
|
94
|
-
await subcommandObject.action(validateResult);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return validateResult as UnsafeParseResult<[...T, NoSubcommand & U]>;
|
|
98
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { Argument, Option, Prettify, Schema, Subcommand, ToOptional, ZodInferOutput } from "../../types.js";
|
|
2
|
-
import type { ParseResult } from "../parse/parse-types.js";
|
|
3
|
-
|
|
4
|
-
type OptionsArray2RecordType<T extends Option[] | undefined> = T extends Option[]
|
|
5
|
-
? ToOptional<{ [K in T[number]["name"]]: ZodInferOutput<Extract<T[number], { name: K }>["type"]> }>
|
|
6
|
-
: object;
|
|
7
|
-
|
|
8
|
-
type ArgumentsArray2ArrayType<T extends Argument[] | undefined> = T extends Argument[]
|
|
9
|
-
? { [K in keyof T]: T[K] extends { type: Schema } ? ZodInferOutput<T[K]["type"]> : never }
|
|
10
|
-
: never;
|
|
11
|
-
|
|
12
|
-
export type ValidateResult<S extends Partial<Subcommand>[]> = {
|
|
13
|
-
[K in keyof S]: Prettify<{
|
|
14
|
-
subcommand: S[K]["name"] extends string ? S[K]["name"] : undefined;
|
|
15
|
-
arguments: ArgumentsArray2ArrayType<S[K]["arguments"]>;
|
|
16
|
-
positional: S[K]["allowPositional"] extends true ? string[] : never;
|
|
17
|
-
options: S[K]["options"] extends Option[] ? OptionsArray2RecordType<S[K]["options"]> : never;
|
|
18
|
-
ctx: ParseResult<S>;
|
|
19
|
-
}>;
|
|
20
|
-
}[number];
|