zod-args-parser 1.2.8 → 2.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +525 -588
- package/lib/cjs/autocomplete-scripts/bash-autocomplete-script.cjs +2 -0
- package/lib/cjs/autocomplete-scripts/bash-autocomplete-script.cjs.map +1 -0
- package/lib/cjs/autocomplete-scripts/powershell-autocomplete-script.cjs +2 -0
- package/lib/cjs/autocomplete-scripts/powershell-autocomplete-script.cjs.map +1 -0
- package/lib/cjs/autocomplete-scripts/zsh-autocomplete-script.cjs +42 -0
- package/lib/cjs/autocomplete-scripts/zsh-autocomplete-script.cjs.map +1 -0
- package/lib/cjs/coerce/coerce-methods.cjs +2 -0
- package/lib/cjs/coerce/coerce-methods.cjs.map +1 -0
- package/lib/cjs/coerce/string-to-array.cjs +2 -0
- package/lib/cjs/coerce/string-to-array.cjs.map +1 -0
- package/lib/cjs/coerce/string-to-primitive.cjs +2 -0
- package/lib/cjs/coerce/string-to-primitive.cjs.map +1 -0
- package/lib/cjs/coerce/string-to-set.cjs +2 -0
- package/lib/cjs/coerce/string-to-set.cjs.map +1 -0
- package/lib/cjs/definitions/define-arguments.cjs +2 -0
- package/lib/cjs/definitions/define-arguments.cjs.map +1 -0
- package/lib/cjs/definitions/define-cli.cjs +2 -0
- package/lib/cjs/definitions/define-cli.cjs.map +1 -0
- package/lib/cjs/definitions/define-options.cjs +2 -0
- package/lib/cjs/definitions/define-options.cjs.map +1 -0
- package/lib/cjs/definitions/define-subcommand.cjs +2 -0
- package/lib/cjs/definitions/define-subcommand.cjs.map +1 -0
- package/lib/cjs/definitions/validate-cli-definition.cjs +2 -0
- package/lib/cjs/definitions/validate-cli-definition.cjs.map +1 -0
- package/lib/cjs/help-message/format-arguments.cjs +2 -0
- package/lib/cjs/help-message/format-arguments.cjs.map +1 -0
- package/lib/cjs/help-message/format-options.cjs +2 -0
- package/lib/cjs/help-message/format-options.cjs.map +1 -0
- package/lib/cjs/help-message/format-subcommands.cjs +2 -0
- package/lib/cjs/help-message/format-subcommands.cjs.map +1 -0
- package/lib/cjs/help-message/generate-for-cli.cjs +2 -0
- package/lib/cjs/help-message/generate-for-cli.cjs.map +1 -0
- package/lib/cjs/help-message/generate-for-subcommand.cjs +2 -0
- package/lib/cjs/help-message/generate-for-subcommand.cjs.map +1 -0
- package/lib/cjs/help-message/print-help.cjs +2 -0
- package/lib/cjs/help-message/print-help.cjs.map +1 -0
- package/lib/cjs/help-message/set-defaults.cjs +2 -0
- package/lib/cjs/help-message/set-defaults.cjs.map +1 -0
- package/lib/cjs/help-message/styles.cjs +2 -0
- package/lib/cjs/help-message/styles.cjs.map +1 -0
- package/lib/cjs/help-message/terminal-markdown.cjs +2 -0
- package/lib/cjs/help-message/terminal-markdown.cjs.map +1 -0
- package/lib/cjs/index.cjs +2 -0
- package/lib/cjs/index.cjs.map +1 -0
- package/lib/cjs/markdown/generate-markdown.cjs +2 -0
- package/lib/cjs/markdown/generate-markdown.cjs.map +1 -0
- package/lib/cjs/metadata/arguments-metadata.cjs +2 -0
- package/lib/cjs/metadata/arguments-metadata.cjs.map +1 -0
- package/lib/cjs/metadata/cli-metadata.cjs +2 -0
- package/lib/cjs/metadata/cli-metadata.cjs.map +1 -0
- package/lib/cjs/metadata/options-metadata.cjs +2 -0
- package/lib/cjs/metadata/options-metadata.cjs.map +1 -0
- package/lib/cjs/metadata/subcommands-metadata.cjs +2 -0
- package/lib/cjs/metadata/subcommands-metadata.cjs.map +1 -0
- package/lib/cjs/parse/context/cli-context-builder.cjs +2 -0
- package/lib/cjs/parse/context/cli-context-builder.cjs.map +1 -0
- package/lib/cjs/parse/context/object-context-builder.cjs +2 -0
- package/lib/cjs/parse/context/object-context-builder.cjs.map +1 -0
- package/lib/cjs/parse/parser-utilities.cjs +2 -0
- package/lib/cjs/parse/parser-utilities.cjs.map +1 -0
- package/lib/cjs/parse/safe-parse.cjs +2 -0
- package/lib/cjs/parse/safe-parse.cjs.map +1 -0
- package/lib/cjs/parse/validation/validate-context.cjs +2 -0
- package/lib/cjs/parse/validation/validate-context.cjs.map +1 -0
- package/lib/cjs/parse/validation/validators/arguments.cjs +2 -0
- package/lib/cjs/parse/validation/validators/arguments.cjs.map +1 -0
- package/lib/cjs/parse/validation/validators/conflict.cjs +2 -0
- package/lib/cjs/parse/validation/validators/conflict.cjs.map +1 -0
- package/lib/cjs/parse/validation/validators/exclusive.cjs +2 -0
- package/lib/cjs/parse/validation/validators/exclusive.cjs.map +1 -0
- package/lib/cjs/parse/validation/validators/explicitly-passed.cjs +2 -0
- package/lib/cjs/parse/validation/validators/explicitly-passed.cjs.map +1 -0
- package/lib/cjs/parse/validation/validators/options.cjs +2 -0
- package/lib/cjs/parse/validation/validators/options.cjs.map +1 -0
- package/lib/cjs/parse/validation/validators/requires.cjs +2 -0
- package/lib/cjs/parse/validation/validators/requires.cjs.map +1 -0
- package/lib/cjs/utilities.cjs +2 -0
- package/lib/cjs/utilities.cjs.map +1 -0
- package/lib/esm/autocomplete-scripts/bash-autocomplete-script.js +2 -0
- package/lib/esm/autocomplete-scripts/bash-autocomplete-script.js.map +1 -0
- package/lib/esm/autocomplete-scripts/powershell-autocomplete-script.js +2 -0
- package/lib/esm/autocomplete-scripts/powershell-autocomplete-script.js.map +1 -0
- package/lib/esm/autocomplete-scripts/zsh-autocomplete-script.js +42 -0
- package/lib/esm/autocomplete-scripts/zsh-autocomplete-script.js.map +1 -0
- package/lib/esm/coerce/coerce-methods.js +2 -0
- package/lib/esm/coerce/coerce-methods.js.map +1 -0
- package/lib/esm/coerce/string-to-array.js +2 -0
- package/lib/esm/coerce/string-to-array.js.map +1 -0
- package/lib/esm/coerce/string-to-primitive.js +2 -0
- package/lib/esm/coerce/string-to-primitive.js.map +1 -0
- package/lib/esm/coerce/string-to-set.js +2 -0
- package/lib/esm/coerce/string-to-set.js.map +1 -0
- package/lib/esm/definitions/define-arguments.js +2 -0
- package/lib/esm/definitions/define-arguments.js.map +1 -0
- package/lib/esm/definitions/define-cli.js +2 -0
- package/lib/esm/definitions/define-cli.js.map +1 -0
- package/lib/esm/definitions/define-options.js +2 -0
- package/lib/esm/definitions/define-options.js.map +1 -0
- package/lib/esm/definitions/define-subcommand.js +2 -0
- package/lib/esm/definitions/define-subcommand.js.map +1 -0
- package/lib/esm/definitions/validate-cli-definition.js +2 -0
- package/lib/esm/definitions/validate-cli-definition.js.map +1 -0
- package/lib/esm/help-message/format-arguments.js +2 -0
- package/lib/esm/help-message/format-arguments.js.map +1 -0
- package/lib/esm/help-message/format-options.js +2 -0
- package/lib/esm/help-message/format-options.js.map +1 -0
- package/lib/esm/help-message/format-subcommands.js +2 -0
- package/lib/esm/help-message/format-subcommands.js.map +1 -0
- package/lib/esm/help-message/generate-for-cli.js +2 -0
- package/lib/esm/help-message/generate-for-cli.js.map +1 -0
- package/lib/esm/help-message/generate-for-subcommand.js +2 -0
- package/lib/esm/help-message/generate-for-subcommand.js.map +1 -0
- package/lib/esm/help-message/print-help.js +2 -0
- package/lib/esm/help-message/print-help.js.map +1 -0
- package/lib/esm/help-message/set-defaults.js +2 -0
- package/lib/esm/help-message/set-defaults.js.map +1 -0
- package/lib/esm/help-message/styles.js +2 -0
- package/lib/esm/help-message/styles.js.map +1 -0
- package/lib/esm/help-message/terminal-markdown.js +2 -0
- package/lib/esm/help-message/terminal-markdown.js.map +1 -0
- package/lib/esm/index.js +2 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/markdown/generate-markdown.js +2 -0
- package/lib/esm/markdown/generate-markdown.js.map +1 -0
- package/lib/esm/metadata/arguments-metadata.js +2 -0
- package/lib/esm/metadata/arguments-metadata.js.map +1 -0
- package/lib/esm/metadata/cli-metadata.js +2 -0
- package/lib/esm/metadata/cli-metadata.js.map +1 -0
- package/lib/esm/metadata/options-metadata.js +2 -0
- package/lib/esm/metadata/options-metadata.js.map +1 -0
- package/lib/esm/metadata/subcommands-metadata.js +2 -0
- package/lib/esm/metadata/subcommands-metadata.js.map +1 -0
- package/lib/esm/parse/context/cli-context-builder.js +2 -0
- package/lib/esm/parse/context/cli-context-builder.js.map +1 -0
- package/lib/esm/parse/context/object-context-builder.js +2 -0
- package/lib/esm/parse/context/object-context-builder.js.map +1 -0
- package/lib/esm/parse/parser-utilities.js +2 -0
- package/lib/esm/parse/parser-utilities.js.map +1 -0
- package/lib/esm/parse/safe-parse.js +2 -0
- package/lib/esm/parse/safe-parse.js.map +1 -0
- package/lib/esm/parse/validation/validate-context.js +2 -0
- package/lib/esm/parse/validation/validate-context.js.map +1 -0
- package/lib/esm/parse/validation/validators/arguments.js +2 -0
- package/lib/esm/parse/validation/validators/arguments.js.map +1 -0
- package/lib/esm/parse/validation/validators/conflict.js +2 -0
- package/lib/esm/parse/validation/validators/conflict.js.map +1 -0
- package/lib/esm/parse/validation/validators/exclusive.js +2 -0
- package/lib/esm/parse/validation/validators/exclusive.js.map +1 -0
- package/lib/esm/parse/validation/validators/explicitly-passed.js +2 -0
- package/lib/esm/parse/validation/validators/explicitly-passed.js.map +1 -0
- package/lib/esm/parse/validation/validators/options.js +2 -0
- package/lib/esm/parse/validation/validators/options.js.map +1 -0
- package/lib/esm/parse/validation/validators/requires.js +2 -0
- package/lib/esm/parse/validation/validators/requires.js.map +1 -0
- package/lib/esm/utilities.js +2 -0
- package/lib/esm/utilities.js.map +1 -0
- package/lib/iife/index.js +2 -0
- package/lib/iife/index.js.map +1 -0
- package/lib/mjs/autocomplete-scripts/bash-autocomplete-script.mjs +2 -0
- package/lib/mjs/autocomplete-scripts/bash-autocomplete-script.mjs.map +1 -0
- package/lib/mjs/autocomplete-scripts/powershell-autocomplete-script.mjs +2 -0
- package/lib/mjs/autocomplete-scripts/powershell-autocomplete-script.mjs.map +1 -0
- package/lib/mjs/autocomplete-scripts/zsh-autocomplete-script.mjs +42 -0
- package/lib/mjs/autocomplete-scripts/zsh-autocomplete-script.mjs.map +1 -0
- package/lib/mjs/coerce/coerce-methods.mjs +2 -0
- package/lib/mjs/coerce/coerce-methods.mjs.map +1 -0
- package/lib/mjs/coerce/string-to-array.mjs +2 -0
- package/lib/mjs/coerce/string-to-array.mjs.map +1 -0
- package/lib/mjs/coerce/string-to-primitive.mjs +2 -0
- package/lib/mjs/coerce/string-to-primitive.mjs.map +1 -0
- package/lib/mjs/coerce/string-to-set.mjs +2 -0
- package/lib/mjs/coerce/string-to-set.mjs.map +1 -0
- package/lib/mjs/definitions/define-arguments.mjs +2 -0
- package/lib/mjs/definitions/define-arguments.mjs.map +1 -0
- package/lib/mjs/definitions/define-cli.mjs +2 -0
- package/lib/mjs/definitions/define-cli.mjs.map +1 -0
- package/lib/mjs/definitions/define-options.mjs +2 -0
- package/lib/mjs/definitions/define-options.mjs.map +1 -0
- package/lib/mjs/definitions/define-subcommand.mjs +2 -0
- package/lib/mjs/definitions/define-subcommand.mjs.map +1 -0
- package/lib/mjs/definitions/validate-cli-definition.mjs +2 -0
- package/lib/mjs/definitions/validate-cli-definition.mjs.map +1 -0
- package/lib/mjs/help-message/format-arguments.mjs +2 -0
- package/lib/mjs/help-message/format-arguments.mjs.map +1 -0
- package/lib/mjs/help-message/format-options.mjs +2 -0
- package/lib/mjs/help-message/format-options.mjs.map +1 -0
- package/lib/mjs/help-message/format-subcommands.mjs +2 -0
- package/lib/mjs/help-message/format-subcommands.mjs.map +1 -0
- package/lib/mjs/help-message/generate-for-cli.mjs +2 -0
- package/lib/mjs/help-message/generate-for-cli.mjs.map +1 -0
- package/lib/mjs/help-message/generate-for-subcommand.mjs +2 -0
- package/lib/mjs/help-message/generate-for-subcommand.mjs.map +1 -0
- package/lib/mjs/help-message/print-help.mjs +2 -0
- package/lib/mjs/help-message/print-help.mjs.map +1 -0
- package/lib/mjs/help-message/set-defaults.mjs +2 -0
- package/lib/mjs/help-message/set-defaults.mjs.map +1 -0
- package/lib/mjs/help-message/styles.mjs +2 -0
- package/lib/mjs/help-message/styles.mjs.map +1 -0
- package/lib/mjs/help-message/terminal-markdown.mjs +2 -0
- package/lib/mjs/help-message/terminal-markdown.mjs.map +1 -0
- package/lib/mjs/index.mjs +2 -0
- package/lib/mjs/index.mjs.map +1 -0
- package/lib/mjs/markdown/generate-markdown.mjs +2 -0
- package/lib/mjs/markdown/generate-markdown.mjs.map +1 -0
- package/lib/mjs/metadata/arguments-metadata.mjs +2 -0
- package/lib/mjs/metadata/arguments-metadata.mjs.map +1 -0
- package/lib/mjs/metadata/cli-metadata.mjs +2 -0
- package/lib/mjs/metadata/cli-metadata.mjs.map +1 -0
- package/lib/mjs/metadata/options-metadata.mjs +2 -0
- package/lib/mjs/metadata/options-metadata.mjs.map +1 -0
- package/lib/mjs/metadata/subcommands-metadata.mjs +2 -0
- package/lib/mjs/metadata/subcommands-metadata.mjs.map +1 -0
- package/lib/mjs/parse/context/cli-context-builder.mjs +2 -0
- package/lib/mjs/parse/context/cli-context-builder.mjs.map +1 -0
- package/lib/mjs/parse/context/object-context-builder.mjs +2 -0
- package/lib/mjs/parse/context/object-context-builder.mjs.map +1 -0
- package/lib/mjs/parse/parser-utilities.mjs +2 -0
- package/lib/mjs/parse/parser-utilities.mjs.map +1 -0
- package/lib/mjs/parse/safe-parse.mjs +2 -0
- package/lib/mjs/parse/safe-parse.mjs.map +1 -0
- package/lib/mjs/parse/validation/validate-context.mjs +2 -0
- package/lib/mjs/parse/validation/validate-context.mjs.map +1 -0
- package/lib/mjs/parse/validation/validators/arguments.mjs +2 -0
- package/lib/mjs/parse/validation/validators/arguments.mjs.map +1 -0
- package/lib/mjs/parse/validation/validators/conflict.mjs +2 -0
- package/lib/mjs/parse/validation/validators/conflict.mjs.map +1 -0
- package/lib/mjs/parse/validation/validators/exclusive.mjs +2 -0
- package/lib/mjs/parse/validation/validators/exclusive.mjs.map +1 -0
- package/lib/mjs/parse/validation/validators/explicitly-passed.mjs +2 -0
- package/lib/mjs/parse/validation/validators/explicitly-passed.mjs.map +1 -0
- package/lib/mjs/parse/validation/validators/options.mjs +2 -0
- package/lib/mjs/parse/validation/validators/options.mjs.map +1 -0
- package/lib/mjs/parse/validation/validators/requires.mjs +2 -0
- package/lib/mjs/parse/validation/validators/requires.mjs.map +1 -0
- package/lib/mjs/utilities.mjs +2 -0
- package/lib/mjs/utilities.mjs.map +1 -0
- package/lib/typescript/autocomplete-scripts/bash-autocomplete-script.d.ts +2 -2
- package/lib/typescript/autocomplete-scripts/bash-autocomplete-script.d.ts.map +1 -1
- package/lib/typescript/autocomplete-scripts/powershell-autocomplete-script.d.ts +2 -2
- package/lib/typescript/autocomplete-scripts/powershell-autocomplete-script.d.ts.map +1 -1
- package/lib/typescript/autocomplete-scripts/zsh-autocomplete-script.d.ts +2 -2
- package/lib/typescript/autocomplete-scripts/zsh-autocomplete-script.d.ts.map +1 -1
- package/lib/typescript/coerce/coerce-methods.d.ts +20 -0
- package/lib/typescript/coerce/coerce-methods.d.ts.map +1 -0
- package/lib/typescript/coerce/string-to-array.d.ts +6 -0
- package/lib/typescript/coerce/string-to-array.d.ts.map +1 -0
- package/lib/typescript/coerce/string-to-primitive.d.ts +5 -0
- package/lib/typescript/coerce/string-to-primitive.d.ts.map +1 -0
- package/lib/typescript/coerce/string-to-set.d.ts +6 -0
- package/lib/typescript/coerce/string-to-set.d.ts.map +1 -0
- package/lib/typescript/definitions/define-arguments.d.ts +7 -0
- package/lib/typescript/definitions/define-arguments.d.ts.map +1 -0
- package/lib/typescript/definitions/define-cli.d.ts +24 -0
- package/lib/typescript/definitions/define-cli.d.ts.map +1 -0
- package/lib/typescript/definitions/define-options.d.ts +7 -0
- package/lib/typescript/definitions/define-options.d.ts.map +1 -0
- package/lib/typescript/definitions/define-subcommand.d.ts +17 -0
- package/lib/typescript/definitions/define-subcommand.d.ts.map +1 -0
- package/lib/typescript/definitions/validate-cli-definition.d.ts +4 -0
- package/lib/typescript/definitions/validate-cli-definition.d.ts.map +1 -0
- package/lib/typescript/help-message/format-arguments.d.ts +3 -3
- package/lib/typescript/help-message/format-arguments.d.ts.map +1 -1
- package/lib/typescript/help-message/format-options.d.ts +3 -3
- package/lib/typescript/help-message/format-options.d.ts.map +1 -1
- package/lib/typescript/help-message/format-subcommands.d.ts +3 -3
- package/lib/typescript/help-message/format-subcommands.d.ts.map +1 -1
- package/lib/typescript/help-message/generate-for-cli.d.ts +8 -0
- package/lib/typescript/help-message/generate-for-cli.d.ts.map +1 -0
- package/lib/typescript/help-message/generate-for-subcommand.d.ts +4 -0
- package/lib/typescript/help-message/generate-for-subcommand.d.ts.map +1 -0
- package/lib/typescript/help-message/print-help.d.ts +5 -0
- package/lib/typescript/help-message/print-help.d.ts.map +1 -0
- package/lib/typescript/help-message/set-defaults.d.ts +4 -0
- package/lib/typescript/help-message/set-defaults.d.ts.map +1 -0
- package/lib/typescript/help-message/styles.d.ts +30 -106
- package/lib/typescript/help-message/styles.d.ts.map +1 -1
- package/lib/typescript/help-message/terminal-markdown.d.ts +3 -0
- package/lib/typescript/help-message/terminal-markdown.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +23 -35
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/markdown/generate-markdown.d.ts +2 -2
- package/lib/typescript/markdown/generate-markdown.d.ts.map +1 -1
- package/lib/typescript/metadata/arguments-metadata.d.ts +4 -0
- package/lib/typescript/metadata/arguments-metadata.d.ts.map +1 -0
- package/lib/typescript/metadata/cli-metadata.d.ts +4 -0
- package/lib/typescript/metadata/cli-metadata.d.ts.map +1 -0
- package/lib/typescript/metadata/options-metadata.d.ts +4 -0
- package/lib/typescript/metadata/options-metadata.d.ts.map +1 -0
- package/lib/typescript/metadata/subcommands-metadata.d.ts +4 -0
- package/lib/typescript/metadata/subcommands-metadata.d.ts.map +1 -0
- package/lib/typescript/parse/context/cli-context-builder.d.ts +9 -0
- package/lib/typescript/parse/context/cli-context-builder.d.ts.map +1 -0
- package/lib/typescript/parse/context/object-context-builder.d.ts +6 -0
- package/lib/typescript/parse/context/object-context-builder.d.ts.map +1 -0
- package/lib/typescript/{parser/parse/parser-helpers.d.ts → parse/parser-utilities.d.ts} +18 -9
- package/lib/typescript/parse/parser-utilities.d.ts.map +1 -0
- package/lib/typescript/parse/safe-parse.d.ts +5 -0
- package/lib/typescript/parse/safe-parse.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validate-context.d.ts +6 -0
- package/lib/typescript/parse/validation/validate-context.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validators/arguments.d.ts +12 -0
- package/lib/typescript/parse/validation/validators/arguments.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validators/conflict.d.ts +16 -0
- package/lib/typescript/parse/validation/validators/conflict.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validators/exclusive.d.ts +16 -0
- package/lib/typescript/parse/validation/validators/exclusive.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validators/explicitly-passed.d.ts +5 -0
- package/lib/typescript/parse/validation/validators/explicitly-passed.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validators/options.d.ts +12 -0
- package/lib/typescript/parse/validation/validators/options.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validators/requires.d.ts +18 -0
- package/lib/typescript/parse/validation/validators/requires.d.ts.map +1 -0
- package/lib/typescript/types/context-types.d.ts +135 -0
- package/lib/typescript/types/context-types.d.ts.map +1 -0
- package/lib/typescript/types/definitions-types.d.ts +294 -0
- package/lib/typescript/types/definitions-types.d.ts.map +1 -0
- package/lib/typescript/types/help-message-types.d.ts +134 -0
- package/lib/typescript/types/help-message-types.d.ts.map +1 -0
- package/lib/typescript/types/io-types.d.ts +96 -0
- package/lib/typescript/types/io-types.d.ts.map +1 -0
- package/lib/typescript/types/metadata-types.d.ts +75 -0
- package/lib/typescript/types/metadata-types.d.ts.map +1 -0
- package/lib/typescript/types/schema-types.d.ts +6 -0
- package/lib/typescript/types/schema-types.d.ts.map +1 -0
- package/lib/typescript/types/types.d.ts +61 -0
- package/lib/typescript/types/types.d.ts.map +1 -0
- package/lib/typescript/types/utilities-types.d.ts +17 -0
- package/lib/typescript/types/utilities-types.d.ts.map +1 -0
- package/lib/typescript/utilities.d.ts +24 -10
- package/lib/typescript/utilities.d.ts.map +1 -1
- package/package.json +29 -26
- package/src/autocomplete-scripts/bash-autocomplete-script.ts +13 -9
- package/src/autocomplete-scripts/powershell-autocomplete-script.ts +21 -13
- package/src/autocomplete-scripts/zsh-autocomplete-script.ts +27 -23
- package/src/coerce/coerce-methods.ts +75 -0
- package/src/coerce/string-to-array.ts +18 -0
- package/src/coerce/string-to-primitive.ts +31 -0
- package/src/coerce/string-to-set.ts +15 -0
- package/src/definitions/define-arguments.ts +10 -0
- package/src/definitions/define-cli.ts +105 -0
- package/src/definitions/define-options.ts +12 -0
- package/src/definitions/define-subcommand.ts +57 -0
- package/src/definitions/validate-cli-definition.ts +331 -0
- package/src/help-message/format-arguments.ts +57 -33
- package/src/help-message/format-options.ts +59 -34
- package/src/help-message/format-subcommands.ts +43 -21
- package/src/help-message/generate-for-cli.ts +114 -0
- package/src/help-message/generate-for-subcommand.ts +32 -0
- package/src/help-message/print-help.ts +13 -0
- package/src/help-message/set-defaults.ts +34 -0
- package/src/help-message/styles.ts +148 -103
- package/src/help-message/terminal-markdown.ts +147 -0
- package/src/index.ts +28 -97
- package/src/markdown/generate-markdown.ts +47 -58
- package/src/metadata/arguments-metadata.ts +28 -0
- package/src/metadata/cli-metadata.ts +26 -0
- package/src/metadata/options-metadata.ts +38 -0
- package/src/metadata/subcommands-metadata.ts +35 -0
- package/src/parse/context/cli-context-builder.ts +246 -0
- package/src/parse/context/object-context-builder.ts +63 -0
- package/src/{parser/parse/parser-helpers.ts → parse/parser-utilities.ts} +46 -25
- package/src/parse/safe-parse.ts +76 -0
- package/src/parse/validation/validate-context.ts +23 -0
- package/src/parse/validation/validators/arguments.ts +59 -0
- package/src/parse/validation/validators/conflict.ts +68 -0
- package/src/parse/validation/validators/exclusive.ts +70 -0
- package/src/parse/validation/validators/explicitly-passed.ts +15 -0
- package/src/parse/validation/validators/options.ts +59 -0
- package/src/parse/validation/validators/requires.ts +82 -0
- package/src/types/context-types.ts +171 -0
- package/src/types/definitions-types.ts +340 -0
- package/src/types/help-message-types.ts +153 -0
- package/src/types/io-types.ts +131 -0
- package/src/types/metadata-types.ts +104 -0
- package/src/types/schema-types.ts +9 -0
- package/src/types/types.ts +72 -0
- package/src/types/utilities-types.ts +26 -0
- package/src/utilities.ts +200 -23
- package/lib/commonjs/autocomplete-scripts/bash-autocomplete-script.cjs +0 -42
- package/lib/commonjs/autocomplete-scripts/bash-autocomplete-script.cjs.map +0 -1
- package/lib/commonjs/autocomplete-scripts/powershell-autocomplete-script.cjs +0 -31
- package/lib/commonjs/autocomplete-scripts/powershell-autocomplete-script.cjs.map +0 -1
- package/lib/commonjs/autocomplete-scripts/zsh-autocomplete-script.cjs +0 -41
- package/lib/commonjs/autocomplete-scripts/zsh-autocomplete-script.cjs.map +0 -1
- package/lib/commonjs/help-message/format-arguments.cjs +0 -1
- package/lib/commonjs/help-message/format-arguments.cjs.map +0 -1
- package/lib/commonjs/help-message/format-cli.cjs +0 -1
- package/lib/commonjs/help-message/format-cli.cjs.map +0 -1
- package/lib/commonjs/help-message/format-options.cjs +0 -1
- package/lib/commonjs/help-message/format-options.cjs.map +0 -1
- package/lib/commonjs/help-message/format-subcommands.cjs +0 -1
- package/lib/commonjs/help-message/format-subcommands.cjs.map +0 -1
- package/lib/commonjs/help-message/styles.cjs +0 -1
- package/lib/commonjs/help-message/styles.cjs.map +0 -1
- package/lib/commonjs/index.cjs +0 -1
- package/lib/commonjs/index.cjs.map +0 -1
- package/lib/commonjs/markdown/generate-markdown.cjs +0 -1
- package/lib/commonjs/markdown/generate-markdown.cjs.map +0 -1
- package/lib/commonjs/metadata/get-arguments-metadata.cjs +0 -1
- package/lib/commonjs/metadata/get-arguments-metadata.cjs.map +0 -1
- package/lib/commonjs/metadata/get-cli-metadata.cjs +0 -1
- package/lib/commonjs/metadata/get-cli-metadata.cjs.map +0 -1
- package/lib/commonjs/metadata/get-options-metadata.cjs +0 -1
- package/lib/commonjs/metadata/get-options-metadata.cjs.map +0 -1
- package/lib/commonjs/metadata/get-subcommands-metadata.cjs +0 -1
- package/lib/commonjs/metadata/get-subcommands-metadata.cjs.map +0 -1
- package/lib/commonjs/parser/parse/parse.cjs +0 -1
- package/lib/commonjs/parser/parse/parse.cjs.map +0 -1
- package/lib/commonjs/parser/parse/parser-helpers.cjs +0 -1
- package/lib/commonjs/parser/parse/parser-helpers.cjs.map +0 -1
- package/lib/commonjs/parser/safe-parse.cjs +0 -1
- package/lib/commonjs/parser/safe-parse.cjs.map +0 -1
- package/lib/commonjs/parser/unsafe-parse.cjs +0 -1
- package/lib/commonjs/parser/unsafe-parse.cjs.map +0 -1
- package/lib/commonjs/parser/validate/validate-type.cjs +0 -1
- package/lib/commonjs/parser/validate/validate-type.cjs.map +0 -1
- package/lib/commonjs/parser/validate/validate.cjs +0 -1
- package/lib/commonjs/parser/validate/validate.cjs.map +0 -1
- package/lib/commonjs/utilities.cjs +0 -1
- package/lib/commonjs/utilities.cjs.map +0 -1
- package/lib/commonjs/zod-utilities.cjs +0 -1
- package/lib/commonjs/zod-utilities.cjs.map +0 -1
- package/lib/module/autocomplete-scripts/bash-autocomplete-script.mjs +0 -42
- package/lib/module/autocomplete-scripts/bash-autocomplete-script.mjs.map +0 -1
- package/lib/module/autocomplete-scripts/powershell-autocomplete-script.mjs +0 -31
- package/lib/module/autocomplete-scripts/powershell-autocomplete-script.mjs.map +0 -1
- package/lib/module/autocomplete-scripts/zsh-autocomplete-script.mjs +0 -41
- package/lib/module/autocomplete-scripts/zsh-autocomplete-script.mjs.map +0 -1
- package/lib/module/help-message/format-arguments.mjs +0 -1
- package/lib/module/help-message/format-arguments.mjs.map +0 -1
- package/lib/module/help-message/format-cli.mjs +0 -1
- package/lib/module/help-message/format-cli.mjs.map +0 -1
- package/lib/module/help-message/format-options.mjs +0 -1
- package/lib/module/help-message/format-options.mjs.map +0 -1
- package/lib/module/help-message/format-subcommands.mjs +0 -1
- package/lib/module/help-message/format-subcommands.mjs.map +0 -1
- package/lib/module/help-message/styles.mjs +0 -1
- package/lib/module/help-message/styles.mjs.map +0 -1
- package/lib/module/index.mjs +0 -1
- package/lib/module/index.mjs.map +0 -1
- package/lib/module/markdown/generate-markdown.mjs +0 -1
- package/lib/module/markdown/generate-markdown.mjs.map +0 -1
- package/lib/module/metadata/get-arguments-metadata.mjs +0 -1
- package/lib/module/metadata/get-arguments-metadata.mjs.map +0 -1
- package/lib/module/metadata/get-cli-metadata.mjs +0 -1
- package/lib/module/metadata/get-cli-metadata.mjs.map +0 -1
- package/lib/module/metadata/get-options-metadata.mjs +0 -1
- package/lib/module/metadata/get-options-metadata.mjs.map +0 -1
- package/lib/module/metadata/get-subcommands-metadata.mjs +0 -1
- package/lib/module/metadata/get-subcommands-metadata.mjs.map +0 -1
- package/lib/module/parser/parse/parse.mjs +0 -1
- package/lib/module/parser/parse/parse.mjs.map +0 -1
- package/lib/module/parser/parse/parser-helpers.mjs +0 -1
- package/lib/module/parser/parse/parser-helpers.mjs.map +0 -1
- package/lib/module/parser/safe-parse.mjs +0 -1
- package/lib/module/parser/safe-parse.mjs.map +0 -1
- package/lib/module/parser/unsafe-parse.mjs +0 -1
- package/lib/module/parser/unsafe-parse.mjs.map +0 -1
- package/lib/module/parser/validate/validate-type.mjs +0 -1
- package/lib/module/parser/validate/validate-type.mjs.map +0 -1
- package/lib/module/parser/validate/validate.mjs +0 -1
- package/lib/module/parser/validate/validate.mjs.map +0 -1
- package/lib/module/utilities.mjs +0 -1
- package/lib/module/utilities.mjs.map +0 -1
- package/lib/module/zod-utilities.mjs +0 -1
- package/lib/module/zod-utilities.mjs.map +0 -1
- package/lib/typescript/help-message/format-cli.d.ts +0 -6
- package/lib/typescript/help-message/format-cli.d.ts.map +0 -1
- package/lib/typescript/metadata/get-arguments-metadata.d.ts +0 -4
- package/lib/typescript/metadata/get-arguments-metadata.d.ts.map +0 -1
- package/lib/typescript/metadata/get-cli-metadata.d.ts +0 -4
- package/lib/typescript/metadata/get-cli-metadata.d.ts.map +0 -1
- package/lib/typescript/metadata/get-options-metadata.d.ts +0 -4
- package/lib/typescript/metadata/get-options-metadata.d.ts.map +0 -1
- package/lib/typescript/metadata/get-subcommands-metadata.d.ts +0 -4
- package/lib/typescript/metadata/get-subcommands-metadata.d.ts.map +0 -1
- package/lib/typescript/metadata/metadata-types.d.ts +0 -80
- package/lib/typescript/metadata/metadata-types.d.ts.map +0 -1
- package/lib/typescript/parser/parse/parse-types.d.ts +0 -85
- package/lib/typescript/parser/parse/parse-types.d.ts.map +0 -1
- package/lib/typescript/parser/parse/parse.d.ts +0 -4
- package/lib/typescript/parser/parse/parse.d.ts.map +0 -1
- package/lib/typescript/parser/parse/parser-helpers.d.ts.map +0 -1
- package/lib/typescript/parser/safe-parse.d.ts +0 -4
- package/lib/typescript/parser/safe-parse.d.ts.map +0 -1
- package/lib/typescript/parser/unsafe-parse.d.ts +0 -4
- package/lib/typescript/parser/unsafe-parse.d.ts.map +0 -1
- package/lib/typescript/parser/validate/validate-type.d.ts +0 -22
- package/lib/typescript/parser/validate/validate-type.d.ts.map +0 -1
- package/lib/typescript/parser/validate/validate.d.ts +0 -11
- package/lib/typescript/parser/validate/validate.d.ts.map +0 -1
- package/lib/typescript/types.d.ts +0 -294
- package/lib/typescript/types.d.ts.map +0 -1
- package/lib/typescript/zod-utilities.d.ts +0 -28
- package/lib/typescript/zod-utilities.d.ts.map +0 -1
- package/src/help-message/format-cli.ts +0 -141
- package/src/metadata/get-arguments-metadata.ts +0 -25
- package/src/metadata/get-cli-metadata.ts +0 -23
- package/src/metadata/get-options-metadata.ts +0 -35
- package/src/metadata/get-subcommands-metadata.ts +0 -32
- package/src/metadata/metadata-types.ts +0 -114
- package/src/parser/parse/parse-types.ts +0 -89
- package/src/parser/parse/parse.ts +0 -230
- package/src/parser/safe-parse.ts +0 -103
- package/src/parser/unsafe-parse.ts +0 -98
- package/src/parser/validate/validate-type.ts +0 -21
- package/src/parser/validate/validate.ts +0 -66
- package/src/types.ts +0 -365
- package/src/zod-utilities.ts +0 -214
|
@@ -1,22 +1,33 @@
|
|
|
1
|
-
import type { Option, Subcommand } from "
|
|
1
|
+
import type { Cli, Option, Subcommand } from "../types/definitions-types.ts";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Retrieves a subcommand object from an array of subcommands by matching the provided subcommand name against the
|
|
5
5
|
* subcommand's name or its aliases.
|
|
6
6
|
*
|
|
7
|
-
* @param
|
|
7
|
+
* @param subcommandName - The name or alias of the subcommand to search for.
|
|
8
8
|
* @param subcommandArr - An array of `Subcommand` objects to search within.
|
|
9
9
|
* @returns The matching `Subcommand` object if found; otherwise, `undefined`.
|
|
10
10
|
*/
|
|
11
|
-
export function
|
|
12
|
-
|
|
11
|
+
export function findSubcommandDefinition(
|
|
12
|
+
subcommandName: string | undefined,
|
|
13
|
+
cliDefinition: Cli,
|
|
14
|
+
): Subcommand | Cli | undefined {
|
|
15
|
+
if (subcommandName === undefined) {
|
|
16
|
+
return cliDefinition;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (!cliDefinition.subcommands) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return cliDefinition.subcommands.find(c => {
|
|
13
24
|
// match for undefined too
|
|
14
|
-
if (c.name ===
|
|
25
|
+
if (c.name === subcommandName) {
|
|
15
26
|
return true;
|
|
16
27
|
}
|
|
17
28
|
|
|
18
29
|
// match for aliases
|
|
19
|
-
return
|
|
30
|
+
return subcommandName && c.aliases && c.aliases.includes(subcommandName);
|
|
20
31
|
});
|
|
21
32
|
}
|
|
22
33
|
|
|
@@ -25,32 +36,34 @@ export function findSubcommand(subCmdName: string | undefined, subcommandArray:
|
|
|
25
36
|
*
|
|
26
37
|
* The function supports matching by option name, aliases, and their negated forms (e.g., `--no-` prefix).
|
|
27
38
|
*
|
|
28
|
-
* @param
|
|
39
|
+
* @param optionArgument - The argument string to match (e.g., `--foo`, `--no-bar`, `-f`).
|
|
29
40
|
* @param options - An array of `Option` objects to search through.
|
|
30
41
|
* @returns The matching `Option` object if found; otherwise, `undefined`.
|
|
31
42
|
*/
|
|
32
|
-
export function findOption(optionArgument: string, options:
|
|
43
|
+
export function findOption(optionArgument: string, options: Record<string, Option>): [string, Option] | undefined {
|
|
33
44
|
const validVariableNames = optionArgumentToVariableNames(optionArgument);
|
|
34
|
-
const
|
|
45
|
+
const isNegated = optionArgument.startsWith("--no-");
|
|
35
46
|
|
|
36
|
-
const option = options.find(
|
|
37
|
-
if (validVariableNames.has(
|
|
47
|
+
const option = Object.entries(options).find(([optionName, option]) => {
|
|
48
|
+
if (validVariableNames.has(optionName)) {
|
|
38
49
|
return true;
|
|
39
50
|
}
|
|
40
51
|
|
|
41
|
-
|
|
52
|
+
const isBool = option._preparedType && option._preparedType.coerceTo === "boolean";
|
|
53
|
+
|
|
54
|
+
if (isNegated && isBool && validVariableNames.has(negateOption(optionName))) {
|
|
42
55
|
return true;
|
|
43
56
|
}
|
|
44
57
|
|
|
45
|
-
if (!
|
|
58
|
+
if (!option.aliases) {
|
|
46
59
|
return false;
|
|
47
60
|
}
|
|
48
61
|
|
|
49
|
-
if (
|
|
62
|
+
if (option.aliases.some(a => validVariableNames.has(a))) {
|
|
50
63
|
return true;
|
|
51
64
|
}
|
|
52
65
|
|
|
53
|
-
if (
|
|
66
|
+
if (isNegated && isBool && option.aliases.map(alias => negateOption(alias)).some(a => validVariableNames.has(a))) {
|
|
54
67
|
return true;
|
|
55
68
|
}
|
|
56
69
|
|
|
@@ -85,13 +98,20 @@ export function decoupleFlags(arguments_: string[]): string[] {
|
|
|
85
98
|
}
|
|
86
99
|
|
|
87
100
|
/**
|
|
88
|
-
*
|
|
101
|
+
* Transforms an option name to a set of variants: `camelCase`, `PascalCase`, `snake_case`, `SCREAMING_SNAKE_CASE`.
|
|
102
|
+
*
|
|
103
|
+
* **Example** for `--input-dir`
|
|
104
|
+
*
|
|
105
|
+
* - CamelCase: `inputDir`
|
|
106
|
+
* - PascalCase: `InputDir`
|
|
107
|
+
* - Snake_case: `input_dir`
|
|
108
|
+
* - SCREAMING_SNAKE_CASE: `INPUT_DIR`
|
|
89
109
|
*
|
|
90
110
|
* @param name - Should start with `'--'` or `'-'`
|
|
91
111
|
*/
|
|
92
112
|
export function optionArgumentToVariableNames(name: string): Set<string> {
|
|
93
113
|
if (!name.startsWith("-")) {
|
|
94
|
-
throw new Error(`
|
|
114
|
+
throw new Error(`invalid option name: ${name}`);
|
|
95
115
|
}
|
|
96
116
|
|
|
97
117
|
name = name.startsWith("--") ? name.slice(2) : name.slice(1); // remove prefix
|
|
@@ -136,14 +156,12 @@ export function isOptionArgument(name: string | boolean): boolean {
|
|
|
136
156
|
}
|
|
137
157
|
|
|
138
158
|
/**
|
|
139
|
-
*
|
|
140
|
-
*
|
|
159
|
+
* Transform option name to no name.
|
|
160
|
+
*
|
|
161
|
+
* - `verbose` -> `noVerbose`
|
|
162
|
+
* - `v` -> `noV`
|
|
141
163
|
*/
|
|
142
164
|
export function negateOption(name: string): string {
|
|
143
|
-
if (name.length === 1) {
|
|
144
|
-
return name;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
165
|
return "no" + name.replace(/^[a-z]/, g => g.toUpperCase());
|
|
148
166
|
}
|
|
149
167
|
|
|
@@ -155,12 +173,15 @@ export function transformOptionToArgument(name: string): string {
|
|
|
155
173
|
}
|
|
156
174
|
|
|
157
175
|
// snake_case, SCREAMING_SNAKE_CASE
|
|
158
|
-
if (name
|
|
176
|
+
if (/^[a-z_]+$/.test(name) || /^[A-Z_]+$/.test(name)) {
|
|
159
177
|
name = name.replace(/_/g, "-");
|
|
160
178
|
return `--${name.toLowerCase()}`;
|
|
161
179
|
}
|
|
162
180
|
|
|
163
181
|
// camelCase, PascalCase
|
|
164
|
-
|
|
182
|
+
|
|
183
|
+
// add "-" before camel case letters except for the first letter
|
|
184
|
+
name = name.replace(/[A-Z]/g, (match, index: number) => (index > 0 ? "-" + match : match));
|
|
185
|
+
|
|
165
186
|
return `--${name.toLowerCase()}`;
|
|
166
187
|
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { validateCliDefinition } from "../definitions/validate-cli-definition.ts";
|
|
2
|
+
import { parseArgv } from "../utilities.ts";
|
|
3
|
+
import { buildCliContext } from "./context/cli-context-builder.ts";
|
|
4
|
+
import { findSubcommandDefinition } from "./parser-utilities.ts";
|
|
5
|
+
import { validate } from "./validation/validate-context.ts";
|
|
6
|
+
|
|
7
|
+
import type { Cli } from "../types/definitions-types.ts";
|
|
8
|
+
import type { CliParseResultWide } from "../types/types.ts";
|
|
9
|
+
|
|
10
|
+
export function safeParse(stringOrArgv: string | string[], cliDefinition: Cli): CliParseResultWide {
|
|
11
|
+
const core = safeParseCore(stringOrArgv, cliDefinition);
|
|
12
|
+
if (core.error) return { error: core.error };
|
|
13
|
+
|
|
14
|
+
const { validateResult, subcommandObject } = core;
|
|
15
|
+
|
|
16
|
+
// Fire action (throw errors caused by the usage of the action hook)
|
|
17
|
+
if (subcommandObject._onExecute) {
|
|
18
|
+
for (const handler of subcommandObject._onExecute) {
|
|
19
|
+
handler(validateResult);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return { error: undefined, value: validateResult };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function safeParseAsync(stringOrArgv: string | string[], cliDefinition: Cli): Promise<CliParseResultWide> {
|
|
27
|
+
const core = safeParseCore(stringOrArgv, cliDefinition);
|
|
28
|
+
if (core.error) return { error: core.error };
|
|
29
|
+
|
|
30
|
+
const { validateResult, subcommandObject } = core;
|
|
31
|
+
|
|
32
|
+
// Fire action (throw errors caused by the usage of the action hook)
|
|
33
|
+
if (subcommandObject._onExecute) {
|
|
34
|
+
for (const handler of subcommandObject._onExecute) {
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
36
|
+
await handler(validateResult);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return { error: undefined, value: validateResult };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function safeParseCore(stringOrArgv: string | string[], cliDefinition: Cli) {
|
|
44
|
+
const argv = typeof stringOrArgv === "string" ? parseArgv(stringOrArgv) : stringOrArgv;
|
|
45
|
+
|
|
46
|
+
// validate cli definition
|
|
47
|
+
try {
|
|
48
|
+
validateCliDefinition(cliDefinition);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
return { error: error as Error };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Parse
|
|
54
|
+
let cliContext;
|
|
55
|
+
try {
|
|
56
|
+
cliContext = buildCliContext(argv, cliDefinition);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
return { error: error as Error };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const subcommandObject = findSubcommandDefinition(cliContext.subcommand, cliDefinition);
|
|
62
|
+
if (!subcommandObject) {
|
|
63
|
+
const error = new Error(`Subcommand "${cliContext.subcommand}" does not exist`);
|
|
64
|
+
return { error };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Validate context
|
|
68
|
+
let validateResult;
|
|
69
|
+
try {
|
|
70
|
+
validateResult = validate(cliContext, subcommandObject);
|
|
71
|
+
} catch (error) {
|
|
72
|
+
return { error: error as Error };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return { error: undefined, validateResult, subcommandObject };
|
|
76
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { validateArguments } from "./validators/arguments.ts";
|
|
2
|
+
import { validateOptions } from "./validators/options.ts";
|
|
3
|
+
|
|
4
|
+
import type { ContextWide } from "../../types/context-types.ts";
|
|
5
|
+
import type { Cli, Subcommand } from "../../types/definitions-types.ts";
|
|
6
|
+
import type { OutputTypeWide } from "../../types/io-types.ts";
|
|
7
|
+
|
|
8
|
+
/** @throws {Error} */
|
|
9
|
+
export function validate(context: ContextWide, commandDefinition: Subcommand | Cli) {
|
|
10
|
+
const output: OutputTypeWide = {
|
|
11
|
+
subcommand: context.subcommand,
|
|
12
|
+
positionals: context.positionals,
|
|
13
|
+
context: context,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// validate options
|
|
17
|
+
validateOptions({ commandDefinition, context, output });
|
|
18
|
+
|
|
19
|
+
// validate arguments
|
|
20
|
+
validateArguments({ commandDefinition, context, output });
|
|
21
|
+
|
|
22
|
+
return output;
|
|
23
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { validateSync } from "../../../utilities.ts";
|
|
2
|
+
import { validateConflictWith } from "./conflict.ts";
|
|
3
|
+
import { validateExclusive } from "./exclusive.ts";
|
|
4
|
+
import { validateRequires } from "./requires.ts";
|
|
5
|
+
|
|
6
|
+
import type { ContextWide } from "../../../types/context-types.ts";
|
|
7
|
+
import type { Cli, Subcommand } from "../../../types/definitions-types.ts";
|
|
8
|
+
import type { OutputTypeWide } from "../../../types/io-types.ts";
|
|
9
|
+
|
|
10
|
+
interface ValidateArgument {
|
|
11
|
+
commandDefinition: Subcommand | Cli;
|
|
12
|
+
context: ContextWide;
|
|
13
|
+
output: OutputTypeWide;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** @throws {Error} */
|
|
17
|
+
export function validateArguments({ commandDefinition, context, output }: ValidateArgument) {
|
|
18
|
+
if (!context.arguments) return;
|
|
19
|
+
|
|
20
|
+
output.arguments ??= {};
|
|
21
|
+
|
|
22
|
+
const argumentsDefinition = commandDefinition.arguments;
|
|
23
|
+
if (!argumentsDefinition) {
|
|
24
|
+
throw new Error(`Subcommand "${context.subcommand}" does not have arguments`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
for (const [argumentName, argument] of Object.entries(argumentsDefinition)) {
|
|
28
|
+
validateRequires({ name: argumentName, commandDefinition, optionOrArgument: argument, context, type: "option" });
|
|
29
|
+
validateExclusive({ name: argumentName, optionOrArgument: argument, context, type: "option" });
|
|
30
|
+
validateConflictWith({ name: argumentName, optionOrArgument: argument, context, type: "option" });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const argumentContextEntries = Object.entries(context.arguments);
|
|
34
|
+
|
|
35
|
+
for (const [name, { passedValue, stringValue, source, schema }] of argumentContextEntries) {
|
|
36
|
+
const isProgrammatic = source === "programmatic";
|
|
37
|
+
|
|
38
|
+
const argument = argumentsDefinition[name];
|
|
39
|
+
if (!argument) {
|
|
40
|
+
throw new Error(`Subcommand "${context.subcommand}" does not have the argument "${name}"`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!argument._preparedType) {
|
|
44
|
+
throw new Error(`internal error: missing prepared type for the argument "${name}"`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const safeParseResult = isProgrammatic
|
|
48
|
+
? validateSync(schema, passedValue)
|
|
49
|
+
: argument._preparedType.validate(stringValue);
|
|
50
|
+
|
|
51
|
+
if (safeParseResult.issues) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
`The argument ${name} argument ${isProgrammatic ? "" : `"${stringValue}"`} is invalid: ${safeParseResult.issues.map(issue => issue.message).join(", ")}`,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
output.arguments[name] = safeParseResult.value;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { isOptionOrArgumentExplicitlyPassed } from "./explicitly-passed.ts";
|
|
2
|
+
|
|
3
|
+
import type { ContextWide } from "../../../types/context-types.ts";
|
|
4
|
+
import type { Argument, Option } from "../../../types/definitions-types.ts";
|
|
5
|
+
|
|
6
|
+
interface ValidateConflictOptions {
|
|
7
|
+
/** The option or argument name to check its `requires` */
|
|
8
|
+
name: string;
|
|
9
|
+
|
|
10
|
+
/** The option or argument to check */
|
|
11
|
+
optionOrArgument: Option | Argument;
|
|
12
|
+
|
|
13
|
+
/** The parsed context */
|
|
14
|
+
context: ContextWide;
|
|
15
|
+
|
|
16
|
+
/** What we're checking */
|
|
17
|
+
type: "option" | "argument";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** @throws {Error} */
|
|
21
|
+
export function validateConflictWith({ name, optionOrArgument, context, type }: ValidateConflictOptions) {
|
|
22
|
+
const conflictWith = optionOrArgument.conflictWith;
|
|
23
|
+
if (!conflictWith || conflictWith.length === 0) return;
|
|
24
|
+
|
|
25
|
+
// Check if the options/argument is passed
|
|
26
|
+
if (!isOptionOrArgumentExplicitlyPassed(name, context)) return;
|
|
27
|
+
|
|
28
|
+
const conflictedOptions: string[] = [];
|
|
29
|
+
const conflictedArguments: string[] = [];
|
|
30
|
+
|
|
31
|
+
if (context.options) {
|
|
32
|
+
for (const [optionName, optionContext] of Object.entries(context.options)) {
|
|
33
|
+
if (optionName === name) continue; // don't check self
|
|
34
|
+
if (!conflictWith.includes(optionName)) continue; // not a conflict
|
|
35
|
+
if (optionContext.source === "default") continue; // not explicitly passed
|
|
36
|
+
conflictedOptions.push(optionName);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (context.arguments) {
|
|
41
|
+
for (const [argumentName, argumentContext] of Object.entries(context.arguments)) {
|
|
42
|
+
if (argumentName === name) continue; // don't check self
|
|
43
|
+
if (!conflictWith.includes(argumentName)) continue; // not a conflict
|
|
44
|
+
if (argumentContext.source === "default") continue; // not explicitly passed
|
|
45
|
+
conflictedArguments.push(argumentName);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (conflictedOptions.length === 0 && conflictedArguments.length === 0) return; // OK
|
|
50
|
+
|
|
51
|
+
const parts: string[] = [];
|
|
52
|
+
|
|
53
|
+
if (conflictedOptions.length > 0) {
|
|
54
|
+
const formatted = conflictedOptions.map(o => `"${o}"`).join(", ");
|
|
55
|
+
const s = conflictedOptions.length > 1 ? "s" : "";
|
|
56
|
+
parts.push(`option${s} ${formatted}`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (conflictedArguments.length > 0) {
|
|
60
|
+
const formatted = conflictedArguments.map(a => `"${a}"`).join(", ");
|
|
61
|
+
const s = conflictedArguments.length > 1 ? "s" : "";
|
|
62
|
+
parts.push(`argument${s} ${formatted}`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const joinedParts = parts.join(" and ");
|
|
66
|
+
|
|
67
|
+
throw new Error(`${type} "${name}" cannot be used with the ${joinedParts} because they are mutually exclusive.`);
|
|
68
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { isOptionOrArgumentExplicitlyPassed } from "./explicitly-passed.ts";
|
|
2
|
+
|
|
3
|
+
import type { ContextWide } from "../../../types/context-types.ts";
|
|
4
|
+
import type { Argument, Option } from "../../../types/definitions-types.ts";
|
|
5
|
+
|
|
6
|
+
interface ValidateExclusiveOptions {
|
|
7
|
+
/** The option or argument name to check its `requires` */
|
|
8
|
+
name: string;
|
|
9
|
+
|
|
10
|
+
/** The option or argument to check */
|
|
11
|
+
optionOrArgument: Option | Argument;
|
|
12
|
+
|
|
13
|
+
/** The parsed context */
|
|
14
|
+
context: ContextWide;
|
|
15
|
+
|
|
16
|
+
/** What we're checking */
|
|
17
|
+
type: "option" | "argument";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** @throws {Error} */
|
|
21
|
+
export function validateExclusive({ name, optionOrArgument, context, type }: ValidateExclusiveOptions) {
|
|
22
|
+
const exclusive = optionOrArgument.exclusive;
|
|
23
|
+
if (!exclusive) return;
|
|
24
|
+
|
|
25
|
+
// Check if the options/argument is passed
|
|
26
|
+
if (!isOptionOrArgumentExplicitlyPassed(name, context)) return;
|
|
27
|
+
|
|
28
|
+
const requires = optionOrArgument.requires ?? [];
|
|
29
|
+
|
|
30
|
+
const mutuallyExclusiveOptions: string[] = [];
|
|
31
|
+
const mutuallyExclusiveArguments: string[] = [];
|
|
32
|
+
|
|
33
|
+
if (context.options) {
|
|
34
|
+
for (const [optionName, optionContext] of Object.entries(context.options)) {
|
|
35
|
+
if (optionName === name) continue; // don't check self
|
|
36
|
+
if (requires.includes(optionName)) continue; // allow required options
|
|
37
|
+
if (optionContext.source === "default") continue; // not explicitly passed
|
|
38
|
+
mutuallyExclusiveOptions.push(optionName);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (context.arguments) {
|
|
43
|
+
for (const [argumentName, argumentContext] of Object.entries(context.arguments)) {
|
|
44
|
+
if (argumentName === name) continue; // don't check self
|
|
45
|
+
if (requires.includes(argumentName)) continue; // allow required arguments
|
|
46
|
+
if (argumentContext.source === "default") continue; // not explicitly passed
|
|
47
|
+
mutuallyExclusiveArguments.push(argumentName);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (mutuallyExclusiveOptions.length === 0 && mutuallyExclusiveArguments.length === 0) return;
|
|
52
|
+
|
|
53
|
+
const parts: string[] = [];
|
|
54
|
+
|
|
55
|
+
if (mutuallyExclusiveOptions.length > 0) {
|
|
56
|
+
const formatted = mutuallyExclusiveOptions.map(o => `"${o}"`).join(", ");
|
|
57
|
+
const s = mutuallyExclusiveOptions.length > 1 ? "s" : "";
|
|
58
|
+
parts.push(`option${s} ${formatted}`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (mutuallyExclusiveArguments.length > 0) {
|
|
62
|
+
const formatted = mutuallyExclusiveArguments.map(a => `"${a}"`).join(", ");
|
|
63
|
+
const s = mutuallyExclusiveArguments.length > 1 ? "s" : "";
|
|
64
|
+
parts.push(`argument${s} ${formatted}`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const joinedParts = parts.join(" and ");
|
|
68
|
+
|
|
69
|
+
throw new Error(`${type} "${name}" cannot be used with the ${joinedParts} because they are mutually exclusive.`);
|
|
70
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ContextWide } from "../../../types/context-types.ts";
|
|
2
|
+
|
|
3
|
+
export function isArgumentExplicitlyPassed(name: string, context: ContextWide) {
|
|
4
|
+
if (!context.arguments) return false;
|
|
5
|
+
return name in context.arguments && context.arguments[name].source !== "default";
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function isOptionExplicitlyPassed(name: string, context: ContextWide) {
|
|
9
|
+
if (!context.options) return false;
|
|
10
|
+
return name in context.options && context.options[name].source !== "default";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function isOptionOrArgumentExplicitlyPassed(name: string, context: ContextWide) {
|
|
14
|
+
return isOptionExplicitlyPassed(name, context) || isArgumentExplicitlyPassed(name, context);
|
|
15
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { validateSync } from "../../../utilities.ts";
|
|
2
|
+
import { validateConflictWith } from "./conflict.ts";
|
|
3
|
+
import { validateExclusive } from "./exclusive.ts";
|
|
4
|
+
import { validateRequires } from "./requires.ts";
|
|
5
|
+
|
|
6
|
+
import type { ContextWide } from "../../../types/context-types.ts";
|
|
7
|
+
import type { Cli, Subcommand } from "../../../types/definitions-types.ts";
|
|
8
|
+
import type { OutputTypeWide } from "../../../types/io-types.ts";
|
|
9
|
+
|
|
10
|
+
interface ValidateOptions {
|
|
11
|
+
commandDefinition: Subcommand | Cli;
|
|
12
|
+
context: ContextWide;
|
|
13
|
+
output: OutputTypeWide;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** @throws {Error} */
|
|
17
|
+
export function validateOptions({ commandDefinition, context, output }: ValidateOptions) {
|
|
18
|
+
if (!context.options) return;
|
|
19
|
+
|
|
20
|
+
output.options ??= {};
|
|
21
|
+
|
|
22
|
+
const optionsDefinition = commandDefinition.options;
|
|
23
|
+
if (!optionsDefinition) {
|
|
24
|
+
throw new Error(`subcommand "${context.subcommand}" does not have options`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
for (const [optionName, option] of Object.entries(optionsDefinition)) {
|
|
28
|
+
validateRequires({ name: optionName, commandDefinition, optionOrArgument: option, context, type: "option" });
|
|
29
|
+
validateExclusive({ name: optionName, optionOrArgument: option, context, type: "option" });
|
|
30
|
+
validateConflictWith({ name: optionName, optionOrArgument: option, context, type: "option" });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const optionContextEntries = Object.entries(context.options);
|
|
34
|
+
|
|
35
|
+
for (const [optionName, { passedValue, stringValue, flag, source, schema }] of optionContextEntries) {
|
|
36
|
+
const option = optionsDefinition[optionName];
|
|
37
|
+
if (!option) {
|
|
38
|
+
throw new Error(`subcommand "${context.subcommand}" does not have option "${optionName}"`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (!option._preparedType) {
|
|
42
|
+
throw new Error(`internal error: missing prepared type for option "${optionName}"`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const isProgrammatic = source === "programmatic";
|
|
46
|
+
|
|
47
|
+
const safeParseResult = isProgrammatic
|
|
48
|
+
? validateSync(schema, passedValue)
|
|
49
|
+
: option._preparedType.validate(stringValue);
|
|
50
|
+
|
|
51
|
+
if (safeParseResult.issues) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
`invalid value ${isProgrammatic ? "" : `"${stringValue}"`} for "${isProgrammatic ? optionName : flag}": ${safeParseResult.issues.map(issue => issue.message).join(", ")}`,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
output.options[optionName] = safeParseResult.value;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isArgumentExplicitlyPassed,
|
|
3
|
+
isOptionExplicitlyPassed,
|
|
4
|
+
isOptionOrArgumentExplicitlyPassed,
|
|
5
|
+
} from "./explicitly-passed.ts";
|
|
6
|
+
|
|
7
|
+
import type { ContextWide } from "../../../types/context-types.ts";
|
|
8
|
+
import type { Argument, Cli, Option, Subcommand } from "../../../types/definitions-types.ts";
|
|
9
|
+
|
|
10
|
+
interface ValidateRequiresOptions {
|
|
11
|
+
/** The option or argument name to check its `requires` */
|
|
12
|
+
name: string;
|
|
13
|
+
|
|
14
|
+
/** The subcommand or cli configuration */
|
|
15
|
+
commandDefinition: Subcommand | Cli;
|
|
16
|
+
|
|
17
|
+
/** The option or argument to check */
|
|
18
|
+
optionOrArgument: Option | Argument;
|
|
19
|
+
|
|
20
|
+
/** The parsed context */
|
|
21
|
+
context: ContextWide;
|
|
22
|
+
|
|
23
|
+
/** What we're checking */
|
|
24
|
+
type: "option" | "argument";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** @throws {Error} */
|
|
28
|
+
export function validateRequires({
|
|
29
|
+
name,
|
|
30
|
+
commandDefinition,
|
|
31
|
+
optionOrArgument,
|
|
32
|
+
context,
|
|
33
|
+
type,
|
|
34
|
+
}: ValidateRequiresOptions) {
|
|
35
|
+
const requires = optionOrArgument.requires;
|
|
36
|
+
if (!requires || requires.length === 0) return;
|
|
37
|
+
|
|
38
|
+
// Check if the options/argument is passed
|
|
39
|
+
if (!isOptionOrArgumentExplicitlyPassed(name, context)) return;
|
|
40
|
+
|
|
41
|
+
const optionsDefinition = commandDefinition.options ?? {};
|
|
42
|
+
|
|
43
|
+
const missingOptions: string[] = [];
|
|
44
|
+
const missingArguments: string[] = [];
|
|
45
|
+
|
|
46
|
+
for (const requiredName of requires) {
|
|
47
|
+
const isOption = requiredName in optionsDefinition;
|
|
48
|
+
|
|
49
|
+
const provided = isOption
|
|
50
|
+
? isOptionExplicitlyPassed(requiredName, context)
|
|
51
|
+
: isArgumentExplicitlyPassed(requiredName, context);
|
|
52
|
+
|
|
53
|
+
if (provided) continue;
|
|
54
|
+
|
|
55
|
+
if (isOption) {
|
|
56
|
+
missingOptions.push(requiredName);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
missingArguments.push(requiredName);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (missingOptions.length === 0 && missingArguments.length === 0) return; // OK
|
|
64
|
+
|
|
65
|
+
const parts: string[] = [];
|
|
66
|
+
|
|
67
|
+
if (missingOptions.length > 0) {
|
|
68
|
+
const formatted = missingOptions.map(o => `"${o}"`).join(", ");
|
|
69
|
+
const s = missingOptions.length > 1 ? "s" : "";
|
|
70
|
+
parts.push(`option${s} ${formatted}`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (missingArguments.length > 0) {
|
|
74
|
+
const formatted = missingArguments.map(a => `"${a}"`).join(", ");
|
|
75
|
+
const s = missingArguments.length > 1 ? "s" : "";
|
|
76
|
+
parts.push(`argument${s} ${formatted}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const joinedParts = parts.join(" and ");
|
|
80
|
+
|
|
81
|
+
throw new Error(`${type} "${name}" cannot be used without the required ${joinedParts}.`);
|
|
82
|
+
}
|