zod-args-parser 2.0.0-beta.0 → 2.0.0-beta.2
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 +230 -289
- 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 +1 -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/{typescript → types}/types/io-types.d.ts +1 -1
- 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 +7 -7
- 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/io-types.ts +1 -1
- 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.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,2 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/parse/validation/validators/explicitly-passed.ts
|
|
2
|
+
function isArgumentExplicitlyPassed(name, context) {
|
|
3
|
+
if (!context.arguments) return false;
|
|
4
|
+
return name in context.arguments && context.arguments[name].source !== "default";
|
|
5
|
+
}
|
|
6
|
+
function isOptionExplicitlyPassed(name, context) {
|
|
7
|
+
if (!context.options) return false;
|
|
8
|
+
return name in context.options && context.options[name].source !== "default";
|
|
9
|
+
}
|
|
10
|
+
function isOptionOrArgumentExplicitlyPassed(name, context) {
|
|
11
|
+
return isOptionExplicitlyPassed(name, context) || isArgumentExplicitlyPassed(name, context);
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
isArgumentExplicitlyPassed,
|
|
15
|
+
isOptionExplicitlyPassed,
|
|
16
|
+
isOptionOrArgumentExplicitlyPassed
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=explicitly-passed.mjs.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/parse/validation/validators/explicitly-passed.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ContextWide } from \"../../../types/context-types.ts\";\n\nexport function isArgumentExplicitlyPassed(name: string, context: ContextWide) {\n if (!context.arguments) return false;\n return name in context.arguments && context.arguments[name].source !== \"default\";\n}\n\nexport function isOptionExplicitlyPassed(name: string, context: ContextWide) {\n if (!context.options) return false;\n return name in context.options && context.options[name].source !== \"default\";\n}\n\nexport function isOptionOrArgumentExplicitlyPassed(name: string, context: ContextWide) {\n return isOptionExplicitlyPassed(name, context) || isArgumentExplicitlyPassed(name, context);\n}\n"],
|
|
5
|
+
"mappings": ";AAEO,SAAS,2BAA2B,MAAc,SAAsB;AAC7E,MAAI,CAAC,QAAQ,UAAW,QAAO;AAC/B,SAAO,QAAQ,QAAQ,aAAa,QAAQ,UAAU,IAAI,EAAE,WAAW;AACzE;AAEO,SAAS,yBAAyB,MAAc,SAAsB;AAC3E,MAAI,CAAC,QAAQ,QAAS,QAAO;AAC7B,SAAO,QAAQ,QAAQ,WAAW,QAAQ,QAAQ,IAAI,EAAE,WAAW;AACrE;AAEO,SAAS,mCAAmC,MAAc,SAAsB;AACrF,SAAO,yBAAyB,MAAM,OAAO,KAAK,2BAA2B,MAAM,OAAO;AAC5F;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,2 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/parse/validation/validators/options.ts
|
|
2
|
+
import { CliError } from "../../../cli-error/cli-error.mjs";
|
|
3
|
+
import { ErrorCause } from "../../../cli-error/error-cause.mjs";
|
|
4
|
+
import { InternalErrorCode } from "../../../cli-error/error-code/internal-error-code.mjs";
|
|
5
|
+
import { ValidationErrorCode } from "../../../cli-error/error-code/validation-error-code.mjs";
|
|
6
|
+
import { validateSync } from "../../../utilities/schema-utilities.mjs";
|
|
7
|
+
import { validateConflictWith } from "./conflict.mjs";
|
|
8
|
+
import { validateExclusive } from "./exclusive.mjs";
|
|
9
|
+
import { validateRequires } from "./requires.mjs";
|
|
10
|
+
function validateOptions({ commandDefinition, context, output }) {
|
|
11
|
+
if (!context.options) return;
|
|
12
|
+
output.options ??= {};
|
|
13
|
+
const commandKind = "cliName" in commandDefinition ? "command" : "subcommand";
|
|
14
|
+
const commandName = "cliName" in commandDefinition ? commandDefinition.cliName : commandDefinition.name;
|
|
15
|
+
const optionsDefinition = commandDefinition.options;
|
|
16
|
+
if (!optionsDefinition) {
|
|
17
|
+
throw new CliError({
|
|
18
|
+
cause: ErrorCause.Validation,
|
|
19
|
+
code: ValidationErrorCode.NoOptionsToValidate,
|
|
20
|
+
context: { commandKind, commandName }
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
for (const [optionName, option] of Object.entries(optionsDefinition)) {
|
|
24
|
+
validateRequires({ name: optionName, commandDefinition, optionOrArgument: option, context, kind: "option" });
|
|
25
|
+
validateExclusive({ name: optionName, optionOrArgument: option, context, kind: "option" });
|
|
26
|
+
validateConflictWith({ name: optionName, optionOrArgument: option, context, kind: "option" });
|
|
27
|
+
}
|
|
28
|
+
const optionContextEntries = Object.entries(context.options);
|
|
29
|
+
for (const [optionName, { passedValue, stringValue, source, schema }] of optionContextEntries) {
|
|
30
|
+
const option = optionsDefinition[optionName];
|
|
31
|
+
if (!option) {
|
|
32
|
+
throw new CliError({
|
|
33
|
+
cause: ErrorCause.Validation,
|
|
34
|
+
code: ValidationErrorCode.UnknownOptionValidation,
|
|
35
|
+
context: { commandKind, commandName, optionName }
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (!option._preparedType) {
|
|
39
|
+
throw new CliError({
|
|
40
|
+
cause: ErrorCause.Internal,
|
|
41
|
+
code: InternalErrorCode.MissingPreparedTypes,
|
|
42
|
+
context: { commandKind, commandName, kind: "option", name: optionName }
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const isProgrammatic = source === "programmatic";
|
|
46
|
+
const safeParseResult = isProgrammatic ? validateSync(schema, passedValue) : option._preparedType.validate(stringValue);
|
|
47
|
+
if (safeParseResult.issues) {
|
|
48
|
+
throw new CliError({
|
|
49
|
+
cause: ErrorCause.Validation,
|
|
50
|
+
code: ValidationErrorCode.SchemaValidationFailed,
|
|
51
|
+
context: {
|
|
52
|
+
commandKind,
|
|
53
|
+
commandName,
|
|
54
|
+
kind: "option",
|
|
55
|
+
name: optionName,
|
|
56
|
+
inputValue: isProgrammatic ? passedValue : stringValue,
|
|
57
|
+
issues: safeParseResult.issues
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
output.options[optionName] = safeParseResult.value;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export {
|
|
65
|
+
validateOptions
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=options.mjs.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/parse/validation/validators/options.ts"],
|
|
4
|
+
"sourcesContent": ["import { CliError } from \"../../../cli-error/cli-error.ts\";\nimport { ErrorCause } from \"../../../cli-error/error-cause.ts\";\nimport { InternalErrorCode } from \"../../../cli-error/error-code/internal-error-code.ts\";\nimport { ValidationErrorCode } from \"../../../cli-error/error-code/validation-error-code.ts\";\nimport { validateSync } from \"../../../utilities/schema-utilities.ts\";\nimport { validateConflictWith } from \"./conflict.ts\";\nimport { validateExclusive } from \"./exclusive.ts\";\nimport { validateRequires } from \"./requires.ts\";\n\nimport type { ContextWide } from \"../../../types/context-types.ts\";\nimport type { Cli, Subcommand } from \"../../../types/definitions-types.ts\";\nimport type { OutputTypeWide } from \"../../../types/io-types.ts\";\n\ninterface ValidateOptions {\n commandDefinition: Subcommand | Cli;\n context: ContextWide;\n output: OutputTypeWide;\n}\n\n/** @throws {CliError} */\nexport function validateOptions({ commandDefinition, context, output }: ValidateOptions) {\n if (!context.options) return;\n\n output.options ??= {};\n\n const commandKind = \"cliName\" in commandDefinition ? \"command\" : \"subcommand\";\n const commandName = \"cliName\" in commandDefinition ? commandDefinition.cliName : commandDefinition.name;\n\n const optionsDefinition = commandDefinition.options;\n if (!optionsDefinition) {\n throw new CliError({\n cause: ErrorCause.Validation,\n code: ValidationErrorCode.NoOptionsToValidate,\n context: { commandKind, commandName },\n });\n }\n\n for (const [optionName, option] of Object.entries(optionsDefinition)) {\n validateRequires({ name: optionName, commandDefinition, optionOrArgument: option, context, kind: \"option\" });\n validateExclusive({ name: optionName, optionOrArgument: option, context, kind: \"option\" });\n validateConflictWith({ name: optionName, optionOrArgument: option, context, kind: \"option\" });\n }\n\n const optionContextEntries = Object.entries(context.options);\n\n for (const [optionName, { passedValue, stringValue, source, schema }] of optionContextEntries) {\n const option = optionsDefinition[optionName];\n if (!option) {\n throw new CliError({\n cause: ErrorCause.Validation,\n code: ValidationErrorCode.UnknownOptionValidation,\n context: { commandKind, commandName, optionName },\n });\n }\n\n if (!option._preparedType) {\n throw new CliError({\n cause: ErrorCause.Internal,\n code: InternalErrorCode.MissingPreparedTypes,\n context: { commandKind, commandName, kind: \"option\", name: optionName },\n });\n }\n\n const isProgrammatic = source === \"programmatic\";\n\n const safeParseResult = isProgrammatic\n ? validateSync(schema, passedValue)\n : option._preparedType.validate(stringValue);\n\n if (safeParseResult.issues) {\n throw new CliError({\n cause: ErrorCause.Validation,\n code: ValidationErrorCode.SchemaValidationFailed,\n context: {\n commandKind,\n commandName,\n kind: \"option\",\n name: optionName,\n inputValue: isProgrammatic ? passedValue : stringValue,\n issues: safeParseResult.issues,\n },\n });\n }\n\n output.options[optionName] = safeParseResult.value;\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,yBAAyB;AAClC,SAAS,2BAA2B;AACpC,SAAS,oBAAoB;AAC7B,SAAS,4BAA4B;AACrC,SAAS,yBAAyB;AAClC,SAAS,wBAAwB;AAa1B,SAAS,gBAAgB,EAAE,mBAAmB,SAAS,OAAO,GAAoB;AACvF,MAAI,CAAC,QAAQ,QAAS;AAEtB,SAAO,YAAY,CAAC;AAEpB,QAAM,cAAc,aAAa,oBAAoB,YAAY;AACjE,QAAM,cAAc,aAAa,oBAAoB,kBAAkB,UAAU,kBAAkB;AAEnG,QAAM,oBAAoB,kBAAkB;AAC5C,MAAI,CAAC,mBAAmB;AACtB,UAAM,IAAI,SAAS;AAAA,MACjB,OAAO,WAAW;AAAA,MAClB,MAAM,oBAAoB;AAAA,MAC1B,SAAS,EAAE,aAAa,YAAY;AAAA,IACtC,CAAC;AAAA,EACH;AAEA,aAAW,CAAC,YAAY,MAAM,KAAK,OAAO,QAAQ,iBAAiB,GAAG;AACpE,qBAAiB,EAAE,MAAM,YAAY,mBAAmB,kBAAkB,QAAQ,SAAS,MAAM,SAAS,CAAC;AAC3G,sBAAkB,EAAE,MAAM,YAAY,kBAAkB,QAAQ,SAAS,MAAM,SAAS,CAAC;AACzF,yBAAqB,EAAE,MAAM,YAAY,kBAAkB,QAAQ,SAAS,MAAM,SAAS,CAAC;AAAA,EAC9F;AAEA,QAAM,uBAAuB,OAAO,QAAQ,QAAQ,OAAO;AAE3D,aAAW,CAAC,YAAY,EAAE,aAAa,aAAa,QAAQ,OAAO,CAAC,KAAK,sBAAsB;AAC7F,UAAM,SAAS,kBAAkB,UAAU;AAC3C,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,SAAS;AAAA,QACjB,OAAO,WAAW;AAAA,QAClB,MAAM,oBAAoB;AAAA,QAC1B,SAAS,EAAE,aAAa,aAAa,WAAW;AAAA,MAClD,CAAC;AAAA,IACH;AAEA,QAAI,CAAC,OAAO,eAAe;AACzB,YAAM,IAAI,SAAS;AAAA,QACjB,OAAO,WAAW;AAAA,QAClB,MAAM,kBAAkB;AAAA,QACxB,SAAS,EAAE,aAAa,aAAa,MAAM,UAAU,MAAM,WAAW;AAAA,MACxE,CAAC;AAAA,IACH;AAEA,UAAM,iBAAiB,WAAW;AAElC,UAAM,kBAAkB,iBACpB,aAAa,QAAQ,WAAW,IAChC,OAAO,cAAc,SAAS,WAAW;AAE7C,QAAI,gBAAgB,QAAQ;AAC1B,YAAM,IAAI,SAAS;AAAA,QACjB,OAAO,WAAW;AAAA,QAClB,MAAM,oBAAoB;AAAA,QAC1B,SAAS;AAAA,UACP;AAAA,UACA;AAAA,UACA,MAAM;AAAA,UACN,MAAM;AAAA,UACN,YAAY,iBAAiB,cAAc;AAAA,UAC3C,QAAQ,gBAAgB;AAAA,QAC1B;AAAA,MACF,CAAC;AAAA,IACH;AAEA,WAAO,QAAQ,UAAU,IAAI,gBAAgB;AAAA,EAC/C;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,2 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/parse/validation/validators/requires.ts
|
|
2
|
+
import { CliError } from "../../../cli-error/cli-error.mjs";
|
|
3
|
+
import { ErrorCause } from "../../../cli-error/error-cause.mjs";
|
|
4
|
+
import { ValidationErrorCode } from "../../../cli-error/error-code/validation-error-code.mjs";
|
|
5
|
+
import {
|
|
6
|
+
isArgumentExplicitlyPassed,
|
|
7
|
+
isOptionExplicitlyPassed,
|
|
8
|
+
isOptionOrArgumentExplicitlyPassed
|
|
9
|
+
} from "./explicitly-passed.mjs";
|
|
10
|
+
function validateRequires({
|
|
11
|
+
name,
|
|
12
|
+
commandDefinition,
|
|
13
|
+
optionOrArgument,
|
|
14
|
+
context,
|
|
15
|
+
kind
|
|
16
|
+
}) {
|
|
17
|
+
const requires = optionOrArgument.requires;
|
|
18
|
+
if (!requires || requires.length === 0) return;
|
|
19
|
+
if (!isOptionOrArgumentExplicitlyPassed(name, context)) return;
|
|
20
|
+
const optionsDefinition = commandDefinition.options ?? {};
|
|
21
|
+
const missingOptions = [];
|
|
22
|
+
const missingArguments = [];
|
|
23
|
+
for (const requiredName of requires) {
|
|
24
|
+
const isOption = requiredName in optionsDefinition;
|
|
25
|
+
const provided = isOption ? isOptionExplicitlyPassed(requiredName, context) : isArgumentExplicitlyPassed(requiredName, context);
|
|
26
|
+
if (provided) continue;
|
|
27
|
+
if (isOption) {
|
|
28
|
+
missingOptions.push(requiredName);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
missingArguments.push(requiredName);
|
|
32
|
+
}
|
|
33
|
+
if (missingOptions.length === 0 && missingArguments.length === 0) return;
|
|
34
|
+
throw new CliError({
|
|
35
|
+
cause: ErrorCause.Validation,
|
|
36
|
+
code: ValidationErrorCode.RequiredDependencyMissing,
|
|
37
|
+
context: { kind, name, missingArguments, missingOptions }
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
validateRequires
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=requires.mjs.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/parse/validation/validators/requires.ts"],
|
|
4
|
+
"sourcesContent": ["import { CliError } from \"../../../cli-error/cli-error.ts\";\nimport { ErrorCause } from \"../../../cli-error/error-cause.ts\";\nimport { ValidationErrorCode } from \"../../../cli-error/error-code/validation-error-code.ts\";\nimport {\n isArgumentExplicitlyPassed,\n isOptionExplicitlyPassed,\n isOptionOrArgumentExplicitlyPassed,\n} from \"./explicitly-passed.ts\";\n\nimport type { ContextWide } from \"../../../types/context-types.ts\";\nimport type { Argument, Cli, Option, Subcommand } from \"../../../types/definitions-types.ts\";\n\ninterface ValidateRequiresOptions {\n /** The option or argument name to check its `requires` */\n name: string;\n\n /** The subcommand or cli configuration */\n commandDefinition: Subcommand | Cli;\n\n /** The option or argument to check */\n optionOrArgument: Option | Argument;\n\n /** The parsed context */\n context: ContextWide;\n\n /** What we're checking */\n kind: \"option\" | \"argument\";\n}\n\n/** @throws {CliError} */\nexport function validateRequires({\n name,\n commandDefinition,\n optionOrArgument,\n context,\n kind,\n}: ValidateRequiresOptions) {\n const requires = optionOrArgument.requires;\n if (!requires || requires.length === 0) return;\n\n // Check if the options/argument is passed\n if (!isOptionOrArgumentExplicitlyPassed(name, context)) return;\n\n const optionsDefinition = commandDefinition.options ?? {};\n\n const missingOptions: string[] = [];\n const missingArguments: string[] = [];\n\n for (const requiredName of requires) {\n const isOption = requiredName in optionsDefinition;\n\n const provided = isOption\n ? isOptionExplicitlyPassed(requiredName, context)\n : isArgumentExplicitlyPassed(requiredName, context);\n\n if (provided) continue;\n\n if (isOption) {\n missingOptions.push(requiredName);\n continue;\n }\n\n missingArguments.push(requiredName);\n }\n\n if (missingOptions.length === 0 && missingArguments.length === 0) return; // OK\n\n throw new CliError({\n cause: ErrorCause.Validation,\n code: ValidationErrorCode.RequiredDependencyMissing,\n context: { kind, name, missingArguments, missingOptions },\n });\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAuBA,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA4B;AAC1B,QAAM,WAAW,iBAAiB;AAClC,MAAI,CAAC,YAAY,SAAS,WAAW,EAAG;AAGxC,MAAI,CAAC,mCAAmC,MAAM,OAAO,EAAG;AAExD,QAAM,oBAAoB,kBAAkB,WAAW,CAAC;AAExD,QAAM,iBAA2B,CAAC;AAClC,QAAM,mBAA6B,CAAC;AAEpC,aAAW,gBAAgB,UAAU;AACnC,UAAM,WAAW,gBAAgB;AAEjC,UAAM,WAAW,WACb,yBAAyB,cAAc,OAAO,IAC9C,2BAA2B,cAAc,OAAO;AAEpD,QAAI,SAAU;AAEd,QAAI,UAAU;AACZ,qBAAe,KAAK,YAAY;AAChC;AAAA,IACF;AAEA,qBAAiB,KAAK,YAAY;AAAA,EACpC;AAEA,MAAI,eAAe,WAAW,KAAK,iBAAiB,WAAW,EAAG;AAElE,QAAM,IAAI,SAAS;AAAA,IACjB,OAAO,WAAW;AAAA,IAClB,MAAM,oBAAoB;AAAA,IAC1B,SAAS,EAAE,MAAM,MAAM,kBAAkB,eAAe;AAAA,EAC1D,CAAC;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// src/utilities/parse-argv.ts
|
|
2
|
+
function parseArgv(input) {
|
|
3
|
+
const argv = [];
|
|
4
|
+
let currentQuote = void 0;
|
|
5
|
+
let currentArgument = void 0;
|
|
6
|
+
for (let index = 0; index < input.length; index++) {
|
|
7
|
+
const char = input[index];
|
|
8
|
+
const previousChar = input[index - 1];
|
|
9
|
+
const nextChar = input[index + 1];
|
|
10
|
+
const end = index === input.length - 1;
|
|
11
|
+
if ((char === '"' || char === "'") && previousChar !== "\\") {
|
|
12
|
+
if (currentQuote === char) {
|
|
13
|
+
currentQuote = void 0;
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (currentQuote === void 0) {
|
|
17
|
+
currentQuote = char;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (currentQuote !== void 0 && char !== currentQuote) {
|
|
21
|
+
currentArgument ??= "";
|
|
22
|
+
currentArgument += char;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (char === "\\" && nextChar === "\n") {
|
|
28
|
+
index++;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (currentArgument !== void 0 && currentQuote === void 0) {
|
|
32
|
+
if (char === " ") {
|
|
33
|
+
argv.push(currentArgument);
|
|
34
|
+
currentArgument = void 0;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (end) {
|
|
38
|
+
currentArgument += char;
|
|
39
|
+
argv.push(currentArgument);
|
|
40
|
+
currentArgument = void 0;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (char === " " && currentQuote === void 0) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (char === "\\" && (nextChar === "'" || nextChar === '"')) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
currentArgument ??= "";
|
|
51
|
+
currentArgument += char;
|
|
52
|
+
}
|
|
53
|
+
if (currentArgument !== void 0) {
|
|
54
|
+
argv.push(currentArgument);
|
|
55
|
+
}
|
|
56
|
+
return argv;
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
parseArgv
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=parse-argv.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/utilities/parse-argv.ts"],
|
|
4
|
+
"sourcesContent": ["/** Parse a string into an argv (array of arguments) */\nexport function parseArgv(input: string): string[] {\n const argv = [];\n\n let currentQuote: string | undefined = undefined;\n let currentArgument: string | undefined = undefined;\n\n for (let index = 0; index < input.length; index++) {\n const char = input[index];\n const previousChar = input[index - 1];\n const nextChar = input[index + 1];\n const end = index === input.length - 1;\n\n // entering/leaving quote\n if ((char === '\"' || char === \"'\") && previousChar !== \"\\\\\") {\n // leaving quote\n if (currentQuote === char) {\n currentQuote = undefined;\n continue;\n }\n\n // entering quote\n if (currentQuote === undefined) {\n currentQuote = char;\n continue;\n }\n\n // quote inside quote\n if (currentQuote !== undefined && char !== currentQuote) {\n currentArgument ??= \"\";\n currentArgument += char;\n continue;\n }\n continue;\n }\n\n // new line\n if (char === \"\\\\\" && nextChar === \"\\n\") {\n index++;\n continue;\n }\n\n // Add to argv\n if (currentArgument !== undefined && currentQuote === undefined) {\n if (char === \" \") {\n argv.push(currentArgument);\n currentArgument = undefined;\n continue;\n }\n\n if (end) {\n currentArgument += char;\n argv.push(currentArgument);\n currentArgument = undefined;\n continue;\n }\n }\n\n // Ignore spaces outside of quotes\n if (char === \" \" && currentQuote === undefined) {\n continue;\n }\n\n // Ignore escaped characters\n if (char === \"\\\\\" && (nextChar === \"'\" || nextChar === '\"')) {\n continue;\n }\n\n currentArgument ??= \"\";\n currentArgument += char;\n }\n\n // Add last argument\n if (currentArgument !== undefined) {\n argv.push(currentArgument);\n }\n\n return argv;\n}\n"],
|
|
5
|
+
"mappings": ";AACO,SAAS,UAAU,OAAyB;AACjD,QAAM,OAAO,CAAC;AAEd,MAAI,eAAmC;AACvC,MAAI,kBAAsC;AAE1C,WAAS,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS;AACjD,UAAM,OAAO,MAAM,KAAK;AACxB,UAAM,eAAe,MAAM,QAAQ,CAAC;AACpC,UAAM,WAAW,MAAM,QAAQ,CAAC;AAChC,UAAM,MAAM,UAAU,MAAM,SAAS;AAGrC,SAAK,SAAS,OAAO,SAAS,QAAQ,iBAAiB,MAAM;AAE3D,UAAI,iBAAiB,MAAM;AACzB,uBAAe;AACf;AAAA,MACF;AAGA,UAAI,iBAAiB,QAAW;AAC9B,uBAAe;AACf;AAAA,MACF;AAGA,UAAI,iBAAiB,UAAa,SAAS,cAAc;AACvD,4BAAoB;AACpB,2BAAmB;AACnB;AAAA,MACF;AACA;AAAA,IACF;AAGA,QAAI,SAAS,QAAQ,aAAa,MAAM;AACtC;AACA;AAAA,IACF;AAGA,QAAI,oBAAoB,UAAa,iBAAiB,QAAW;AAC/D,UAAI,SAAS,KAAK;AAChB,aAAK,KAAK,eAAe;AACzB,0BAAkB;AAClB;AAAA,MACF;AAEA,UAAI,KAAK;AACP,2BAAmB;AACnB,aAAK,KAAK,eAAe;AACzB,0BAAkB;AAClB;AAAA,MACF;AAAA,IACF;AAGA,QAAI,SAAS,OAAO,iBAAiB,QAAW;AAC9C;AAAA,IACF;AAGA,QAAI,SAAS,SAAS,aAAa,OAAO,aAAa,MAAM;AAC3D;AAAA,IACF;AAEA,wBAAoB;AACpB,uBAAmB;AAAA,EACrB;AAGA,MAAI,oBAAoB,QAAW;AACjC,SAAK,KAAK,eAAe;AAAA,EAC3B;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/utilities/schema-utilities.ts
|
|
2
|
+
import { CliError } from "../cli-error/cli-error.mjs";
|
|
3
|
+
import { ErrorCause } from "../cli-error/error-cause.mjs";
|
|
4
|
+
import { ValidationErrorCode } from "../cli-error/error-code/validation-error-code.mjs";
|
|
5
|
+
function validateSync(schema, value) {
|
|
6
|
+
const results = schema["~standard"].validate(value);
|
|
7
|
+
if (results instanceof Promise) {
|
|
8
|
+
throw new CliError({
|
|
9
|
+
cause: ErrorCause.Validation,
|
|
10
|
+
code: ValidationErrorCode.AsyncSchemaNotSupported,
|
|
11
|
+
context: { schema, value }
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return results;
|
|
15
|
+
}
|
|
16
|
+
function defaultValueAndIsOptional(schema) {
|
|
17
|
+
const results = validateSync(schema);
|
|
18
|
+
if (results.issues) {
|
|
19
|
+
return { defaultValue: void 0, optional: false };
|
|
20
|
+
}
|
|
21
|
+
return { defaultValue: results.value, optional: true };
|
|
22
|
+
}
|
|
23
|
+
function PrepareType(schema, coerceHandler) {
|
|
24
|
+
const { optional, defaultValue } = defaultValueAndIsOptional(schema);
|
|
25
|
+
return {
|
|
26
|
+
schema,
|
|
27
|
+
optional,
|
|
28
|
+
defaultValue,
|
|
29
|
+
coerceTo: coerceHandler.type,
|
|
30
|
+
validate: (value) => validateSync(schema, value && coerceHandler(value))
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function prepareDefinitionTypes(definition) {
|
|
34
|
+
if (!definition) return;
|
|
35
|
+
for (const object of Object.values(definition)) {
|
|
36
|
+
if (!object.coerce) {
|
|
37
|
+
object.coerce = (value) => value;
|
|
38
|
+
}
|
|
39
|
+
if (!object._preparedType) {
|
|
40
|
+
object._preparedType = PrepareType(object.schema, object.coerce);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function prettifyError(issues) {
|
|
45
|
+
return issues.map((issue) => {
|
|
46
|
+
const path = issue.path?.map((seg) => typeof seg === "object" && "key" in seg ? seg.key : seg);
|
|
47
|
+
const pathString = path && path.length > 0 ? ` at "${path.join(".")}"` : "";
|
|
48
|
+
return `${issue.message}${pathString}`;
|
|
49
|
+
}).join(" : ");
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
defaultValueAndIsOptional,
|
|
53
|
+
prepareDefinitionTypes,
|
|
54
|
+
prettifyError,
|
|
55
|
+
validateSync
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=schema-utilities.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/utilities/schema-utilities.ts"],
|
|
4
|
+
"sourcesContent": ["import { CliError } from \"../cli-error/cli-error.ts\";\nimport { ErrorCause } from \"../cli-error/error-cause.ts\";\nimport { ValidationErrorCode } from \"../cli-error/error-code/validation-error-code.ts\";\n\nimport type { Argument, Option, PreparedType } from \"../types/definitions-types.ts\";\nimport type { SchemaResult, SchemaType } from \"../types/schema-types.ts\";\nimport type { CoerceMethod } from \"../types/types.ts\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\n/** @throws {CliError} When schema is async */\nexport function validateSync(schema: SchemaType, value?: unknown): SchemaResult {\n const results = schema[\"~standard\"].validate(value);\n if (results instanceof Promise) {\n throw new CliError({\n cause: ErrorCause.Validation,\n code: ValidationErrorCode.AsyncSchemaNotSupported,\n context: { schema, value },\n });\n }\n\n return results;\n}\n\n/** @throws {CliError} When schema is async */\nexport function defaultValueAndIsOptional(schema: SchemaType): { defaultValue: unknown; optional: boolean } {\n const results = validateSync(schema);\n\n if (results.issues) {\n return { defaultValue: undefined, optional: false };\n }\n\n return { defaultValue: results.value, optional: true };\n}\n\n/** @throws {CliError} When schema is async */\nfunction PrepareType(schema: SchemaType, coerceHandler: CoerceMethod<unknown>): PreparedType {\n const { optional, defaultValue } = defaultValueAndIsOptional(schema);\n\n return {\n schema,\n optional,\n defaultValue,\n coerceTo: coerceHandler.type,\n validate: (value?: string) => validateSync(schema, value && coerceHandler(value)),\n };\n}\n\n/** @throws {CliError} When schema is async */\nexport function prepareDefinitionTypes(definition: Record<string, Argument> | Record<string, Option> | undefined) {\n if (!definition) return;\n\n for (const object of Object.values<Argument | Option>(definition)) {\n if (!object.coerce) {\n (object.coerce as CoerceMethod<string> | undefined) = (value: string) => value;\n }\n\n if (!object._preparedType) {\n object._preparedType = PrepareType(object.schema, object.coerce!);\n }\n }\n}\n\n/** Prettify Standard Schema V1 issues */\nexport function prettifyError(issues: ReadonlyArray<StandardSchemaV1.Issue>): string {\n return issues\n .map(issue => {\n const path = issue.path?.map(seg => (typeof seg === \"object\" && \"key\" in seg ? seg.key : seg));\n const pathString = path && path.length > 0 ? ` at \"${path.join(\".\")}\"` : \"\";\n return `${issue.message}${pathString}`;\n })\n .join(\" : \");\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,2BAA2B;AAQ7B,SAAS,aAAa,QAAoB,OAA+B;AAC9E,QAAM,UAAU,OAAO,WAAW,EAAE,SAAS,KAAK;AAClD,MAAI,mBAAmB,SAAS;AAC9B,UAAM,IAAI,SAAS;AAAA,MACjB,OAAO,WAAW;AAAA,MAClB,MAAM,oBAAoB;AAAA,MAC1B,SAAS,EAAE,QAAQ,MAAM;AAAA,IAC3B,CAAC;AAAA,EACH;AAEA,SAAO;AACT;AAGO,SAAS,0BAA0B,QAAkE;AAC1G,QAAM,UAAU,aAAa,MAAM;AAEnC,MAAI,QAAQ,QAAQ;AAClB,WAAO,EAAE,cAAc,QAAW,UAAU,MAAM;AAAA,EACpD;AAEA,SAAO,EAAE,cAAc,QAAQ,OAAO,UAAU,KAAK;AACvD;AAGA,SAAS,YAAY,QAAoB,eAAoD;AAC3F,QAAM,EAAE,UAAU,aAAa,IAAI,0BAA0B,MAAM;AAEnE,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU,cAAc;AAAA,IACxB,UAAU,CAAC,UAAmB,aAAa,QAAQ,SAAS,cAAc,KAAK,CAAC;AAAA,EAClF;AACF;AAGO,SAAS,uBAAuB,YAA2E;AAChH,MAAI,CAAC,WAAY;AAEjB,aAAW,UAAU,OAAO,OAA0B,UAAU,GAAG;AACjE,QAAI,CAAC,OAAO,QAAQ;AAClB,MAAC,OAAO,SAA8C,CAAC,UAAkB;AAAA,IAC3E;AAEA,QAAI,CAAC,OAAO,eAAe;AACzB,aAAO,gBAAgB,YAAY,OAAO,QAAQ,OAAO,MAAO;AAAA,IAClE;AAAA,EACF;AACF;AAGO,SAAS,cAAc,QAAuD;AACnF,SAAO,OACJ,IAAI,WAAS;AACZ,UAAM,OAAO,MAAM,MAAM,IAAI,SAAQ,OAAO,QAAQ,YAAY,SAAS,MAAM,IAAI,MAAM,GAAI;AAC7F,UAAM,aAAa,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,KAAK,GAAG,CAAC,MAAM;AACzE,WAAO,GAAG,MAAM,OAAO,GAAG,UAAU;AAAA,EACtC,CAAC,EACA,KAAK,KAAK;AACf;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// src/utilities/utilities.ts
|
|
2
|
+
function toKebabCase(input) {
|
|
3
|
+
return input.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
4
|
+
}
|
|
5
|
+
function generateOrdinalSuffix(index) {
|
|
6
|
+
if (index < 0) return "";
|
|
7
|
+
const number = index + 1;
|
|
8
|
+
const lastDigit = number % 10;
|
|
9
|
+
const lastTwoDigits = number % 100;
|
|
10
|
+
let suffix = "th";
|
|
11
|
+
if (lastTwoDigits < 11 || lastTwoDigits > 13) {
|
|
12
|
+
switch (lastDigit) {
|
|
13
|
+
case 1: {
|
|
14
|
+
suffix = "st";
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
case 2: {
|
|
18
|
+
suffix = "nd";
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
case 3: {
|
|
22
|
+
suffix = "rd";
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return `${number}${suffix}`;
|
|
28
|
+
}
|
|
29
|
+
function ln(count) {
|
|
30
|
+
return "\n".repeat(count);
|
|
31
|
+
}
|
|
32
|
+
function indent(count) {
|
|
33
|
+
if (count <= 0) return "";
|
|
34
|
+
return " ".repeat(count);
|
|
35
|
+
}
|
|
36
|
+
function indentLines(text, spaces) {
|
|
37
|
+
return text.replace(/\n/g, "\n" + indent(spaces));
|
|
38
|
+
}
|
|
39
|
+
function stringifyValue(value) {
|
|
40
|
+
if (value instanceof Set) {
|
|
41
|
+
return "new Set([" + Array.from(value).map((element) => stringifyValue(element)).join(", ") + "])";
|
|
42
|
+
}
|
|
43
|
+
return JSON.stringify(value);
|
|
44
|
+
}
|
|
45
|
+
function insertAtEndOfFirstLine(string, insert) {
|
|
46
|
+
const lines = string.split("\n");
|
|
47
|
+
lines[0] += (lines[0] ? " " : "") + insert;
|
|
48
|
+
return lines.join("\n");
|
|
49
|
+
}
|
|
50
|
+
function subcommandPlaceholder(metadata) {
|
|
51
|
+
let placeholder = metadata.placeholder;
|
|
52
|
+
if (placeholder) {
|
|
53
|
+
return placeholder;
|
|
54
|
+
}
|
|
55
|
+
if (metadata.options.length > 0) {
|
|
56
|
+
placeholder += (placeholder ? " " : "") + "[options]";
|
|
57
|
+
}
|
|
58
|
+
if (metadata.arguments.length > 0) {
|
|
59
|
+
placeholder += (placeholder ? " " : "") + "<arguments>";
|
|
60
|
+
}
|
|
61
|
+
if (metadata.allowPositionals) {
|
|
62
|
+
placeholder += (placeholder ? " " : "") + "<positionals>";
|
|
63
|
+
}
|
|
64
|
+
if (!placeholder) {
|
|
65
|
+
placeholder = " ";
|
|
66
|
+
}
|
|
67
|
+
return placeholder;
|
|
68
|
+
}
|
|
69
|
+
function escapeHtmlTags(markdown) {
|
|
70
|
+
const escapeMap = { "&": "&", "<": "<", ">": ">" };
|
|
71
|
+
const re = /(```[\s\S]*?```|`[^`]*`)|(<!--[\s\S]*?-->)|(<[^>]+>)/g;
|
|
72
|
+
return markdown.replace(re, (fullMatch, code, comment, tag) => {
|
|
73
|
+
if (code) return code;
|
|
74
|
+
if (comment) return comment;
|
|
75
|
+
if (!tag) return fullMatch;
|
|
76
|
+
return tag.replace(/[&<>]/g, (ch) => escapeMap[ch]);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function ansiRegex({ onlyFirst = false } = {}) {
|
|
80
|
+
const ST = String.raw`(?:\u0007|\u001B\u005C|\u009C)`;
|
|
81
|
+
const osc = String.raw`(?:\u001B\][\s\S]*?${ST})`;
|
|
82
|
+
const csi = String.raw`[\u001B\u009B][[\]()#;?]*(?:\d{1,4}(?:[;:]\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]`;
|
|
83
|
+
const pattern = `${osc}|${csi}`;
|
|
84
|
+
return new RegExp(pattern, onlyFirst ? void 0 : "g");
|
|
85
|
+
}
|
|
86
|
+
var regex = ansiRegex();
|
|
87
|
+
function stripAnsi(string) {
|
|
88
|
+
return string.replace(regex, "");
|
|
89
|
+
}
|
|
90
|
+
function walkObject(object_, onVisit, basePath = "") {
|
|
91
|
+
for (const [key, value] of Object.entries(object_)) {
|
|
92
|
+
const path = basePath ? `${basePath}.${key}` : key;
|
|
93
|
+
const newValue = onVisit(key, value, path);
|
|
94
|
+
if (newValue !== void 0) {
|
|
95
|
+
object_[key] = newValue;
|
|
96
|
+
}
|
|
97
|
+
const target = object_[key];
|
|
98
|
+
if (target && typeof target === "object" && !Array.isArray(target)) {
|
|
99
|
+
walkObject(target, onVisit, path);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function Enum(value) {
|
|
104
|
+
const casted = value;
|
|
105
|
+
for (const [key] of Object.entries(casted)) casted[key] = key;
|
|
106
|
+
return Object.freeze(casted);
|
|
107
|
+
}
|
|
108
|
+
export {
|
|
109
|
+
Enum,
|
|
110
|
+
escapeHtmlTags,
|
|
111
|
+
generateOrdinalSuffix,
|
|
112
|
+
indent,
|
|
113
|
+
indentLines,
|
|
114
|
+
insertAtEndOfFirstLine,
|
|
115
|
+
ln,
|
|
116
|
+
stringifyValue,
|
|
117
|
+
stripAnsi,
|
|
118
|
+
subcommandPlaceholder,
|
|
119
|
+
toKebabCase,
|
|
120
|
+
walkObject
|
|
121
|
+
};
|
|
122
|
+
//# sourceMappingURL=utilities.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/utilities/utilities.ts"],
|
|
4
|
+
"sourcesContent": ["import type { SubcommandMetadata } from \"../types/metadata-types.ts\";\n\nexport function toKebabCase(input: string): string {\n return input.replace(/([a-z])([A-Z])/g, \"$1-$2\").toLowerCase();\n}\n\n/**\n * Converts a zero-based index into its human-readable ordinal form.\n *\n * Examples: 0 \u2192 \"1st\" 1 \u2192 \"2nd\" 2 \u2192 \"3rd\" 3 \u2192 \"4th\" 10 \u2192 \"11th\"\n *\n * Handles special cases for 11, 12, and 13.\n *\n * @param index - The zero-based index to convert.\n * @returns The ordinal string (e.g., \"1st\", \"2nd\", \"3rd\", \"4th\", ...).\n */\nexport function generateOrdinalSuffix(index: number): string {\n if (index < 0) return \"\";\n\n const number = index + 1;\n const lastDigit = number % 10;\n const lastTwoDigits = number % 100;\n\n let suffix = \"th\";\n\n if (lastTwoDigits < 11 || lastTwoDigits > 13) {\n switch (lastDigit) {\n case 1: {\n suffix = \"st\";\n break;\n }\n case 2: {\n suffix = \"nd\";\n break;\n }\n case 3: {\n suffix = \"rd\";\n break;\n }\n }\n }\n\n return `${number}${suffix}`;\n}\n\n/** New line */\nexport function ln(count: number) {\n return \"\\n\".repeat(count);\n}\n\n/** Space */\nexport function indent(count: number) {\n if (count <= 0) return \"\";\n return \" \".repeat(count);\n}\n\n/** Indents every line in the given text by the provided number of spaces. Empty lines are preserved. */\nexport function indentLines(text: string, spaces: number): string {\n return text.replace(/\\n/g, \"\\n\" + indent(spaces));\n}\n\nexport function stringifyValue(value: unknown): string {\n // Set\n if (value instanceof Set) {\n return (\n \"new Set([\" +\n Array.from(value)\n .map(element => stringifyValue(element))\n .join(\", \") +\n \"])\"\n );\n }\n\n // unknown\n return JSON.stringify(value);\n}\n\n/** Insert text at the end of the first line */\nexport function insertAtEndOfFirstLine(string: string, insert: string) {\n const lines = string.split(\"\\n\");\n lines[0] += (lines[0] ? \" \" : \"\") + insert;\n return lines.join(\"\\n\");\n}\n\n/** Get the placeholder for a subcommand */\nexport function subcommandPlaceholder(metadata: SubcommandMetadata): string {\n let placeholder = metadata.placeholder;\n\n if (placeholder) {\n return placeholder;\n }\n\n if (metadata.options.length > 0) {\n placeholder += (placeholder ? \" \" : \"\") + \"[options]\";\n }\n\n if (metadata.arguments.length > 0) {\n placeholder += (placeholder ? \" \" : \"\") + \"<arguments>\";\n }\n\n if (metadata.allowPositionals) {\n placeholder += (placeholder ? \" \" : \"\") + \"<positionals>\";\n }\n\n if (!placeholder) {\n placeholder = \" \";\n }\n\n return placeholder;\n}\n\n/**\n * Escape HTML characters inside HTML tags in a Markdown string, but leave code blocks, inline code, and HTML comments\n * unchanged.\n */\nexport function escapeHtmlTags(markdown: string): string {\n const escapeMap: Record<string, string> = { \"&\": \"&\", \"<\": \"<\", \">\": \">\" };\n\n // Captures:\n // 1) fenced code blocks or inline code\n // 2) HTML comments <!-- ... -->\n // 3) other HTML tags like <b>, <div attr=\"x\">, etc.\n const re = /(```[\\s\\S]*?```|`[^`]*`)|(<!--[\\s\\S]*?-->)|(<[^>]+>)/g;\n\n return markdown.replace(re, (fullMatch: string, code?: string, comment?: string, tag?: string) => {\n if (code) return code;\n if (comment) return comment;\n if (!tag) return fullMatch;\n\n return tag.replace(/[&<>]/g, ch => escapeMap[ch]);\n });\n}\n\n/** Credits: https://github.com/chalk/ansi-regex */\nfunction ansiRegex({ onlyFirst = false } = {}) {\n // Valid string terminator sequences are BEL, ESC\\, and 0x9c\n const ST = String.raw`(?:\\u0007|\\u001B\\u005C|\\u009C)`;\n\n // OSC sequences only: ESC ] ... ST (non-greedy until the first ST)\n const osc = String.raw`(?:\\u001B\\][\\s\\S]*?${ST})`;\n\n // CSI and related: ESC/C1, optional intermediates, optional params (supports ; and :) then final byte\n const csi = String.raw`[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]`;\n\n const pattern = `${osc}|${csi}`;\n\n return new RegExp(pattern, onlyFirst ? undefined : \"g\");\n}\n\nconst regex = ansiRegex();\n\nexport function stripAnsi(string: string): string {\n return string.replace(regex, \"\");\n}\n\ntype WalkCallback = (key: string, value: unknown, path: string) => unknown;\n\n/**\n * Recursively walks through an object and calls a function for each key-value pair.\n *\n * @param object_ - The object to walk.\n * @param onVisit - Function called on every visited property (key, value, path).\n * @param basePath - (Internal) Used for recursion to build nested paths.\n */\nexport function walkObject(object_: Record<string, unknown>, onVisit: WalkCallback, basePath = \"\"): void {\n for (const [key, value] of Object.entries(object_)) {\n const path = basePath ? `${basePath}.${key}` : key;\n const newValue = onVisit(key, value, path);\n\n if (newValue !== undefined) {\n object_[key] = newValue;\n }\n\n const target = object_[key];\n if (target && typeof target === \"object\" && !Array.isArray(target)) {\n walkObject(target as Record<string, unknown>, onVisit, path);\n }\n }\n}\n\nexport function Enum<const T extends Record<string, undefined>>(value: T) {\n const casted = value as Record<string, unknown>;\n for (const [key] of Object.entries(casted)) casted[key] = key;\n return Object.freeze(casted) as { [K in keyof T]: K };\n}\n"],
|
|
5
|
+
"mappings": ";AAEO,SAAS,YAAY,OAAuB;AACjD,SAAO,MAAM,QAAQ,mBAAmB,OAAO,EAAE,YAAY;AAC/D;AAYO,SAAS,sBAAsB,OAAuB;AAC3D,MAAI,QAAQ,EAAG,QAAO;AAEtB,QAAM,SAAS,QAAQ;AACvB,QAAM,YAAY,SAAS;AAC3B,QAAM,gBAAgB,SAAS;AAE/B,MAAI,SAAS;AAEb,MAAI,gBAAgB,MAAM,gBAAgB,IAAI;AAC5C,YAAQ,WAAW;AAAA,MACjB,KAAK,GAAG;AACN,iBAAS;AACT;AAAA,MACF;AAAA,MACA,KAAK,GAAG;AACN,iBAAS;AACT;AAAA,MACF;AAAA,MACA,KAAK,GAAG;AACN,iBAAS;AACT;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO,GAAG,MAAM,GAAG,MAAM;AAC3B;AAGO,SAAS,GAAG,OAAe;AAChC,SAAO,KAAK,OAAO,KAAK;AAC1B;AAGO,SAAS,OAAO,OAAe;AACpC,MAAI,SAAS,EAAG,QAAO;AACvB,SAAO,IAAI,OAAO,KAAK;AACzB;AAGO,SAAS,YAAY,MAAc,QAAwB;AAChE,SAAO,KAAK,QAAQ,OAAO,OAAO,OAAO,MAAM,CAAC;AAClD;AAEO,SAAS,eAAe,OAAwB;AAErD,MAAI,iBAAiB,KAAK;AACxB,WACE,cACA,MAAM,KAAK,KAAK,EACb,IAAI,aAAW,eAAe,OAAO,CAAC,EACtC,KAAK,IAAI,IACZ;AAAA,EAEJ;AAGA,SAAO,KAAK,UAAU,KAAK;AAC7B;AAGO,SAAS,uBAAuB,QAAgB,QAAgB;AACrE,QAAM,QAAQ,OAAO,MAAM,IAAI;AAC/B,QAAM,CAAC,MAAM,MAAM,CAAC,IAAI,MAAM,MAAM;AACpC,SAAO,MAAM,KAAK,IAAI;AACxB;AAGO,SAAS,sBAAsB,UAAsC;AAC1E,MAAI,cAAc,SAAS;AAE3B,MAAI,aAAa;AACf,WAAO;AAAA,EACT;AAEA,MAAI,SAAS,QAAQ,SAAS,GAAG;AAC/B,oBAAgB,cAAc,MAAM,MAAM;AAAA,EAC5C;AAEA,MAAI,SAAS,UAAU,SAAS,GAAG;AACjC,oBAAgB,cAAc,MAAM,MAAM;AAAA,EAC5C;AAEA,MAAI,SAAS,kBAAkB;AAC7B,oBAAgB,cAAc,MAAM,MAAM;AAAA,EAC5C;AAEA,MAAI,CAAC,aAAa;AAChB,kBAAc;AAAA,EAChB;AAEA,SAAO;AACT;AAMO,SAAS,eAAe,UAA0B;AACvD,QAAM,YAAoC,EAAE,KAAK,SAAS,KAAK,QAAQ,KAAK,OAAO;AAMnF,QAAM,KAAK;AAEX,SAAO,SAAS,QAAQ,IAAI,CAAC,WAAmB,MAAe,SAAkB,QAAiB;AAChG,QAAI,KAAM,QAAO;AACjB,QAAI,QAAS,QAAO;AACpB,QAAI,CAAC,IAAK,QAAO;AAEjB,WAAO,IAAI,QAAQ,UAAU,QAAM,UAAU,EAAE,CAAC;AAAA,EAClD,CAAC;AACH;AAGA,SAAS,UAAU,EAAE,YAAY,MAAM,IAAI,CAAC,GAAG;AAE7C,QAAM,KAAK,OAAO;AAGlB,QAAM,MAAM,OAAO,yBAAyB,EAAE;AAG9C,QAAM,MAAM,OAAO;AAEnB,QAAM,UAAU,GAAG,GAAG,IAAI,GAAG;AAE7B,SAAO,IAAI,OAAO,SAAS,YAAY,SAAY,GAAG;AACxD;AAEA,IAAM,QAAQ,UAAU;AAEjB,SAAS,UAAU,QAAwB;AAChD,SAAO,OAAO,QAAQ,OAAO,EAAE;AACjC;AAWO,SAAS,WAAW,SAAkC,SAAuB,WAAW,IAAU;AACvG,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,OAAO,GAAG;AAClD,UAAM,OAAO,WAAW,GAAG,QAAQ,IAAI,GAAG,KAAK;AAC/C,UAAM,WAAW,QAAQ,KAAK,OAAO,IAAI;AAEzC,QAAI,aAAa,QAAW;AAC1B,cAAQ,GAAG,IAAI;AAAA,IACjB;AAEA,UAAM,SAAS,QAAQ,GAAG;AAC1B,QAAI,UAAU,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,MAAM,GAAG;AAClE,iBAAW,QAAmC,SAAS,IAAI;AAAA,IAC7D;AAAA,EACF;AACF;AAEO,SAAS,KAAgD,OAAU;AACxE,QAAM,SAAS;AACf,aAAW,CAAC,GAAG,KAAK,OAAO,QAAQ,MAAM,EAAG,QAAO,GAAG,IAAI;AAC1D,SAAO,OAAO,OAAO,MAAM;AAC7B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bash-autocomplete-script.d.ts","sourceRoot":"","sources":["../../../src/autocomplete-scripts/bash-autocomplete-script.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAC;AAEzD;;;;;;;GAOG;AACH,wBAAgB,8BAA8B,CAAC,aAAa,EAAE,GAAG,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"bash-autocomplete-script.d.ts","sourceRoot":"","sources":["../../../src/autocomplete-scripts/bash-autocomplete-script.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAC;AAEzD;;;;;;;GAOG;AACH,wBAAgB,8BAA8B,CAAC,aAAa,EAAE,GAAG,GAAG,MAAM,CA0EzE"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Cli } from "../types/definitions-types.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Generates a PowerShell autocomplete script for a CLI.
|
|
4
|
+
*
|
|
5
|
+
* Instructions:
|
|
6
|
+
*
|
|
7
|
+
* - Ensure your CLI is available as a `.ps1` file in your environment. e.g., `cliName.ps1`.
|
|
8
|
+
* - Add the generated script to your `profile.ps1` file:
|
|
9
|
+
*
|
|
10
|
+
* 1. Run: `notepad $profile`
|
|
11
|
+
* 2. Add: `. "<generated script path>"`
|
|
12
|
+
* 3. Save and reopen PowerShell
|
|
13
|
+
*/
|
|
14
|
+
export declare function generatePowerShellAutocompleteScript(cliDefinition: Cli): string;
|
|
15
|
+
//# sourceMappingURL=powershell-autocomplete-script.d.ts.map
|
package/lib/{typescript → types}/autocomplete-scripts/powershell-autocomplete-script.d.ts.map
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"powershell-autocomplete-script.d.ts","sourceRoot":"","sources":["../../../src/autocomplete-scripts/powershell-autocomplete-script.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAC;AAEzD
|
|
1
|
+
{"version":3,"file":"powershell-autocomplete-script.d.ts","sourceRoot":"","sources":["../../../src/autocomplete-scripts/powershell-autocomplete-script.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAC;AAEzD;;;;;;;;;;;GAWG;AACH,wBAAgB,oCAAoC,CAAC,aAAa,EAAE,GAAG,GAAG,MAAM,CAyG/E"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Cli } from "../types/definitions-types.ts";
|
|
2
|
+
/** Generates a Zsh autocomplete script for a CLI, including global options when no subcommand is provided. */
|
|
3
|
+
export declare function generateZshAutocompleteScript(cliDefinition: Cli): string;
|
|
4
|
+
//# sourceMappingURL=zsh-autocomplete-script.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zsh-autocomplete-script.d.ts","sourceRoot":"","sources":["../../../src/autocomplete-scripts/zsh-autocomplete-script.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAc,MAAM,+BAA+B,CAAC;AAErE
|
|
1
|
+
{"version":3,"file":"zsh-autocomplete-script.d.ts","sourceRoot":"","sources":["../../../src/autocomplete-scripts/zsh-autocomplete-script.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAc,MAAM,+BAA+B,CAAC;AAErE,8GAA8G;AAC9G,wBAAgB,6BAA6B,CAAC,aAAa,EAAE,GAAG,GAAG,MAAM,CA8ExE"}
|