zod-args-parser 2.0.0-beta.1 → 2.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -0
- package/README.md +244 -282
- package/lib/esm/autocomplete-scripts/bash-autocomplete-script.js +74 -2
- package/lib/esm/autocomplete-scripts/bash-autocomplete-script.js.map +7 -1
- package/lib/esm/autocomplete-scripts/powershell-autocomplete-script.js +90 -2
- package/lib/esm/autocomplete-scripts/powershell-autocomplete-script.js.map +7 -1
- package/lib/esm/autocomplete-scripts/zsh-autocomplete-script.js +39 -13
- package/lib/esm/autocomplete-scripts/zsh-autocomplete-script.js.map +7 -1
- package/lib/esm/cli-error/cli-error.js +38 -0
- package/lib/esm/cli-error/cli-error.js.map +7 -0
- package/lib/esm/cli-error/error-cause.js +12 -0
- package/lib/esm/cli-error/error-cause.js.map +7 -0
- package/lib/esm/cli-error/error-code/definition-error-code.js +23 -0
- package/lib/esm/cli-error/error-code/definition-error-code.js.map +7 -0
- package/lib/esm/cli-error/error-code/internal-error-code.js +10 -0
- package/lib/esm/cli-error/error-code/internal-error-code.js.map +7 -0
- package/lib/esm/cli-error/error-code/parse-error-code.js +18 -0
- package/lib/esm/cli-error/error-code/parse-error-code.js.map +7 -0
- package/lib/esm/cli-error/error-code/validation-error-code.js +17 -0
- package/lib/esm/cli-error/error-code/validation-error-code.js.map +7 -0
- package/lib/esm/cli-error/error-message/definition-error-message.js +70 -0
- package/lib/esm/cli-error/error-message/definition-error-message.js.map +7 -0
- package/lib/esm/cli-error/error-message/internal-error-message.js +16 -0
- package/lib/esm/cli-error/error-message/internal-error-message.js.map +7 -0
- package/lib/esm/cli-error/error-message/parse-error-message.js +40 -0
- package/lib/esm/cli-error/error-message/parse-error-message.js.map +7 -0
- package/lib/esm/cli-error/error-message/validation-error-message.js +60 -0
- package/lib/esm/cli-error/error-message/validation-error-message.js.map +7 -0
- package/lib/esm/coerce/coerce-methods.js +197 -2
- package/lib/esm/coerce/coerce-methods.js.map +7 -1
- package/lib/esm/coerce/string-to-array.js +17 -2
- package/lib/esm/coerce/string-to-array.js.map +7 -1
- package/lib/esm/coerce/string-to-primitive.js +73 -2
- package/lib/esm/coerce/string-to-primitive.js.map +7 -1
- package/lib/esm/coerce/string-to-set.js +17 -2
- package/lib/esm/coerce/string-to-set.js.map +7 -1
- package/lib/esm/definitions/define-arguments.js +10 -2
- package/lib/esm/definitions/define-arguments.js.map +7 -1
- package/lib/esm/definitions/define-cli.js +89 -2
- package/lib/esm/definitions/define-cli.js.map +7 -1
- package/lib/esm/definitions/define-options.js +10 -2
- package/lib/esm/definitions/define-options.js.map +7 -1
- package/lib/esm/definitions/define-subcommand.js +56 -2
- package/lib/esm/definitions/define-subcommand.js.map +7 -1
- package/lib/esm/definitions/validate-cli-definition.js +360 -2
- package/lib/esm/definitions/validate-cli-definition.js.map +7 -1
- package/lib/esm/help-message/format-arguments.js +48 -2
- package/lib/esm/help-message/format-arguments.js.map +7 -1
- package/lib/esm/help-message/format-options.js +50 -2
- package/lib/esm/help-message/format-options.js.map +7 -1
- package/lib/esm/help-message/format-subcommands.js +37 -2
- package/lib/esm/help-message/format-subcommands.js.map +7 -1
- package/lib/esm/help-message/generate-for-cli.js +71 -2
- package/lib/esm/help-message/generate-for-cli.js.map +7 -1
- package/lib/esm/help-message/generate-for-subcommand.js +23 -2
- package/lib/esm/help-message/generate-for-subcommand.js.map +7 -1
- package/lib/esm/help-message/print-help.js +14 -2
- package/lib/esm/help-message/print-help.js.map +7 -1
- package/lib/esm/help-message/set-defaults.js +29 -2
- package/lib/esm/help-message/set-defaults.js.map +7 -1
- package/lib/esm/help-message/styles.js +154 -2
- package/lib/esm/help-message/styles.js.map +7 -1
- package/lib/esm/help-message/terminal-markdown.js +121 -2
- package/lib/esm/help-message/terminal-markdown.js.map +7 -1
- package/lib/esm/index.js +52 -2
- package/lib/esm/index.js.map +7 -1
- package/lib/esm/markdown/generate-markdown.js +153 -2
- package/lib/esm/markdown/generate-markdown.js.map +7 -1
- package/lib/esm/metadata/arguments-metadata.js +26 -2
- package/lib/esm/metadata/arguments-metadata.js.map +7 -1
- package/lib/esm/metadata/cli-metadata.js +24 -2
- package/lib/esm/metadata/cli-metadata.js.map +7 -1
- package/lib/esm/metadata/options-metadata.js +35 -2
- package/lib/esm/metadata/options-metadata.js.map +7 -1
- package/lib/esm/metadata/subcommands-metadata.js +32 -2
- package/lib/esm/metadata/subcommands-metadata.js.map +7 -1
- package/lib/esm/parse/context/cli-context-builder.js +283 -2
- package/lib/esm/parse/context/cli-context-builder.js.map +7 -1
- package/lib/esm/parse/context/object-context-builder.js +62 -2
- package/lib/esm/parse/context/object-context-builder.js.map +7 -1
- package/lib/esm/parse/parser-utilities.js +108 -2
- package/lib/esm/parse/parser-utilities.js.map +7 -1
- package/lib/esm/parse/safe-parse.js +57 -2
- package/lib/esm/parse/safe-parse.js.map +7 -1
- package/lib/esm/parse/validation/validate-context.js +17 -2
- package/lib/esm/parse/validation/validate-context.js.map +7 -1
- package/lib/esm/parse/validation/validators/arguments.js +67 -2
- package/lib/esm/parse/validation/validators/arguments.js.map +7 -1
- package/lib/esm/parse/validation/validators/conflict.js +38 -2
- package/lib/esm/parse/validation/validators/conflict.js.map +7 -1
- package/lib/esm/parse/validation/validators/exclusive.js +39 -2
- package/lib/esm/parse/validation/validators/exclusive.js.map +7 -1
- package/lib/esm/parse/validation/validators/explicitly-passed.js +18 -2
- package/lib/esm/parse/validation/validators/explicitly-passed.js.map +7 -1
- package/lib/esm/parse/validation/validators/options.js +67 -2
- package/lib/esm/parse/validation/validators/options.js.map +7 -1
- package/lib/esm/parse/validation/validators/requires.js +43 -2
- package/lib/esm/parse/validation/validators/requires.js.map +7 -1
- package/lib/esm/utilities/parse-argv.js +61 -0
- package/lib/esm/utilities/parse-argv.js.map +7 -0
- package/lib/esm/utilities/schema-utilities.js +57 -0
- package/lib/esm/utilities/schema-utilities.js.map +7 -0
- package/lib/esm/utilities/utilities.js +122 -0
- package/lib/esm/utilities/utilities.js.map +7 -0
- package/lib/iife/index.js +41 -1
- package/lib/iife/index.js.map +1 -1
- package/lib/mjs/autocomplete-scripts/bash-autocomplete-script.mjs +74 -2
- package/lib/mjs/autocomplete-scripts/bash-autocomplete-script.mjs.map +7 -1
- package/lib/mjs/autocomplete-scripts/powershell-autocomplete-script.mjs +90 -2
- package/lib/mjs/autocomplete-scripts/powershell-autocomplete-script.mjs.map +7 -1
- package/lib/mjs/autocomplete-scripts/zsh-autocomplete-script.mjs +39 -13
- package/lib/mjs/autocomplete-scripts/zsh-autocomplete-script.mjs.map +7 -1
- package/lib/mjs/cli-error/cli-error.mjs +38 -0
- package/lib/mjs/cli-error/cli-error.mjs.map +7 -0
- package/lib/mjs/cli-error/error-cause.mjs +12 -0
- package/lib/mjs/cli-error/error-cause.mjs.map +7 -0
- package/lib/mjs/cli-error/error-code/definition-error-code.mjs +23 -0
- package/lib/mjs/cli-error/error-code/definition-error-code.mjs.map +7 -0
- package/lib/mjs/cli-error/error-code/internal-error-code.mjs +10 -0
- package/lib/mjs/cli-error/error-code/internal-error-code.mjs.map +7 -0
- package/lib/mjs/cli-error/error-code/parse-error-code.mjs +18 -0
- package/lib/mjs/cli-error/error-code/parse-error-code.mjs.map +7 -0
- package/lib/mjs/cli-error/error-code/validation-error-code.mjs +17 -0
- package/lib/mjs/cli-error/error-code/validation-error-code.mjs.map +7 -0
- package/lib/mjs/cli-error/error-message/definition-error-message.mjs +70 -0
- package/lib/mjs/cli-error/error-message/definition-error-message.mjs.map +7 -0
- package/lib/mjs/cli-error/error-message/internal-error-message.mjs +16 -0
- package/lib/mjs/cli-error/error-message/internal-error-message.mjs.map +7 -0
- package/lib/mjs/cli-error/error-message/parse-error-message.mjs +40 -0
- package/lib/mjs/cli-error/error-message/parse-error-message.mjs.map +7 -0
- package/lib/mjs/cli-error/error-message/validation-error-message.mjs +60 -0
- package/lib/mjs/cli-error/error-message/validation-error-message.mjs.map +7 -0
- package/lib/mjs/coerce/coerce-methods.mjs +197 -2
- package/lib/mjs/coerce/coerce-methods.mjs.map +7 -1
- package/lib/mjs/coerce/string-to-array.mjs +17 -2
- package/lib/mjs/coerce/string-to-array.mjs.map +7 -1
- package/lib/mjs/coerce/string-to-primitive.mjs +73 -2
- package/lib/mjs/coerce/string-to-primitive.mjs.map +7 -1
- package/lib/mjs/coerce/string-to-set.mjs +17 -2
- package/lib/mjs/coerce/string-to-set.mjs.map +7 -1
- package/lib/mjs/definitions/define-arguments.mjs +10 -2
- package/lib/mjs/definitions/define-arguments.mjs.map +7 -1
- package/lib/mjs/definitions/define-cli.mjs +89 -2
- package/lib/mjs/definitions/define-cli.mjs.map +7 -1
- package/lib/mjs/definitions/define-options.mjs +10 -2
- package/lib/mjs/definitions/define-options.mjs.map +7 -1
- package/lib/mjs/definitions/define-subcommand.mjs +56 -2
- package/lib/mjs/definitions/define-subcommand.mjs.map +7 -1
- package/lib/mjs/definitions/validate-cli-definition.mjs +360 -2
- package/lib/mjs/definitions/validate-cli-definition.mjs.map +7 -1
- package/lib/mjs/help-message/format-arguments.mjs +48 -2
- package/lib/mjs/help-message/format-arguments.mjs.map +7 -1
- package/lib/mjs/help-message/format-options.mjs +50 -2
- package/lib/mjs/help-message/format-options.mjs.map +7 -1
- package/lib/mjs/help-message/format-subcommands.mjs +37 -2
- package/lib/mjs/help-message/format-subcommands.mjs.map +7 -1
- package/lib/mjs/help-message/generate-for-cli.mjs +71 -2
- package/lib/mjs/help-message/generate-for-cli.mjs.map +7 -1
- package/lib/mjs/help-message/generate-for-subcommand.mjs +23 -2
- package/lib/mjs/help-message/generate-for-subcommand.mjs.map +7 -1
- package/lib/mjs/help-message/print-help.mjs +14 -2
- package/lib/mjs/help-message/print-help.mjs.map +7 -1
- package/lib/mjs/help-message/set-defaults.mjs +29 -2
- package/lib/mjs/help-message/set-defaults.mjs.map +7 -1
- package/lib/mjs/help-message/styles.mjs +154 -2
- package/lib/mjs/help-message/styles.mjs.map +7 -1
- package/lib/mjs/help-message/terminal-markdown.mjs +121 -2
- package/lib/mjs/help-message/terminal-markdown.mjs.map +7 -1
- package/lib/mjs/index.mjs +52 -2
- package/lib/mjs/index.mjs.map +7 -1
- package/lib/mjs/markdown/generate-markdown.mjs +153 -2
- package/lib/mjs/markdown/generate-markdown.mjs.map +7 -1
- package/lib/mjs/metadata/arguments-metadata.mjs +26 -2
- package/lib/mjs/metadata/arguments-metadata.mjs.map +7 -1
- package/lib/mjs/metadata/cli-metadata.mjs +24 -2
- package/lib/mjs/metadata/cli-metadata.mjs.map +7 -1
- package/lib/mjs/metadata/options-metadata.mjs +35 -2
- package/lib/mjs/metadata/options-metadata.mjs.map +7 -1
- package/lib/mjs/metadata/subcommands-metadata.mjs +32 -2
- package/lib/mjs/metadata/subcommands-metadata.mjs.map +7 -1
- package/lib/mjs/parse/context/cli-context-builder.mjs +283 -2
- package/lib/mjs/parse/context/cli-context-builder.mjs.map +7 -1
- package/lib/mjs/parse/context/object-context-builder.mjs +62 -2
- package/lib/mjs/parse/context/object-context-builder.mjs.map +7 -1
- package/lib/mjs/parse/parser-utilities.mjs +108 -2
- package/lib/mjs/parse/parser-utilities.mjs.map +7 -1
- package/lib/mjs/parse/safe-parse.mjs +57 -2
- package/lib/mjs/parse/safe-parse.mjs.map +7 -1
- package/lib/mjs/parse/validation/validate-context.mjs +17 -2
- package/lib/mjs/parse/validation/validate-context.mjs.map +7 -1
- package/lib/mjs/parse/validation/validators/arguments.mjs +67 -2
- package/lib/mjs/parse/validation/validators/arguments.mjs.map +7 -1
- package/lib/mjs/parse/validation/validators/conflict.mjs +38 -2
- package/lib/mjs/parse/validation/validators/conflict.mjs.map +7 -1
- package/lib/mjs/parse/validation/validators/exclusive.mjs +39 -2
- package/lib/mjs/parse/validation/validators/exclusive.mjs.map +7 -1
- package/lib/mjs/parse/validation/validators/explicitly-passed.mjs +18 -2
- package/lib/mjs/parse/validation/validators/explicitly-passed.mjs.map +7 -1
- package/lib/mjs/parse/validation/validators/options.mjs +67 -2
- package/lib/mjs/parse/validation/validators/options.mjs.map +7 -1
- package/lib/mjs/parse/validation/validators/requires.mjs +43 -2
- package/lib/mjs/parse/validation/validators/requires.mjs.map +7 -1
- package/lib/mjs/utilities/parse-argv.mjs +61 -0
- package/lib/mjs/utilities/parse-argv.mjs.map +7 -0
- package/lib/mjs/utilities/schema-utilities.mjs +57 -0
- package/lib/mjs/utilities/schema-utilities.mjs.map +7 -0
- package/lib/mjs/utilities/utilities.mjs +122 -0
- package/lib/mjs/utilities/utilities.mjs.map +7 -0
- package/lib/{typescript → types}/autocomplete-scripts/bash-autocomplete-script.d.ts.map +1 -1
- package/lib/types/autocomplete-scripts/powershell-autocomplete-script.d.ts +15 -0
- package/lib/{typescript → types}/autocomplete-scripts/powershell-autocomplete-script.d.ts.map +1 -1
- package/lib/types/autocomplete-scripts/zsh-autocomplete-script.d.ts +4 -0
- package/lib/{typescript → types}/autocomplete-scripts/zsh-autocomplete-script.d.ts.map +1 -1
- package/lib/types/cli-error/cli-error.d.ts +152 -0
- package/lib/types/cli-error/cli-error.d.ts.map +1 -0
- package/lib/types/cli-error/error-cause.d.ts +5 -0
- package/lib/types/cli-error/error-cause.d.ts.map +1 -0
- package/lib/types/cli-error/error-code/definition-error-code.d.ts +5 -0
- package/lib/types/cli-error/error-code/definition-error-code.d.ts.map +1 -0
- package/lib/types/cli-error/error-code/internal-error-code.d.ts +5 -0
- package/lib/types/cli-error/error-code/internal-error-code.d.ts.map +1 -0
- package/lib/types/cli-error/error-code/parse-error-code.d.ts +5 -0
- package/lib/types/cli-error/error-code/parse-error-code.d.ts.map +1 -0
- package/lib/types/cli-error/error-code/validation-error-code.d.ts +5 -0
- package/lib/types/cli-error/error-code/validation-error-code.d.ts.map +1 -0
- package/lib/types/cli-error/error-message/definition-error-message.d.ts +3 -0
- package/lib/types/cli-error/error-message/definition-error-message.d.ts.map +1 -0
- package/lib/types/cli-error/error-message/internal-error-message.d.ts +3 -0
- package/lib/types/cli-error/error-message/internal-error-message.d.ts.map +1 -0
- package/lib/types/cli-error/error-message/parse-error-message.d.ts +3 -0
- package/lib/types/cli-error/error-message/parse-error-message.d.ts.map +1 -0
- package/lib/types/cli-error/error-message/validation-error-message.d.ts +3 -0
- package/lib/types/cli-error/error-message/validation-error-message.d.ts.map +1 -0
- package/lib/types/coerce/coerce-methods.d.ts +122 -0
- package/lib/types/coerce/coerce-methods.d.ts.map +1 -0
- package/lib/{typescript → types}/coerce/string-to-array.d.ts +2 -2
- package/lib/types/coerce/string-to-array.d.ts.map +1 -0
- package/lib/types/coerce/string-to-primitive.d.ts +21 -0
- package/lib/types/coerce/string-to-primitive.d.ts.map +1 -0
- package/lib/{typescript → types}/coerce/string-to-set.d.ts +2 -2
- package/lib/{typescript → types}/coerce/string-to-set.d.ts.map +1 -1
- package/lib/{typescript → types}/definitions/define-cli.d.ts +2 -6
- package/lib/types/definitions/define-cli.d.ts.map +1 -0
- package/lib/{typescript → types}/definitions/define-subcommand.d.ts +2 -4
- package/lib/types/definitions/define-subcommand.d.ts.map +1 -0
- package/lib/{typescript → types}/definitions/validate-cli-definition.d.ts +1 -1
- package/lib/types/definitions/validate-cli-definition.d.ts.map +1 -0
- package/lib/{typescript → types}/help-message/terminal-markdown.d.ts.map +1 -1
- package/lib/{typescript → types}/index.d.ts +7 -0
- package/lib/{typescript → types}/index.d.ts.map +1 -1
- package/lib/{typescript → types}/metadata/arguments-metadata.d.ts.map +1 -1
- package/lib/{typescript → types}/metadata/options-metadata.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/context/cli-context-builder.d.ts +1 -1
- package/lib/{typescript → types}/parse/context/cli-context-builder.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/context/object-context-builder.d.ts +1 -1
- package/lib/types/parse/context/object-context-builder.d.ts.map +1 -0
- package/lib/{typescript → types}/parse/parser-utilities.d.ts +9 -0
- package/lib/{typescript → types}/parse/parser-utilities.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/safe-parse.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/validation/validate-context.d.ts +1 -1
- package/lib/{typescript → types}/parse/validation/validate-context.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/validation/validators/arguments.d.ts +1 -1
- package/lib/{typescript → types}/parse/validation/validators/arguments.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/validation/validators/conflict.d.ts +3 -3
- package/lib/{typescript → types}/parse/validation/validators/conflict.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/validation/validators/exclusive.d.ts +3 -3
- package/lib/{typescript → types}/parse/validation/validators/exclusive.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/validation/validators/options.d.ts +1 -1
- package/lib/{typescript → types}/parse/validation/validators/options.d.ts.map +1 -1
- package/lib/{typescript → types}/parse/validation/validators/requires.d.ts +3 -3
- package/lib/{typescript → types}/parse/validation/validators/requires.d.ts.map +1 -1
- package/lib/{typescript → types}/types/definitions-types.d.ts +35 -4
- package/lib/types/types/definitions-types.d.ts.map +1 -0
- package/lib/types/types/error-types.d.ts +275 -0
- package/lib/types/types/error-types.d.ts.map +1 -0
- package/lib/types/types/types.d.ts +146 -0
- package/lib/types/types/types.d.ts.map +1 -0
- package/lib/{typescript → types}/types/utilities-types.d.ts +0 -2
- package/lib/{typescript → types}/types/utilities-types.d.ts.map +1 -1
- package/lib/types/utilities/parse-argv.d.ts +3 -0
- package/lib/types/utilities/parse-argv.d.ts.map +1 -0
- package/lib/types/utilities/schema-utilities.d.ts +15 -0
- package/lib/types/utilities/schema-utilities.d.ts.map +1 -0
- package/lib/{typescript → types/utilities}/utilities.d.ts +12 -15
- package/lib/types/utilities/utilities.d.ts.map +1 -0
- package/package.json +10 -9
- package/src/autocomplete-scripts/bash-autocomplete-script.ts +14 -12
- package/src/autocomplete-scripts/powershell-autocomplete-script.ts +67 -33
- package/src/autocomplete-scripts/zsh-autocomplete-script.ts +39 -31
- package/src/cli-error/cli-error.ts +44 -0
- package/src/cli-error/error-cause.ts +10 -0
- package/src/cli-error/error-code/definition-error-code.ts +21 -0
- package/src/cli-error/error-code/internal-error-code.ts +8 -0
- package/src/cli-error/error-code/parse-error-code.ts +16 -0
- package/src/cli-error/error-code/validation-error-code.ts +15 -0
- package/src/cli-error/error-message/definition-error-message.ts +144 -0
- package/src/cli-error/error-message/internal-error-message.ts +19 -0
- package/src/cli-error/error-message/parse-error-message.ts +76 -0
- package/src/cli-error/error-message/validation-error-message.ts +104 -0
- package/src/coerce/coerce-methods.ts +194 -39
- package/src/coerce/string-to-array.ts +2 -2
- package/src/coerce/string-to-primitive.ts +72 -13
- package/src/coerce/string-to-set.ts +2 -2
- package/src/definitions/define-arguments.ts +1 -1
- package/src/definitions/define-cli.ts +65 -30
- package/src/definitions/define-options.ts +1 -1
- package/src/definitions/define-subcommand.ts +47 -17
- package/src/definitions/validate-cli-definition.ts +287 -172
- package/src/help-message/format-arguments.ts +1 -1
- package/src/help-message/format-options.ts +1 -1
- package/src/help-message/format-subcommands.ts +1 -1
- package/src/help-message/generate-for-cli.ts +1 -1
- package/src/help-message/terminal-markdown.ts +3 -4
- package/src/index.ts +16 -0
- package/src/markdown/generate-markdown.ts +5 -4
- package/src/metadata/arguments-metadata.ts +2 -1
- package/src/metadata/options-metadata.ts +2 -1
- package/src/parse/context/cli-context-builder.ts +166 -39
- package/src/parse/context/object-context-builder.ts +37 -11
- package/src/parse/parser-utilities.ts +24 -10
- package/src/parse/safe-parse.ts +3 -6
- package/src/parse/validation/validate-context.ts +1 -1
- package/src/parse/validation/validators/arguments.ts +42 -14
- package/src/parse/validation/validators/conflict.ts +11 -20
- package/src/parse/validation/validators/exclusive.ts +16 -25
- package/src/parse/validation/validators/options.ts +40 -12
- package/src/parse/validation/validators/requires.ts +11 -20
- package/src/types/definitions-types.ts +36 -8
- package/src/types/error-types.ts +326 -0
- package/src/types/types.ts +100 -7
- package/src/types/utilities-types.ts +0 -10
- package/src/utilities/parse-argv.ts +79 -0
- package/src/utilities/schema-utilities.ts +72 -0
- package/src/{utilities.ts → utilities/utilities.ts} +25 -138
- package/lib/cjs/autocomplete-scripts/bash-autocomplete-script.cjs +0 -2
- package/lib/cjs/autocomplete-scripts/bash-autocomplete-script.cjs.map +0 -1
- package/lib/cjs/autocomplete-scripts/powershell-autocomplete-script.cjs +0 -2
- package/lib/cjs/autocomplete-scripts/powershell-autocomplete-script.cjs.map +0 -1
- package/lib/cjs/autocomplete-scripts/zsh-autocomplete-script.cjs +0 -42
- package/lib/cjs/autocomplete-scripts/zsh-autocomplete-script.cjs.map +0 -1
- package/lib/cjs/coerce/coerce-methods.cjs +0 -2
- package/lib/cjs/coerce/coerce-methods.cjs.map +0 -1
- package/lib/cjs/coerce/string-to-array.cjs +0 -2
- package/lib/cjs/coerce/string-to-array.cjs.map +0 -1
- package/lib/cjs/coerce/string-to-primitive.cjs +0 -2
- package/lib/cjs/coerce/string-to-primitive.cjs.map +0 -1
- package/lib/cjs/coerce/string-to-set.cjs +0 -2
- package/lib/cjs/coerce/string-to-set.cjs.map +0 -1
- package/lib/cjs/definitions/define-arguments.cjs +0 -2
- package/lib/cjs/definitions/define-arguments.cjs.map +0 -1
- package/lib/cjs/definitions/define-cli.cjs +0 -2
- package/lib/cjs/definitions/define-cli.cjs.map +0 -1
- package/lib/cjs/definitions/define-options.cjs +0 -2
- package/lib/cjs/definitions/define-options.cjs.map +0 -1
- package/lib/cjs/definitions/define-subcommand.cjs +0 -2
- package/lib/cjs/definitions/define-subcommand.cjs.map +0 -1
- package/lib/cjs/definitions/validate-cli-definition.cjs +0 -2
- package/lib/cjs/definitions/validate-cli-definition.cjs.map +0 -1
- package/lib/cjs/help-message/format-arguments.cjs +0 -2
- package/lib/cjs/help-message/format-arguments.cjs.map +0 -1
- package/lib/cjs/help-message/format-options.cjs +0 -2
- package/lib/cjs/help-message/format-options.cjs.map +0 -1
- package/lib/cjs/help-message/format-subcommands.cjs +0 -2
- package/lib/cjs/help-message/format-subcommands.cjs.map +0 -1
- package/lib/cjs/help-message/generate-for-cli.cjs +0 -2
- package/lib/cjs/help-message/generate-for-cli.cjs.map +0 -1
- package/lib/cjs/help-message/generate-for-subcommand.cjs +0 -2
- package/lib/cjs/help-message/generate-for-subcommand.cjs.map +0 -1
- package/lib/cjs/help-message/print-help.cjs +0 -2
- package/lib/cjs/help-message/print-help.cjs.map +0 -1
- package/lib/cjs/help-message/set-defaults.cjs +0 -2
- package/lib/cjs/help-message/set-defaults.cjs.map +0 -1
- package/lib/cjs/help-message/styles.cjs +0 -2
- package/lib/cjs/help-message/styles.cjs.map +0 -1
- package/lib/cjs/help-message/terminal-markdown.cjs +0 -2
- package/lib/cjs/help-message/terminal-markdown.cjs.map +0 -1
- package/lib/cjs/index.cjs +0 -2
- package/lib/cjs/index.cjs.map +0 -1
- package/lib/cjs/markdown/generate-markdown.cjs +0 -2
- package/lib/cjs/markdown/generate-markdown.cjs.map +0 -1
- package/lib/cjs/metadata/arguments-metadata.cjs +0 -2
- package/lib/cjs/metadata/arguments-metadata.cjs.map +0 -1
- package/lib/cjs/metadata/cli-metadata.cjs +0 -2
- package/lib/cjs/metadata/cli-metadata.cjs.map +0 -1
- package/lib/cjs/metadata/options-metadata.cjs +0 -2
- package/lib/cjs/metadata/options-metadata.cjs.map +0 -1
- package/lib/cjs/metadata/subcommands-metadata.cjs +0 -2
- package/lib/cjs/metadata/subcommands-metadata.cjs.map +0 -1
- package/lib/cjs/parse/context/cli-context-builder.cjs +0 -2
- package/lib/cjs/parse/context/cli-context-builder.cjs.map +0 -1
- package/lib/cjs/parse/context/object-context-builder.cjs +0 -2
- package/lib/cjs/parse/context/object-context-builder.cjs.map +0 -1
- package/lib/cjs/parse/parser-utilities.cjs +0 -2
- package/lib/cjs/parse/parser-utilities.cjs.map +0 -1
- package/lib/cjs/parse/safe-parse.cjs +0 -2
- package/lib/cjs/parse/safe-parse.cjs.map +0 -1
- package/lib/cjs/parse/validation/validate-context.cjs +0 -2
- package/lib/cjs/parse/validation/validate-context.cjs.map +0 -1
- package/lib/cjs/parse/validation/validators/arguments.cjs +0 -2
- package/lib/cjs/parse/validation/validators/arguments.cjs.map +0 -1
- package/lib/cjs/parse/validation/validators/conflict.cjs +0 -2
- package/lib/cjs/parse/validation/validators/conflict.cjs.map +0 -1
- package/lib/cjs/parse/validation/validators/exclusive.cjs +0 -2
- package/lib/cjs/parse/validation/validators/exclusive.cjs.map +0 -1
- package/lib/cjs/parse/validation/validators/explicitly-passed.cjs +0 -2
- package/lib/cjs/parse/validation/validators/explicitly-passed.cjs.map +0 -1
- package/lib/cjs/parse/validation/validators/options.cjs +0 -2
- package/lib/cjs/parse/validation/validators/options.cjs.map +0 -1
- package/lib/cjs/parse/validation/validators/requires.cjs +0 -2
- package/lib/cjs/parse/validation/validators/requires.cjs.map +0 -1
- package/lib/cjs/utilities.cjs +0 -2
- package/lib/cjs/utilities.cjs.map +0 -1
- package/lib/esm/utilities.js +0 -2
- package/lib/esm/utilities.js.map +0 -1
- package/lib/mjs/utilities.mjs +0 -2
- package/lib/mjs/utilities.mjs.map +0 -1
- package/lib/typescript/autocomplete-scripts/powershell-autocomplete-script.d.ts +0 -14
- package/lib/typescript/autocomplete-scripts/zsh-autocomplete-script.d.ts +0 -11
- package/lib/typescript/coerce/coerce-methods.d.ts +0 -20
- package/lib/typescript/coerce/coerce-methods.d.ts.map +0 -1
- package/lib/typescript/coerce/string-to-array.d.ts.map +0 -1
- package/lib/typescript/coerce/string-to-primitive.d.ts +0 -5
- package/lib/typescript/coerce/string-to-primitive.d.ts.map +0 -1
- package/lib/typescript/definitions/define-cli.d.ts.map +0 -1
- package/lib/typescript/definitions/define-subcommand.d.ts.map +0 -1
- package/lib/typescript/definitions/validate-cli-definition.d.ts.map +0 -1
- package/lib/typescript/parse/context/object-context-builder.d.ts.map +0 -1
- package/lib/typescript/types/definitions-types.d.ts.map +0 -1
- package/lib/typescript/types/types.d.ts +0 -61
- package/lib/typescript/types/types.d.ts.map +0 -1
- package/lib/typescript/utilities.d.ts.map +0 -1
- /package/lib/{typescript → types}/autocomplete-scripts/bash-autocomplete-script.d.ts +0 -0
- /package/lib/{typescript → types}/definitions/define-arguments.d.ts +0 -0
- /package/lib/{typescript → types}/definitions/define-arguments.d.ts.map +0 -0
- /package/lib/{typescript → types}/definitions/define-options.d.ts +0 -0
- /package/lib/{typescript → types}/definitions/define-options.d.ts.map +0 -0
- /package/lib/{typescript → types}/help-message/format-arguments.d.ts +0 -0
- /package/lib/{typescript → types}/help-message/format-arguments.d.ts.map +0 -0
- /package/lib/{typescript → types}/help-message/format-options.d.ts +0 -0
- /package/lib/{typescript → types}/help-message/format-options.d.ts.map +0 -0
- /package/lib/{typescript → types}/help-message/format-subcommands.d.ts +0 -0
- /package/lib/{typescript → types}/help-message/format-subcommands.d.ts.map +0 -0
- /package/lib/{typescript → types}/help-message/generate-for-cli.d.ts +0 -0
- /package/lib/{typescript → types}/help-message/generate-for-cli.d.ts.map +0 -0
- /package/lib/{typescript → types}/help-message/generate-for-subcommand.d.ts +0 -0
- /package/lib/{typescript → types}/help-message/generate-for-subcommand.d.ts.map +0 -0
- /package/lib/{typescript → types}/help-message/print-help.d.ts +0 -0
- /package/lib/{typescript → types}/help-message/print-help.d.ts.map +0 -0
- /package/lib/{typescript → types}/help-message/set-defaults.d.ts +0 -0
- /package/lib/{typescript → types}/help-message/set-defaults.d.ts.map +0 -0
- /package/lib/{typescript → types}/help-message/styles.d.ts +0 -0
- /package/lib/{typescript → types}/help-message/styles.d.ts.map +0 -0
- /package/lib/{typescript → types}/help-message/terminal-markdown.d.ts +0 -0
- /package/lib/{typescript → types}/markdown/generate-markdown.d.ts +0 -0
- /package/lib/{typescript → types}/markdown/generate-markdown.d.ts.map +0 -0
- /package/lib/{typescript → types}/metadata/arguments-metadata.d.ts +0 -0
- /package/lib/{typescript → types}/metadata/cli-metadata.d.ts +0 -0
- /package/lib/{typescript → types}/metadata/cli-metadata.d.ts.map +0 -0
- /package/lib/{typescript → types}/metadata/options-metadata.d.ts +0 -0
- /package/lib/{typescript → types}/metadata/subcommands-metadata.d.ts +0 -0
- /package/lib/{typescript → types}/metadata/subcommands-metadata.d.ts.map +0 -0
- /package/lib/{typescript → types}/parse/safe-parse.d.ts +0 -0
- /package/lib/{typescript → types}/parse/validation/validators/explicitly-passed.d.ts +0 -0
- /package/lib/{typescript → types}/parse/validation/validators/explicitly-passed.d.ts.map +0 -0
- /package/lib/{typescript → types}/types/context-types.d.ts +0 -0
- /package/lib/{typescript → types}/types/context-types.d.ts.map +0 -0
- /package/lib/{typescript → types}/types/help-message-types.d.ts +0 -0
- /package/lib/{typescript → types}/types/help-message-types.d.ts.map +0 -0
- /package/lib/{typescript → types}/types/io-types.d.ts +0 -0
- /package/lib/{typescript → types}/types/io-types.d.ts.map +0 -0
- /package/lib/{typescript → types}/types/metadata-types.d.ts +0 -0
- /package/lib/{typescript → types}/types/metadata-types.d.ts.map +0 -0
- /package/lib/{typescript → types}/types/schema-types.d.ts +0 -0
- /package/lib/{typescript → types}/types/schema-types.d.ts.map +0 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Argument, Option } from "../types/definitions-types.ts";
|
|
2
|
+
import type { SchemaResult, SchemaType } from "../types/schema-types.ts";
|
|
3
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
4
|
+
/** @throws {CliError} When schema is async */
|
|
5
|
+
export declare function validateSync(schema: SchemaType, value?: unknown): SchemaResult;
|
|
6
|
+
/** @throws {CliError} When schema is async */
|
|
7
|
+
export declare function defaultValueAndIsOptional(schema: SchemaType): {
|
|
8
|
+
defaultValue: unknown;
|
|
9
|
+
optional: boolean;
|
|
10
|
+
};
|
|
11
|
+
/** @throws {CliError} When schema is async */
|
|
12
|
+
export declare function prepareDefinitionTypes(definition: Record<string, Argument> | Record<string, Option> | undefined): void;
|
|
13
|
+
/** Prettify Standard Schema V1 issues */
|
|
14
|
+
export declare function prettifyError(issues: ReadonlyArray<StandardSchemaV1.Issue>): string;
|
|
15
|
+
//# sourceMappingURL=schema-utilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-utilities.d.ts","sourceRoot":"","sources":["../../../src/utilities/schema-utilities.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAgB,MAAM,+BAA+B,CAAC;AACpF,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,8CAA8C;AAC9C,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,YAAY,CAW9E;AAED,8CAA8C;AAC9C,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,UAAU,GAAG;IAAE,YAAY,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,CAQ1G;AAeD,8CAA8C;AAC9C,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,QAY/G;AAED,yCAAyC;AACzC,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa,CAAC,gBAAgB,CAAC,KAAK,CAAC,GAAG,MAAM,CAQnF"}
|
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { SubcommandMetadata } from "./types/metadata-types.ts";
|
|
3
|
-
import type { SchemaResult, SchemaType } from "./types/schema-types.ts";
|
|
4
|
-
import type { CoerceMethod } from "./types/types.ts";
|
|
5
|
-
/** @throws */
|
|
6
|
-
export declare function validateSync(schema: SchemaType, value?: unknown): SchemaResult;
|
|
7
|
-
export declare function defaultValueAndIsOptional(schema: SchemaType): {
|
|
8
|
-
defaultValue: unknown;
|
|
9
|
-
optional: boolean;
|
|
10
|
-
};
|
|
11
|
-
export declare function PrepareType(schema: SchemaType, coerceHandler: CoerceMethod<unknown>): PreparedType;
|
|
12
|
-
export declare function prepareDefinitionTypes(definition: Record<string, Argument> | Record<string, Option> | undefined): void;
|
|
1
|
+
import type { SubcommandMetadata } from "../types/metadata-types.ts";
|
|
13
2
|
export declare function toKebabCase(input: string): string;
|
|
14
3
|
/**
|
|
15
4
|
* Converts a zero-based index into its human-readable ordinal form.
|
|
@@ -33,13 +22,21 @@ export declare function stringifyValue(value: unknown): string;
|
|
|
33
22
|
export declare function insertAtEndOfFirstLine(string: string, insert: string): string;
|
|
34
23
|
/** Get the placeholder for a subcommand */
|
|
35
24
|
export declare function subcommandPlaceholder(metadata: SubcommandMetadata): string;
|
|
36
|
-
/** Parse a string into an argv (array of arguments) */
|
|
37
|
-
export declare function parseArgv(input: string): string[];
|
|
38
25
|
/**
|
|
39
26
|
* Escape HTML characters inside HTML tags in a Markdown string, but leave code blocks, inline code, and HTML comments
|
|
40
27
|
* unchanged.
|
|
41
28
|
*/
|
|
42
29
|
export declare function escapeHtmlTags(markdown: string): string;
|
|
43
30
|
export declare function stripAnsi(string: string): string;
|
|
44
|
-
|
|
31
|
+
type WalkCallback = (key: string, value: unknown, path: string) => unknown;
|
|
32
|
+
/**
|
|
33
|
+
* Recursively walks through an object and calls a function for each key-value pair.
|
|
34
|
+
*
|
|
35
|
+
* @param object_ - The object to walk.
|
|
36
|
+
* @param onVisit - Function called on every visited property (key, value, path).
|
|
37
|
+
* @param basePath - (Internal) Used for recursion to build nested paths.
|
|
38
|
+
*/
|
|
39
|
+
export declare function walkObject(object_: Record<string, unknown>, onVisit: WalkCallback, basePath?: string): void;
|
|
40
|
+
export declare function Enum<const T extends Record<string, undefined>>(value: T): { [K in keyof T]: K; };
|
|
41
|
+
export {};
|
|
45
42
|
//# sourceMappingURL=utilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../../../src/utilities/utilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAErE,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CA2B3D;AAED,eAAe;AACf,wBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,UAE/B;AAED,YAAY;AACZ,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,UAGnC;AAED,wGAAwG;AACxG,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAEhE;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAcrD;AAED,+CAA+C;AAC/C,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAIpE;AAED,2CAA2C;AAC3C,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,MAAM,CAwB1E;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAgBvD;AAoBD,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,KAAK,YAAY,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;AAE3E;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,QAAQ,SAAK,GAAG,IAAI,CAcvG;AAED,wBAAgB,IAAI,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC,GAGtC,GAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,GAAE,CACtD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zod-args-parser",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.3",
|
|
4
4
|
"description": "A TypeScript-first CLI argument parser with schema-based validation.",
|
|
5
5
|
"author": "Ahmed ALABSI <alabsi91@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,22 +9,23 @@
|
|
|
9
9
|
"url": "https://github.com/alabsi91/zod-args-parser.git"
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
12
|
+
"sideEffects": false,
|
|
12
13
|
"scripts": {
|
|
13
14
|
"dev": "tsx --watch example/index.ts",
|
|
14
15
|
"build": "node scripts/build.ts",
|
|
15
16
|
"test": "node --test && echo Checking types... && tsgo --noEmit && echo Linting... && eslint --config eslint.config.js --fix",
|
|
16
17
|
"prepare": "npm run test && npm run build"
|
|
17
18
|
},
|
|
19
|
+
"jsdelivr": "./lib/iife/index.js",
|
|
20
|
+
"unpkg": "./lib/iife/index.js",
|
|
18
21
|
"exports": {
|
|
19
22
|
".": {
|
|
20
|
-
"types": "./lib/
|
|
23
|
+
"types": "./lib/types/index.d.ts",
|
|
21
24
|
"browser": "./lib/esm/index.js",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
25
|
+
"node": "./lib/mjs/index.mjs",
|
|
26
|
+
"default": "./lib/esm/index.js"
|
|
24
27
|
}
|
|
25
28
|
},
|
|
26
|
-
"jsdelivr": "./lib/iife/index.js",
|
|
27
|
-
"unpkg": "./lib/iife/index.js",
|
|
28
29
|
"files": [
|
|
29
30
|
"lib",
|
|
30
31
|
"src"
|
|
@@ -43,7 +44,7 @@
|
|
|
43
44
|
"@eslint/js": "^9.39.1",
|
|
44
45
|
"@eslint/markdown": "^7.5.1",
|
|
45
46
|
"@trivago/prettier-plugin-sort-imports": "^6.0.0",
|
|
46
|
-
"@types/node": "^24.10.
|
|
47
|
+
"@types/node": "^24.10.1",
|
|
47
48
|
"@typescript/native-preview": "^7.0.0-dev.20251104.1",
|
|
48
49
|
"esbuild": "^0.27.0",
|
|
49
50
|
"eslint": "^9.39.1",
|
|
@@ -60,8 +61,8 @@
|
|
|
60
61
|
"zod": "^4.1.12"
|
|
61
62
|
},
|
|
62
63
|
"dependencies": {
|
|
63
|
-
"@standard-schema/spec": "^1.0.0",
|
|
64
64
|
"chalk": "^5.6.2",
|
|
65
|
-
"marked": "^17.0.0"
|
|
65
|
+
"marked": "^17.0.0",
|
|
66
|
+
"@standard-schema/spec": "^1.0.0"
|
|
66
67
|
}
|
|
67
68
|
}
|
|
@@ -12,11 +12,10 @@ import type { Cli } from "../types/definitions-types.ts";
|
|
|
12
12
|
*/
|
|
13
13
|
export function generateBashAutocompleteScript(cliDefinition: Cli): string {
|
|
14
14
|
const subcommands = cliDefinition.subcommands ?? [];
|
|
15
|
-
|
|
16
15
|
type MappedCommands = Record<string, { options: string[]; aliases: string[] }>;
|
|
17
16
|
|
|
17
|
+
// Map subcommands to options + aliases
|
|
18
18
|
const mappedCommands: MappedCommands = {};
|
|
19
|
-
|
|
20
19
|
for (const subcommand of subcommands) {
|
|
21
20
|
mappedCommands[subcommand.name] = {
|
|
22
21
|
options: subcommand.options ? Object.keys(subcommand.options).map(key => transformOptionToArgument(key)) : [],
|
|
@@ -24,19 +23,23 @@ export function generateBashAutocompleteScript(cliDefinition: Cli): string {
|
|
|
24
23
|
};
|
|
25
24
|
}
|
|
26
25
|
|
|
26
|
+
// Generate switch-case block for subcommands + aliases
|
|
27
27
|
let switchCase = "";
|
|
28
|
-
for (const [
|
|
29
|
-
|
|
28
|
+
for (const [name, { options, aliases }] of Object.entries(mappedCommands)) {
|
|
29
|
+
const caseNames = [name, ...aliases];
|
|
30
|
+
switchCase += ` ${caseNames.join("|")})\n`;
|
|
30
31
|
switchCase += ` opts="${options.join(" ")}"\n`;
|
|
31
32
|
switchCase += " ;;\n";
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
// Include global CLI options in a default case
|
|
36
|
+
const globalOptions = cliDefinition.options
|
|
37
|
+
? Object.keys(cliDefinition.options).map(key => transformOptionToArgument(key))
|
|
38
|
+
: [];
|
|
39
|
+
|
|
40
|
+
if (globalOptions.length > 0) {
|
|
41
|
+
switchCase += ` *)\n`;
|
|
42
|
+
switchCase += ` opts="${globalOptions.join(" ")}"\n`;
|
|
40
43
|
switchCase += " ;;\n";
|
|
41
44
|
}
|
|
42
45
|
|
|
@@ -52,8 +55,7 @@ _${cliDefinition.cliName}_autocomplete() {
|
|
|
52
55
|
commands="${Object.keys(mappedCommands).join(" ")}"
|
|
53
56
|
|
|
54
57
|
case "$subcommand" in
|
|
55
|
-
${switchCase}
|
|
56
|
-
esac
|
|
58
|
+
${switchCase} esac
|
|
57
59
|
|
|
58
60
|
used_opts=""
|
|
59
61
|
if [[ " \${commands[@]} " =~ " $subcommand " ]]; then
|
|
@@ -3,83 +3,117 @@ import { transformOptionToArgument } from "../parse/parser-utilities.ts";
|
|
|
3
3
|
import type { Cli } from "../types/definitions-types.ts";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* - The script assumes that your CLI is available as a `.ps1` file in the environment variable. For example:
|
|
8
|
-
* `cliName.ps1`.
|
|
9
|
-
* - This should return a path to your script: `(Get-Command <cliName>.ps1).Source`
|
|
10
|
-
* - The generated script should be added to your `profile.ps1` file:
|
|
6
|
+
* Generates a PowerShell autocomplete script for a CLI.
|
|
11
7
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
8
|
+
* Instructions:
|
|
9
|
+
*
|
|
10
|
+
* - Ensure your CLI is available as a `.ps1` file in your environment. e.g., `cliName.ps1`.
|
|
11
|
+
* - Add the generated script to your `profile.ps1` file:
|
|
12
|
+
*
|
|
13
|
+
* 1. Run: `notepad $profile`
|
|
14
|
+
* 2. Add: `. "<generated script path>"`
|
|
15
|
+
* 3. Save and reopen PowerShell
|
|
15
16
|
*/
|
|
16
17
|
export function generatePowerShellAutocompleteScript(cliDefinition: Cli): string {
|
|
17
18
|
const subcommands = cliDefinition.subcommands ?? [];
|
|
18
19
|
const meta = cliDefinition.meta ?? {};
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
interface CommandData {
|
|
22
|
+
options: string[];
|
|
23
|
+
aliases: string[];
|
|
24
|
+
}
|
|
21
25
|
|
|
22
|
-
const mappedCommands:
|
|
26
|
+
const mappedCommands: Record<string, CommandData> = {};
|
|
23
27
|
|
|
28
|
+
// Map subcommands to their options and aliases
|
|
24
29
|
for (const subcommand of subcommands) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
const options: string[] = [];
|
|
31
|
+
if (subcommand.options) {
|
|
32
|
+
for (const key of Object.keys(subcommand.options)) {
|
|
33
|
+
options.push(transformOptionToArgument(key));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const aliases: string[] = subcommand.aliases ?? [];
|
|
38
|
+
mappedCommands[subcommand.name] = { options, aliases };
|
|
29
39
|
}
|
|
30
40
|
|
|
41
|
+
// Prepare string representations for subcommands and CLI global options
|
|
31
42
|
const subcommandsString = Object.keys(mappedCommands)
|
|
32
43
|
.map(key => `'${key}'`)
|
|
33
44
|
.join(", ");
|
|
34
45
|
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
const cliOptions: string[] = [];
|
|
47
|
+
if (cliDefinition.options) {
|
|
48
|
+
for (const key of Object.keys(cliDefinition.options)) {
|
|
49
|
+
cliOptions.push(transformOptionToArgument(key));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const cliOptionsString = cliOptions.map(opt => `'${opt}'`).join(", ");
|
|
39
54
|
|
|
55
|
+
// Build the switch-case mapping subcommands/aliases to their options
|
|
40
56
|
let switchCase = "switch ($subcommand) {\n";
|
|
41
|
-
for (const
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
57
|
+
for (const commandName in mappedCommands) {
|
|
58
|
+
const data = mappedCommands[commandName];
|
|
59
|
+
const optionsString = data.options.map(opt => `'${opt}'`).join(", ");
|
|
60
|
+
|
|
61
|
+
// Primary subcommand
|
|
62
|
+
switchCase += ` '${commandName}' { @(${optionsString}) }\n`;
|
|
63
|
+
|
|
64
|
+
// Aliases
|
|
65
|
+
for (const alias of data.aliases) {
|
|
66
|
+
switchCase += ` '${alias}' { @(${optionsString}) }\n`;
|
|
46
67
|
}
|
|
47
68
|
}
|
|
69
|
+
|
|
70
|
+
// Default case returns global CLI options
|
|
48
71
|
switchCase += ` default { @(${cliOptionsString}) }\n }`;
|
|
49
72
|
|
|
50
|
-
|
|
73
|
+
// Optional comment block with description/example
|
|
74
|
+
let commentBlock = "";
|
|
75
|
+
if (meta.description || meta.example) {
|
|
76
|
+
commentBlock = "<#\n";
|
|
77
|
+
|
|
78
|
+
if (meta.description || meta.descriptionMarkdown) {
|
|
79
|
+
commentBlock += `.DESCRIPTION\n${meta.description ?? meta.descriptionMarkdown}\n\n`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (meta.example) {
|
|
83
|
+
commentBlock += `.EXAMPLE\n${meta.example}\n`;
|
|
84
|
+
}
|
|
51
85
|
|
|
52
|
-
|
|
53
|
-
if (description) {
|
|
54
|
-
functionInfo = `<#\n.DESCRIPTION\n${description}\n${meta.example ? `\n.EXAMPLE\n${meta.example}` : ""}\n#>`;
|
|
86
|
+
commentBlock += "#>";
|
|
55
87
|
}
|
|
56
88
|
|
|
89
|
+
const cliName = cliDefinition.cliName;
|
|
90
|
+
|
|
57
91
|
return `# Auto-generated by zod-args-parser
|
|
58
92
|
|
|
59
|
-
${
|
|
60
|
-
function ${
|
|
93
|
+
${commentBlock}
|
|
94
|
+
function ${cliName} {
|
|
61
95
|
param(
|
|
62
96
|
[Parameter(Position = 0, Mandatory = $false)]
|
|
63
97
|
[string]$subcommand,
|
|
64
98
|
[Parameter(Position = 1, ValueFromRemainingArguments = $true)]
|
|
65
99
|
[string[]]$arguments
|
|
66
100
|
)
|
|
67
|
-
$scriptPath = (Get-Command '${
|
|
101
|
+
$scriptPath = (Get-Command '${cliName}.ps1').Source
|
|
68
102
|
if ($scriptPath) {
|
|
69
103
|
$argumentList = @($subcommand) + ($arguments | Where-Object { $_ -notin '--', '--%' }) | Where-Object { $_ -ne '' }
|
|
70
104
|
& $scriptPath @argumentList
|
|
71
105
|
return
|
|
72
106
|
}
|
|
73
|
-
Write-Error "Could not find '${
|
|
107
|
+
Write-Error "Could not find '${cliName}.ps1' script"
|
|
74
108
|
}
|
|
75
109
|
|
|
76
|
-
Register-ArgumentCompleter -CommandName '${
|
|
110
|
+
Register-ArgumentCompleter -CommandName '${cliName}' -ParameterName 'subcommand' -ScriptBlock {
|
|
77
111
|
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
|
|
78
112
|
$subcommands = @(${subcommandsString}${subcommandsString && cliOptionsString ? ", " : ""}${cliOptionsString})
|
|
79
113
|
$subcommands | Where-Object { $_ -like "$wordToComplete*" }
|
|
80
114
|
}
|
|
81
115
|
|
|
82
|
-
Register-ArgumentCompleter -CommandName '${
|
|
116
|
+
Register-ArgumentCompleter -CommandName '${cliName}' -ParameterName 'arguments' -ScriptBlock {
|
|
83
117
|
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
|
|
84
118
|
$subcommand = $commandAst.CommandElements[1].Value
|
|
85
119
|
$arguments = ${switchCase}
|
|
@@ -2,58 +2,66 @@ import { transformOptionToArgument } from "../parse/parser-utilities.ts";
|
|
|
2
2
|
|
|
3
3
|
import type { Cli, Subcommand } from "../types/definitions-types.ts";
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* - Generates a ZSH autocomplete script for your CLI.
|
|
7
|
-
* - The generated script should be added to your `~/.zshrc` or `~/.zsh_profile` file:
|
|
8
|
-
*
|
|
9
|
-
* - Run: `nano $HOME/.zshrc` or `nano $HOME/.zsh_profile`
|
|
10
|
-
* - Add the following line: `source <generated script path>`
|
|
11
|
-
* - Save and reopen zsh to take effect
|
|
12
|
-
*/
|
|
5
|
+
/** Generates a Zsh autocomplete script for a CLI, including global options when no subcommand is provided. */
|
|
13
6
|
export function generateZshAutocompleteScript(cliDefinition: Cli): string {
|
|
14
7
|
const subcommands = cliDefinition.subcommands ?? [];
|
|
15
8
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return
|
|
9
|
+
/** Generate the argument strings for a subcommand Format: 'option[description]' */
|
|
10
|
+
const generateArguments = (command: Subcommand) => {
|
|
11
|
+
if (!command.options) return "";
|
|
12
|
+
const arguments_ = Object.entries(command.options).map(([name, option]) => {
|
|
13
|
+
const description = option.meta?.description ?? "";
|
|
14
|
+
return `'${transformOptionToArgument(name)}[${description}]'`;
|
|
15
|
+
});
|
|
16
|
+
return arguments_.join(" \\\n ");
|
|
24
17
|
};
|
|
25
18
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (!options) return "";
|
|
19
|
+
/** Generate a case block for a subcommand */
|
|
20
|
+
const generateSubcommandCase = (subcommand: Subcommand) => {
|
|
29
21
|
return String.raw`${subcommand.name})
|
|
30
22
|
_arguments \
|
|
31
|
-
${
|
|
23
|
+
${generateArguments(subcommand)} \
|
|
32
24
|
'*: :_files' \
|
|
33
25
|
&& ret=0
|
|
34
26
|
;;`;
|
|
35
27
|
};
|
|
36
28
|
|
|
29
|
+
const subcommandCases = subcommands
|
|
30
|
+
.map(cmd => generateSubcommandCase(cmd))
|
|
31
|
+
.filter(Boolean)
|
|
32
|
+
.join("\n ");
|
|
33
|
+
|
|
34
|
+
const commandDescriptions = subcommands.map(sub => `"${sub.name}:${sub.meta?.description ?? ""}"`).join("\n ");
|
|
35
|
+
|
|
36
|
+
// Global CLI options (only used when no subcommand is provided)
|
|
37
|
+
const globalOptions = cliDefinition.options
|
|
38
|
+
? Object.entries(cliDefinition.options)
|
|
39
|
+
.map(([name, option]) => {
|
|
40
|
+
const description = option.meta?.description ?? "";
|
|
41
|
+
return `'${transformOptionToArgument(name)}[${description}]'`;
|
|
42
|
+
})
|
|
43
|
+
.join(" \\\n ")
|
|
44
|
+
: "";
|
|
45
|
+
|
|
46
|
+
const cliName = cliDefinition.cliName;
|
|
47
|
+
|
|
37
48
|
return String.raw`# Auto-generated by zod-args-parser
|
|
38
49
|
|
|
39
|
-
_${
|
|
50
|
+
_${cliName}_autocomplete() {
|
|
40
51
|
local ret=1
|
|
41
52
|
|
|
42
53
|
_arguments -C \
|
|
43
|
-
'1: :_${
|
|
54
|
+
'1: :_${cliName}_commands' \
|
|
44
55
|
'*:: :->subcmds' \
|
|
45
56
|
&& ret=0
|
|
46
57
|
|
|
47
58
|
case $state in
|
|
48
59
|
subcmds)
|
|
49
60
|
case "$words[1]" in
|
|
50
|
-
${
|
|
51
|
-
.map(subCommand => genSubCommand(subCommand))
|
|
52
|
-
.filter(Boolean)
|
|
53
|
-
.join("\n ")}
|
|
61
|
+
${subcommandCases}
|
|
54
62
|
*)
|
|
55
63
|
_arguments \
|
|
56
|
-
'*: :_files' \
|
|
64
|
+
${globalOptions ? globalOptions + " \\\n " : ""}'*: :_files' \
|
|
57
65
|
&& ret=0
|
|
58
66
|
;;
|
|
59
67
|
esac
|
|
@@ -62,15 +70,15 @@ _${cliDefinition.cliName}_autocomplete() {
|
|
|
62
70
|
|
|
63
71
|
return $ret
|
|
64
72
|
}
|
|
65
|
-
|
|
66
|
-
_${
|
|
73
|
+
|
|
74
|
+
_${cliName}_commands() {
|
|
67
75
|
local -a commands=(
|
|
68
|
-
${
|
|
76
|
+
${commandDescriptions}
|
|
69
77
|
)
|
|
70
78
|
|
|
71
79
|
_describe -t subcommands 'subcommand' commands
|
|
72
80
|
}
|
|
73
81
|
|
|
74
|
-
compdef _${
|
|
82
|
+
compdef _${cliName}_autocomplete ${cliName}
|
|
75
83
|
`;
|
|
76
84
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ErrorCause } from "./error-cause.ts";
|
|
2
|
+
import { definitionErrorMessage } from "./error-message/definition-error-message.ts";
|
|
3
|
+
import { internalErrorMessage } from "./error-message/internal-error-message.ts";
|
|
4
|
+
import { parseErrorMessage } from "./error-message/parse-error-message.ts";
|
|
5
|
+
import { validationErrorMessage } from "./error-message/validation-error-message.ts";
|
|
6
|
+
|
|
7
|
+
import type { CliErrorImpl, CliErrorOptionUnion } from "../types/error-types.ts";
|
|
8
|
+
|
|
9
|
+
export class CliError extends Error implements CliErrorImpl {
|
|
10
|
+
readonly code;
|
|
11
|
+
readonly cause;
|
|
12
|
+
readonly context;
|
|
13
|
+
|
|
14
|
+
constructor(options: CliErrorOptionUnion) {
|
|
15
|
+
super(options.message ?? CliError.errorMessage(options));
|
|
16
|
+
|
|
17
|
+
this.cause = options.cause;
|
|
18
|
+
this.code = options.code;
|
|
19
|
+
this.context = options.context;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static errorMessage(options: CliErrorOptionUnion): string {
|
|
23
|
+
const defaultErrorMessage = "unknown error";
|
|
24
|
+
|
|
25
|
+
if (options.cause === ErrorCause.Internal) {
|
|
26
|
+
return internalErrorMessage(options) ?? defaultErrorMessage;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (options.cause === ErrorCause.Parse) {
|
|
30
|
+
return parseErrorMessage(options) ?? defaultErrorMessage;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (options.cause === ErrorCause.Definition) {
|
|
34
|
+
return definitionErrorMessage(options) ?? defaultErrorMessage;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (options.cause === ErrorCause.Validation) {
|
|
38
|
+
return validationErrorMessage(options) ?? defaultErrorMessage;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const executiveCheck: never = options;
|
|
42
|
+
return executiveCheck;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Enum } from "../utilities/utilities.ts";
|
|
2
|
+
|
|
3
|
+
import type { ErrorCauseI } from "../types/error-types.ts";
|
|
4
|
+
|
|
5
|
+
export const ErrorCause: { [K in keyof ErrorCauseI]: K } = Enum({
|
|
6
|
+
Internal: undefined,
|
|
7
|
+
Parse: undefined,
|
|
8
|
+
Validation: undefined,
|
|
9
|
+
Definition: undefined,
|
|
10
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Enum } from "../../utilities/utilities.ts";
|
|
2
|
+
|
|
3
|
+
import type { DefinitionErrorI } from "../../types/error-types.ts";
|
|
4
|
+
|
|
5
|
+
export const DefinitionErrorCode: { [K in keyof DefinitionErrorI]: K } = Enum({
|
|
6
|
+
MissingSchema: undefined,
|
|
7
|
+
EmptyDefinitionGroup: undefined,
|
|
8
|
+
MissingDefinitionName: undefined,
|
|
9
|
+
InvalidDefinitionOptionName: undefined,
|
|
10
|
+
InvalidDefinitionArgumentName: undefined,
|
|
11
|
+
InvalidOptionalArgumentDefinition: undefined,
|
|
12
|
+
DuplicateDefinitionName: undefined,
|
|
13
|
+
EmptyStringAliasName: undefined,
|
|
14
|
+
SelfRequire: undefined,
|
|
15
|
+
UnknownRequireName: undefined,
|
|
16
|
+
SelfConflict: undefined,
|
|
17
|
+
UnknownConflictName: undefined,
|
|
18
|
+
DefinitionRequiresConflictOverlap: undefined,
|
|
19
|
+
MissingOnExecute: undefined,
|
|
20
|
+
SubcommandHelpNotFound: undefined,
|
|
21
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Enum } from "../../utilities/utilities.ts";
|
|
2
|
+
|
|
3
|
+
import type { InternalErrorI } from "../../types/error-types.ts";
|
|
4
|
+
|
|
5
|
+
export const InternalErrorCode: { [K in keyof InternalErrorI]: K } = Enum({
|
|
6
|
+
MissingPreparedTypes: undefined,
|
|
7
|
+
CannotFindCliDefinition: undefined,
|
|
8
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Enum } from "../../utilities/utilities.ts";
|
|
2
|
+
|
|
3
|
+
import type { ParseErrorI } from "../../types/error-types.ts";
|
|
4
|
+
|
|
5
|
+
export const ParseErrorCode: { [K in keyof ParseErrorI]: K } = Enum({
|
|
6
|
+
UnknownSubcommand: undefined,
|
|
7
|
+
CommandWithoutOptions: undefined,
|
|
8
|
+
UnknownOption: undefined,
|
|
9
|
+
DuplicateOptionProvided: undefined,
|
|
10
|
+
InvalidNegationForNonBooleanOption: undefined,
|
|
11
|
+
PositionalArgumentNotAllowed: undefined,
|
|
12
|
+
MissingRequiredOption: undefined,
|
|
13
|
+
MissingRequiredArgument: undefined,
|
|
14
|
+
OptionMissingValue: undefined,
|
|
15
|
+
FlagAssignedValue: undefined,
|
|
16
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Enum } from "../../utilities/utilities.ts";
|
|
2
|
+
|
|
3
|
+
import type { ValidationErrorI } from "../../types/error-types.ts";
|
|
4
|
+
|
|
5
|
+
export const ValidationErrorCode: { [K in keyof ValidationErrorI]: K } = Enum({
|
|
6
|
+
NoOptionsToValidate: undefined,
|
|
7
|
+
NoArgumentsToValidate: undefined,
|
|
8
|
+
UnknownOptionValidation: undefined,
|
|
9
|
+
UnknownArgumentValidation: undefined,
|
|
10
|
+
SchemaValidationFailed: undefined,
|
|
11
|
+
MutuallyExclusiveConflict: undefined,
|
|
12
|
+
RequiredDependencyMissing: undefined,
|
|
13
|
+
AsyncSchemaNotSupported: undefined,
|
|
14
|
+
CoercionFailed: undefined,
|
|
15
|
+
});
|