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
|
@@ -1,12 +1,19 @@
|
|
|
1
|
+
import { CliError } from "../cli-error/cli-error.ts";
|
|
2
|
+
import { ErrorCause } from "../cli-error/error-cause.ts";
|
|
3
|
+
import { DefinitionErrorCode } from "../cli-error/error-code/definition-error-code.ts";
|
|
4
|
+
import { InternalErrorCode } from "../cli-error/error-code/internal-error-code.ts";
|
|
1
5
|
import { transformOptionToArgument } from "../parse/parser-utilities.ts";
|
|
2
|
-
import { findDuplicateStrings } from "../utilities.ts";
|
|
3
6
|
|
|
4
7
|
import type { Cli, Subcommand } from "../types/definitions-types.ts";
|
|
5
8
|
|
|
6
|
-
/** @throws {
|
|
9
|
+
/** @throws {CliError} If validation fails. */
|
|
7
10
|
export function validateCliDefinition(cliDefinition: Cli) {
|
|
8
11
|
if (!cliDefinition.cliName) {
|
|
9
|
-
throw new
|
|
12
|
+
throw new CliError({
|
|
13
|
+
cause: ErrorCause.Definition,
|
|
14
|
+
code: DefinitionErrorCode.MissingDefinitionName,
|
|
15
|
+
context: { commandKind: "command" },
|
|
16
|
+
});
|
|
10
17
|
}
|
|
11
18
|
|
|
12
19
|
// validate cli options
|
|
@@ -20,52 +27,86 @@ export function validateCliDefinition(cliDefinition: Cli) {
|
|
|
20
27
|
|
|
21
28
|
// no empty subcommands array
|
|
22
29
|
if (subcommands.length === 0) {
|
|
23
|
-
throw new
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
throw new CliError({
|
|
31
|
+
cause: ErrorCause.Definition,
|
|
32
|
+
code: DefinitionErrorCode.EmptyDefinitionGroup,
|
|
33
|
+
context: { commandKind: "command", commandName: cliDefinition.cliName, kind: "subcommands" },
|
|
34
|
+
});
|
|
26
35
|
}
|
|
27
36
|
|
|
28
|
-
const commandsNames = subcommands.map(c => c.name);
|
|
37
|
+
const commandsNames = new Set(subcommands.map(c => c.name));
|
|
29
38
|
|
|
30
|
-
|
|
31
|
-
if (commandsNames.some(c => !c)) {
|
|
32
|
-
throw new Error(`invalid subcommand definition: subcommand's "name" property is required.`);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// no duplicate subcommand names
|
|
36
|
-
const commandsNamesDuplicates = findDuplicateStrings(commandsNames).map(c => `"${c}"`);
|
|
37
|
-
if (commandsNamesDuplicates.length > 0) {
|
|
38
|
-
throw new Error(
|
|
39
|
-
`invalid cli definition "${cliDefinition.cliName}" has duplicated subcommands: ${commandsNamesDuplicates.join(", ")}.`,
|
|
40
|
-
);
|
|
41
|
-
}
|
|
39
|
+
const visitedSubcommandNames = new Set<string>();
|
|
42
40
|
|
|
43
41
|
for (const subcommand of subcommands) {
|
|
42
|
+
if (!subcommand.name) {
|
|
43
|
+
throw new CliError({
|
|
44
|
+
cause: ErrorCause.Definition,
|
|
45
|
+
code: DefinitionErrorCode.MissingDefinitionName,
|
|
46
|
+
context: { commandKind: "subcommand" },
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// no duplicate subcommand names
|
|
51
|
+
if (visitedSubcommandNames.has(subcommand.name)) {
|
|
52
|
+
throw new CliError({
|
|
53
|
+
cause: ErrorCause.Definition,
|
|
54
|
+
code: DefinitionErrorCode.DuplicateDefinitionName,
|
|
55
|
+
context: {
|
|
56
|
+
commandKind: "command",
|
|
57
|
+
commandName: cliDefinition.cliName,
|
|
58
|
+
kind: "subcommand",
|
|
59
|
+
name: subcommand.name,
|
|
60
|
+
foundInKind: "subcommand",
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
visitedSubcommandNames.add(subcommand.name);
|
|
65
|
+
|
|
44
66
|
// command aliases check
|
|
45
67
|
if (subcommand.aliases) {
|
|
46
|
-
// no duplicated aliases
|
|
47
|
-
const aliasesDuplicates = findDuplicateStrings(subcommand.aliases).map(c => `"${c}"`);
|
|
48
|
-
if (aliasesDuplicates.length > 0) {
|
|
49
|
-
throw new Error(`subcommand "${subcommand.name}" has duplicated aliases: ${aliasesDuplicates.join(", ")}.`);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
68
|
for (const alias of subcommand.aliases) {
|
|
53
69
|
// no empty alias
|
|
54
70
|
if (alias === "") {
|
|
55
|
-
throw new
|
|
71
|
+
throw new CliError({
|
|
72
|
+
cause: ErrorCause.Definition,
|
|
73
|
+
code: DefinitionErrorCode.EmptyStringAliasName,
|
|
74
|
+
context: { commandKind: "subcommand", commandName: subcommand.name },
|
|
75
|
+
});
|
|
56
76
|
}
|
|
57
77
|
|
|
58
78
|
// no conflict with subcommand name
|
|
59
|
-
if (commandsNames.
|
|
60
|
-
throw new
|
|
79
|
+
if (commandsNames.has(alias)) {
|
|
80
|
+
throw new CliError({
|
|
81
|
+
cause: ErrorCause.Definition,
|
|
82
|
+
code: DefinitionErrorCode.DuplicateDefinitionName,
|
|
83
|
+
context: {
|
|
84
|
+
commandKind: "command",
|
|
85
|
+
commandName: cliDefinition.cliName,
|
|
86
|
+
kind: "subcommand",
|
|
87
|
+
name: subcommand.name,
|
|
88
|
+
foundInKind: "subcommand",
|
|
89
|
+
duplicatedAlias: alias,
|
|
90
|
+
},
|
|
91
|
+
});
|
|
61
92
|
}
|
|
62
93
|
|
|
63
94
|
// no conflict with another alias
|
|
64
95
|
const aliasConflicts = subcommands.filter(c => c.name !== subcommand.name && c.aliases?.includes(alias));
|
|
65
96
|
if (aliasConflicts.length > 0) {
|
|
66
|
-
throw new
|
|
67
|
-
|
|
68
|
-
|
|
97
|
+
throw new CliError({
|
|
98
|
+
cause: ErrorCause.Definition,
|
|
99
|
+
code: DefinitionErrorCode.DuplicateDefinitionName,
|
|
100
|
+
context: {
|
|
101
|
+
commandKind: "command",
|
|
102
|
+
commandName: cliDefinition.cliName,
|
|
103
|
+
kind: "subcommand",
|
|
104
|
+
name: subcommand.name,
|
|
105
|
+
foundInKind: "subcommand",
|
|
106
|
+
duplicatedAlias: alias,
|
|
107
|
+
foundInName: aliasConflicts[0].name,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
69
110
|
}
|
|
70
111
|
}
|
|
71
112
|
}
|
|
@@ -82,74 +123,124 @@ function validateOptions(commandDefinition: Cli | Subcommand) {
|
|
|
82
123
|
if (!commandDefinition.options) return; // ok
|
|
83
124
|
|
|
84
125
|
const isCli = "cliName" in commandDefinition;
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
const createError = (message: string) => {
|
|
88
|
-
return new Error(`invalid ${isCli ? "cli" : "subcommand"} definition "${name}": ${message}`);
|
|
89
|
-
};
|
|
126
|
+
const commandName = isCli ? commandDefinition.cliName : commandDefinition.name;
|
|
127
|
+
const commandKind = isCli ? "command" : "subcommand";
|
|
90
128
|
|
|
91
129
|
const optionsDefinitionEntries = Object.entries(commandDefinition.options);
|
|
92
130
|
|
|
93
131
|
// no empty options
|
|
94
132
|
if (optionsDefinitionEntries.length === 0) {
|
|
95
|
-
throw
|
|
133
|
+
throw new CliError({
|
|
134
|
+
cause: ErrorCause.Definition,
|
|
135
|
+
code: DefinitionErrorCode.EmptyDefinitionGroup,
|
|
136
|
+
context: { commandKind, commandName, kind: "option" },
|
|
137
|
+
});
|
|
96
138
|
}
|
|
97
139
|
|
|
98
140
|
for (const [name, option] of optionsDefinitionEntries) {
|
|
99
141
|
// required type
|
|
100
142
|
if (!option.schema) {
|
|
101
|
-
throw
|
|
143
|
+
throw new CliError({
|
|
144
|
+
cause: ErrorCause.Definition,
|
|
145
|
+
code: DefinitionErrorCode.MissingSchema,
|
|
146
|
+
context: { commandKind, commandName, kind: "option", name },
|
|
147
|
+
});
|
|
102
148
|
}
|
|
103
149
|
|
|
104
150
|
// should not happen
|
|
105
151
|
if (!option._preparedType) {
|
|
106
|
-
throw
|
|
152
|
+
throw new CliError({
|
|
153
|
+
cause: ErrorCause.Internal,
|
|
154
|
+
code: InternalErrorCode.MissingPreparedTypes,
|
|
155
|
+
context: { commandKind, commandName, kind: "option", name },
|
|
156
|
+
});
|
|
107
157
|
}
|
|
108
158
|
|
|
109
159
|
// no negated option name for boolean options
|
|
110
160
|
if (isNegatedOptionName(name)) {
|
|
111
|
-
throw
|
|
161
|
+
throw new CliError({
|
|
162
|
+
cause: ErrorCause.Definition,
|
|
163
|
+
code: DefinitionErrorCode.InvalidDefinitionOptionName,
|
|
164
|
+
context: { commandKind, commandName, optionName: name },
|
|
165
|
+
});
|
|
112
166
|
}
|
|
113
167
|
|
|
114
168
|
// no conflict with argument name
|
|
115
169
|
if (commandDefinition.arguments && name in commandDefinition.arguments) {
|
|
116
|
-
throw
|
|
170
|
+
throw new CliError({
|
|
171
|
+
cause: ErrorCause.Definition,
|
|
172
|
+
code: DefinitionErrorCode.DuplicateDefinitionName,
|
|
173
|
+
context: { commandKind, commandName, kind: "option", name, foundInKind: "argument" },
|
|
174
|
+
});
|
|
117
175
|
}
|
|
118
176
|
|
|
119
177
|
if (option.aliases) {
|
|
120
|
-
|
|
121
|
-
const aliasesDuplicates = findDuplicateStrings(option.aliases);
|
|
122
|
-
if (aliasesDuplicates.length > 0) {
|
|
123
|
-
throw createError(`the option "${name}" has duplicated aliases: ${aliasesDuplicates.join(", ")}.`);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
for (const alias of option.aliases) {
|
|
178
|
+
for (const aliasName of option.aliases) {
|
|
127
179
|
// no empty string aliases
|
|
128
|
-
if (
|
|
129
|
-
throw
|
|
180
|
+
if (aliasName === "") {
|
|
181
|
+
throw new CliError({
|
|
182
|
+
cause: ErrorCause.Definition,
|
|
183
|
+
code: DefinitionErrorCode.EmptyStringAliasName,
|
|
184
|
+
context: { commandKind, commandName, optionName: name },
|
|
185
|
+
});
|
|
130
186
|
}
|
|
131
187
|
|
|
132
188
|
// no negated alias name for boolean options
|
|
133
|
-
if (isNegatedOptionName(
|
|
134
|
-
throw
|
|
189
|
+
if (isNegatedOptionName(aliasName)) {
|
|
190
|
+
throw new CliError({
|
|
191
|
+
cause: ErrorCause.Definition,
|
|
192
|
+
code: DefinitionErrorCode.InvalidDefinitionOptionName,
|
|
193
|
+
context: { commandKind, commandName, optionName: name, negatedAliasName: aliasName },
|
|
194
|
+
});
|
|
135
195
|
}
|
|
136
196
|
|
|
137
197
|
// no alias name should conflict with any option name
|
|
138
|
-
if (commandDefinition.options[
|
|
139
|
-
throw
|
|
198
|
+
if (commandDefinition.options[aliasName]) {
|
|
199
|
+
throw new CliError({
|
|
200
|
+
cause: ErrorCause.Definition,
|
|
201
|
+
code: DefinitionErrorCode.DuplicateDefinitionName,
|
|
202
|
+
context: {
|
|
203
|
+
commandKind,
|
|
204
|
+
commandName,
|
|
205
|
+
kind: "option",
|
|
206
|
+
name,
|
|
207
|
+
duplicatedAlias: aliasName,
|
|
208
|
+
foundInKind: "option",
|
|
209
|
+
},
|
|
210
|
+
});
|
|
140
211
|
}
|
|
141
212
|
|
|
142
213
|
// no alias name should conflict with any argument name
|
|
143
|
-
if (commandDefinition.arguments &&
|
|
144
|
-
throw
|
|
214
|
+
if (commandDefinition.arguments && aliasName in commandDefinition.arguments) {
|
|
215
|
+
throw new CliError({
|
|
216
|
+
cause: ErrorCause.Definition,
|
|
217
|
+
code: DefinitionErrorCode.DuplicateDefinitionName,
|
|
218
|
+
context: {
|
|
219
|
+
commandKind,
|
|
220
|
+
commandName,
|
|
221
|
+
kind: "option",
|
|
222
|
+
name,
|
|
223
|
+
duplicatedAlias: aliasName,
|
|
224
|
+
foundInKind: "argument",
|
|
225
|
+
},
|
|
226
|
+
});
|
|
145
227
|
}
|
|
146
228
|
|
|
147
229
|
// no alias name should conflict with any other alias name
|
|
148
|
-
const findConflict = optionsDefinitionEntries.find(([n, d]) => n !== name && d.aliases?.includes(
|
|
230
|
+
const findConflict = optionsDefinitionEntries.find(([n, d]) => n !== name && d.aliases?.includes(aliasName));
|
|
149
231
|
if (findConflict) {
|
|
150
|
-
throw
|
|
151
|
-
|
|
152
|
-
|
|
232
|
+
throw new CliError({
|
|
233
|
+
cause: ErrorCause.Definition,
|
|
234
|
+
code: DefinitionErrorCode.DuplicateDefinitionName,
|
|
235
|
+
context: {
|
|
236
|
+
commandKind,
|
|
237
|
+
commandName,
|
|
238
|
+
kind: "option",
|
|
239
|
+
name: aliasName,
|
|
240
|
+
foundInKind: "option",
|
|
241
|
+
foundInName: findConflict[0],
|
|
242
|
+
},
|
|
243
|
+
});
|
|
153
244
|
}
|
|
154
245
|
}
|
|
155
246
|
}
|
|
@@ -157,20 +248,22 @@ function validateOptions(commandDefinition: Cli | Subcommand) {
|
|
|
157
248
|
if (option.requires) {
|
|
158
249
|
// no self require
|
|
159
250
|
if (option.requires.includes(name)) {
|
|
160
|
-
throw
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (duplicateRequires.length > 0) {
|
|
166
|
-
throw createError(`the option "${name}" has duplicate requires: ${duplicateRequires.join(", ")}.`);
|
|
251
|
+
throw new CliError({
|
|
252
|
+
cause: ErrorCause.Definition,
|
|
253
|
+
code: DefinitionErrorCode.SelfRequire,
|
|
254
|
+
context: { commandKind, commandName, kind: "option", name: name },
|
|
255
|
+
});
|
|
167
256
|
}
|
|
168
257
|
|
|
169
258
|
// no unknown required name
|
|
170
|
-
for (const
|
|
171
|
-
const exits =
|
|
259
|
+
for (const requiredName of option.requires) {
|
|
260
|
+
const exits = requiredName in commandDefinition.options || requiredName in (commandDefinition.arguments ?? []);
|
|
172
261
|
if (!exits) {
|
|
173
|
-
throw
|
|
262
|
+
throw new CliError({
|
|
263
|
+
cause: ErrorCause.Definition,
|
|
264
|
+
code: DefinitionErrorCode.UnknownRequireName,
|
|
265
|
+
context: { commandKind, commandName, kind: "option", name: name, requiredName },
|
|
266
|
+
});
|
|
174
267
|
}
|
|
175
268
|
}
|
|
176
269
|
}
|
|
@@ -178,20 +271,22 @@ function validateOptions(commandDefinition: Cli | Subcommand) {
|
|
|
178
271
|
if (option.conflictWith) {
|
|
179
272
|
// no self conflict
|
|
180
273
|
if (option.conflictWith.includes(name)) {
|
|
181
|
-
throw
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
if (duplicateRequires.length > 0) {
|
|
187
|
-
throw createError(`the option "${name}" has duplicate conflicts: ${duplicateRequires.join(", ")}.`);
|
|
274
|
+
throw new CliError({
|
|
275
|
+
cause: ErrorCause.Definition,
|
|
276
|
+
code: DefinitionErrorCode.SelfConflict,
|
|
277
|
+
context: { commandKind, commandName, kind: "option", name: name },
|
|
278
|
+
});
|
|
188
279
|
}
|
|
189
280
|
|
|
190
281
|
// no unknown conflict name
|
|
191
|
-
for (const
|
|
192
|
-
const exits =
|
|
282
|
+
for (const requiredName of option.conflictWith) {
|
|
283
|
+
const exits = requiredName in commandDefinition.options || requiredName in (commandDefinition.arguments ?? []);
|
|
193
284
|
if (!exits) {
|
|
194
|
-
throw
|
|
285
|
+
throw new CliError({
|
|
286
|
+
cause: ErrorCause.Definition,
|
|
287
|
+
code: DefinitionErrorCode.UnknownConflictName,
|
|
288
|
+
context: { commandKind, commandName, kind: "option", name: name, requiredName },
|
|
289
|
+
});
|
|
195
290
|
}
|
|
196
291
|
}
|
|
197
292
|
}
|
|
@@ -202,13 +297,14 @@ function validateOptions(commandDefinition: Cli | Subcommand) {
|
|
|
202
297
|
const conflictsSet = new Set(option.conflictWith);
|
|
203
298
|
|
|
204
299
|
const intersection = requiresSet.intersection(conflictsSet);
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
if (
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
300
|
+
const intersectedNames = Array.from(intersection).map(name => `"${name}"`);
|
|
301
|
+
|
|
302
|
+
if (intersectedNames.length > 0) {
|
|
303
|
+
throw new CliError({
|
|
304
|
+
cause: ErrorCause.Definition,
|
|
305
|
+
code: DefinitionErrorCode.DefinitionRequiresConflictOverlap,
|
|
306
|
+
context: { commandKind, commandName, kind: "option", name: name, intersectedNames },
|
|
307
|
+
});
|
|
212
308
|
}
|
|
213
309
|
}
|
|
214
310
|
}
|
|
@@ -218,109 +314,128 @@ function validateArguments(commandDefinition: Cli | Subcommand) {
|
|
|
218
314
|
if (!commandDefinition.arguments) return; // ok
|
|
219
315
|
|
|
220
316
|
const isCli = "cliName" in commandDefinition;
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
if (
|
|
228
|
-
|
|
317
|
+
const commandName = isCli ? commandDefinition.cliName : commandDefinition.name;
|
|
318
|
+
const commandKind = isCli ? "command" : "subcommand";
|
|
319
|
+
|
|
320
|
+
const argumentsDefinitionEntries = Object.entries(commandDefinition.arguments);
|
|
321
|
+
|
|
322
|
+
// no empty arguments record
|
|
323
|
+
if (argumentsDefinitionEntries.length === 0) {
|
|
324
|
+
throw new CliError({
|
|
325
|
+
cause: ErrorCause.Definition,
|
|
326
|
+
code: DefinitionErrorCode.EmptyDefinitionGroup,
|
|
327
|
+
context: { commandKind, commandName, kind: "argument" },
|
|
328
|
+
});
|
|
329
|
+
}
|
|
229
330
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
331
|
+
for (const [index, [name, argument]] of argumentsDefinitionEntries.entries()) {
|
|
332
|
+
// no number key name
|
|
333
|
+
if (/^\d+$/.test(name)) {
|
|
334
|
+
throw new CliError({
|
|
335
|
+
cause: ErrorCause.Definition,
|
|
336
|
+
code: DefinitionErrorCode.InvalidDefinitionArgumentName,
|
|
337
|
+
context: { commandKind, commandName, name },
|
|
338
|
+
});
|
|
233
339
|
}
|
|
234
340
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
throw createError(`internal error: missing prepared type for argument "${name}".`);
|
|
244
|
-
}
|
|
341
|
+
// should not happen
|
|
342
|
+
if (!argument._preparedType) {
|
|
343
|
+
throw new CliError({
|
|
344
|
+
cause: ErrorCause.Internal,
|
|
345
|
+
code: InternalErrorCode.MissingPreparedTypes,
|
|
346
|
+
context: { commandKind, commandName, kind: "argument", name },
|
|
347
|
+
});
|
|
348
|
+
}
|
|
245
349
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
350
|
+
// no missing schema
|
|
351
|
+
if (!argument.schema) {
|
|
352
|
+
throw new CliError({
|
|
353
|
+
cause: ErrorCause.Definition,
|
|
354
|
+
code: DefinitionErrorCode.MissingSchema,
|
|
355
|
+
context: { commandKind, commandName, kind: "argument", name },
|
|
356
|
+
});
|
|
357
|
+
}
|
|
250
358
|
|
|
251
|
-
|
|
252
|
-
if (commandDefinition.options && name in commandDefinition.options) {
|
|
253
|
-
throw createError(`the argument "${name}" name conflicts with an option name.`);
|
|
254
|
-
}
|
|
359
|
+
if (!argument._preparedType.optional) continue; // ok
|
|
255
360
|
|
|
256
|
-
|
|
361
|
+
// no optional argument when "allowPositionals" is enabled
|
|
362
|
+
if (commandDefinition.allowPositionals) {
|
|
363
|
+
throw new CliError({
|
|
364
|
+
cause: ErrorCause.Definition,
|
|
365
|
+
code: DefinitionErrorCode.InvalidOptionalArgumentDefinition,
|
|
366
|
+
context: { commandKind, commandName, name, allowPositionals: true },
|
|
367
|
+
});
|
|
368
|
+
}
|
|
257
369
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
370
|
+
// only last argument can be optional
|
|
371
|
+
if (index !== argumentsDefinitionEntries.length - 1) {
|
|
372
|
+
throw new CliError({
|
|
373
|
+
cause: ErrorCause.Definition,
|
|
374
|
+
code: DefinitionErrorCode.InvalidOptionalArgumentDefinition,
|
|
375
|
+
context: { commandKind, commandName, name, allowPositionals: false },
|
|
376
|
+
});
|
|
377
|
+
}
|
|
262
378
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
379
|
+
if (argument.requires) {
|
|
380
|
+
// no self require
|
|
381
|
+
if (argument.requires.includes(name)) {
|
|
382
|
+
throw new CliError({
|
|
383
|
+
cause: ErrorCause.Definition,
|
|
384
|
+
code: DefinitionErrorCode.SelfRequire,
|
|
385
|
+
context: { commandKind, commandName, kind: "argument", name },
|
|
386
|
+
});
|
|
266
387
|
}
|
|
267
388
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
throw createError(`the argument "${name}" has duplicate requires: ${duplicateRequires.join(", ")}.`);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// no unknown require
|
|
281
|
-
for (const required of argument.requires) {
|
|
282
|
-
const exits = required in (commandDefinition.options ?? {}) || required in commandDefinition.arguments;
|
|
283
|
-
if (!exits) {
|
|
284
|
-
throw createError(`the argument "${name}" requires "${required}", but it does not exist.`);
|
|
285
|
-
}
|
|
389
|
+
// no unknown require
|
|
390
|
+
for (const requiredName of argument.requires) {
|
|
391
|
+
const exits = requiredName in (commandDefinition.options ?? {}) || requiredName in commandDefinition.arguments;
|
|
392
|
+
if (!exits) {
|
|
393
|
+
throw new CliError({
|
|
394
|
+
cause: ErrorCause.Definition,
|
|
395
|
+
code: DefinitionErrorCode.UnknownRequireName,
|
|
396
|
+
context: { commandKind, commandName, kind: "argument", name, requiredName },
|
|
397
|
+
});
|
|
286
398
|
}
|
|
287
399
|
}
|
|
400
|
+
}
|
|
288
401
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
throw createError(`the argument "${name}" has duplicate conflicts: ${duplicateRequires.join(", ")}.`);
|
|
299
|
-
}
|
|
402
|
+
if (argument.conflictWith) {
|
|
403
|
+
// no self conflict
|
|
404
|
+
if (argument.conflictWith.includes(name)) {
|
|
405
|
+
throw new CliError({
|
|
406
|
+
cause: ErrorCause.Definition,
|
|
407
|
+
code: DefinitionErrorCode.SelfConflict,
|
|
408
|
+
context: { commandKind, commandName, kind: "argument", name },
|
|
409
|
+
});
|
|
410
|
+
}
|
|
300
411
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
412
|
+
// no unknown conflict
|
|
413
|
+
for (const requiredName of argument.conflictWith) {
|
|
414
|
+
const exits = requiredName in (commandDefinition.options ?? {}) || requiredName in commandDefinition.arguments;
|
|
415
|
+
if (!exits) {
|
|
416
|
+
throw new CliError({
|
|
417
|
+
cause: ErrorCause.Definition,
|
|
418
|
+
code: DefinitionErrorCode.UnknownConflictName,
|
|
419
|
+
context: { commandKind, commandName, kind: "argument", name, requiredName },
|
|
420
|
+
});
|
|
307
421
|
}
|
|
308
422
|
}
|
|
423
|
+
}
|
|
309
424
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
const intersection = requiresSet.intersection(conflictsSet);
|
|
316
|
-
const intersectionArray = Array.from(intersection).map(name => `"${name}"`);
|
|
425
|
+
// no intersection between requires and conflicts
|
|
426
|
+
if (argument.requires && argument.conflictWith) {
|
|
427
|
+
const requiresSet = new Set(argument.requires);
|
|
428
|
+
const conflictsSet = new Set(argument.conflictWith);
|
|
317
429
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
430
|
+
const intersection = requiresSet.intersection(conflictsSet);
|
|
431
|
+
const intersectedNames = Array.from(intersection).map(name => `"${name}"`);
|
|
432
|
+
|
|
433
|
+
if (intersectedNames.length > 0) {
|
|
434
|
+
throw new CliError({
|
|
435
|
+
cause: ErrorCause.Definition,
|
|
436
|
+
code: DefinitionErrorCode.DefinitionRequiresConflictOverlap,
|
|
437
|
+
context: { commandKind, commandName, kind: "argument", name, intersectedNames },
|
|
438
|
+
});
|
|
324
439
|
}
|
|
325
440
|
}
|
|
326
441
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { indent, indentLines, insertAtEndOfFirstLine, ln, toKebabCase } from "../utilities.ts";
|
|
1
|
+
import { indent, indentLines, insertAtEndOfFirstLine, ln, toKebabCase } from "../utilities/utilities.ts";
|
|
2
2
|
import { terminalMarkdown } from "./terminal-markdown.ts";
|
|
3
3
|
|
|
4
4
|
import type { ArgumentMetadata } from "../types/metadata-types.ts";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { indent, indentLines, insertAtEndOfFirstLine, ln } from "../utilities.ts";
|
|
1
|
+
import { indent, indentLines, insertAtEndOfFirstLine, ln } from "../utilities/utilities.ts";
|
|
2
2
|
import { terminalMarkdown } from "./terminal-markdown.ts";
|
|
3
3
|
|
|
4
4
|
import type { OptionMetadata } from "../types/metadata-types.ts";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { indent, indentLines, ln, subcommandPlaceholder } from "../utilities.ts";
|
|
1
|
+
import { indent, indentLines, ln, subcommandPlaceholder } from "../utilities/utilities.ts";
|
|
2
2
|
import { terminalMarkdown } from "./terminal-markdown.ts";
|
|
3
3
|
|
|
4
4
|
import type { SubcommandMetadata } from "../types/metadata-types.ts";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getCliMetadata } from "../metadata/cli-metadata.ts";
|
|
2
|
-
import { indent, indentLines, ln, subcommandPlaceholder } from "../utilities.ts";
|
|
2
|
+
import { indent, indentLines, ln, subcommandPlaceholder } from "../utilities/utilities.ts";
|
|
3
3
|
import { formatHelpMessageArguments } from "./format-arguments.ts";
|
|
4
4
|
import { formatHelpMessageOptions } from "./format-options.ts";
|
|
5
5
|
import { formatHelpMessageCommands } from "./format-subcommands.ts";
|
|
@@ -7,7 +7,7 @@ const markdownStyle: Record<string, ColorFunctionType> = {
|
|
|
7
7
|
bold: c.bold,
|
|
8
8
|
italic: c.italic,
|
|
9
9
|
boldItalic: c.bold.italic,
|
|
10
|
-
code: (...string) => c.bgHex("#
|
|
10
|
+
code: (...string) => c.bgHex("#282828").whiteBright(` ${string.join(" ")} `),
|
|
11
11
|
strikethrough: c.strikethrough,
|
|
12
12
|
link: c.underline,
|
|
13
13
|
listBullet: c.whiteBright,
|
|
@@ -125,9 +125,6 @@ const terminalRenderer: RendererObject<string, string> = {
|
|
|
125
125
|
},
|
|
126
126
|
};
|
|
127
127
|
|
|
128
|
-
const terminalMarked = new Marked();
|
|
129
|
-
terminalMarked.use({ renderer: terminalRenderer });
|
|
130
|
-
|
|
131
128
|
export function terminalMarkdown(
|
|
132
129
|
text: string,
|
|
133
130
|
renderer: "terminal" | "html" = "terminal",
|
|
@@ -138,6 +135,8 @@ export function terminalMarkdown(
|
|
|
138
135
|
}
|
|
139
136
|
|
|
140
137
|
if (renderer === "terminal") {
|
|
138
|
+
const terminalMarked = new Marked();
|
|
139
|
+
terminalMarked.use({ renderer: terminalRenderer });
|
|
141
140
|
return ansiTextColor(terminalMarked.parse(text) as string);
|
|
142
141
|
}
|
|
143
142
|
|