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,53 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { SubcommandMetadata } from "./types/metadata-types.ts";
|
|
3
|
-
import type { SchemaResult, SchemaType } from "./types/schema-types.ts";
|
|
4
|
-
import type { CoerceMethod } from "./types/types.ts";
|
|
5
|
-
|
|
6
|
-
/** @throws */
|
|
7
|
-
export function validateSync(schema: SchemaType, value?: unknown): SchemaResult {
|
|
8
|
-
const results = schema["~standard"].validate(value);
|
|
9
|
-
if (results instanceof Promise) {
|
|
10
|
-
throw new TypeError("async schema validation not supported");
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return results;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function defaultValueAndIsOptional(schema: SchemaType): { defaultValue: unknown; optional: boolean } {
|
|
17
|
-
const results = validateSync(schema);
|
|
18
|
-
|
|
19
|
-
if (results.issues) {
|
|
20
|
-
return { defaultValue: undefined, optional: false };
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return { defaultValue: results.value, optional: true };
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function PrepareType(schema: SchemaType, coerceHandler: CoerceMethod<unknown>): PreparedType {
|
|
27
|
-
const { optional, defaultValue } = defaultValueAndIsOptional(schema);
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
schema,
|
|
31
|
-
optional,
|
|
32
|
-
defaultValue,
|
|
33
|
-
coerceTo: coerceHandler.type,
|
|
34
|
-
validate: (value?: string) => validateSync(schema, value && coerceHandler(value)),
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function prepareDefinitionTypes(definition: Record<string, Argument> | Record<string, Option> | undefined) {
|
|
39
|
-
if (!definition) return;
|
|
40
|
-
|
|
41
|
-
for (const object of Object.values<Argument | Option>(definition)) {
|
|
42
|
-
if (!object.coerce) {
|
|
43
|
-
object.coerce = (value: string) => value;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (!object._preparedType) {
|
|
47
|
-
object._preparedType = PrepareType(object.schema, object.coerce);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
1
|
+
import type { SubcommandMetadata } from "../types/metadata-types.ts";
|
|
51
2
|
|
|
52
3
|
export function toKebabCase(input: string): string {
|
|
53
4
|
return input.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
@@ -158,85 +109,6 @@ export function subcommandPlaceholder(metadata: SubcommandMetadata): string {
|
|
|
158
109
|
return placeholder;
|
|
159
110
|
}
|
|
160
111
|
|
|
161
|
-
/** Parse a string into an argv (array of arguments) */
|
|
162
|
-
export function parseArgv(input: string): string[] {
|
|
163
|
-
const argv = [];
|
|
164
|
-
|
|
165
|
-
let currentQuote: string | undefined = undefined;
|
|
166
|
-
let currentArgument: string | undefined = undefined;
|
|
167
|
-
|
|
168
|
-
for (let index = 0; index < input.length; index++) {
|
|
169
|
-
const char = input[index];
|
|
170
|
-
const previousChar = input[index - 1];
|
|
171
|
-
const nextChar = input[index + 1];
|
|
172
|
-
const end = index === input.length - 1;
|
|
173
|
-
|
|
174
|
-
// entering/leaving quote
|
|
175
|
-
if ((char === '"' || char === "'") && previousChar !== "\\") {
|
|
176
|
-
// leaving quote
|
|
177
|
-
if (currentQuote === char) {
|
|
178
|
-
currentQuote = undefined;
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// entering quote
|
|
183
|
-
if (currentQuote === undefined) {
|
|
184
|
-
currentQuote = char;
|
|
185
|
-
continue;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// quote inside quote
|
|
189
|
-
if (currentQuote !== undefined && char !== currentQuote) {
|
|
190
|
-
currentArgument += char;
|
|
191
|
-
continue;
|
|
192
|
-
}
|
|
193
|
-
continue;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// new line
|
|
197
|
-
if (char === "\\" && nextChar === "\n") {
|
|
198
|
-
index++;
|
|
199
|
-
continue;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// Add to argv
|
|
203
|
-
if (currentArgument !== undefined && currentQuote === undefined) {
|
|
204
|
-
if (char === " ") {
|
|
205
|
-
argv.push(currentArgument);
|
|
206
|
-
currentArgument = undefined;
|
|
207
|
-
continue;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
if (end) {
|
|
211
|
-
currentArgument += char;
|
|
212
|
-
argv.push(currentArgument);
|
|
213
|
-
currentArgument = undefined;
|
|
214
|
-
continue;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// Ignore spaces outside of quotes
|
|
219
|
-
if (char === " " && currentQuote === undefined) {
|
|
220
|
-
continue;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// Ignore escaped characters
|
|
224
|
-
if (char === "\\" && (nextChar === "'" || nextChar === '"')) {
|
|
225
|
-
continue;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
currentArgument ??= "";
|
|
229
|
-
currentArgument += char;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// Add last argument
|
|
233
|
-
if (currentArgument !== undefined) {
|
|
234
|
-
argv.push(currentArgument);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return argv;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
112
|
/**
|
|
241
113
|
* Escape HTML characters inside HTML tags in a Markdown string, but leave code blocks, inline code, and HTML comments
|
|
242
114
|
* unchanged.
|
|
@@ -281,18 +153,33 @@ export function stripAnsi(string: string): string {
|
|
|
281
153
|
return string.replace(regex, "");
|
|
282
154
|
}
|
|
283
155
|
|
|
284
|
-
|
|
285
|
-
const seen = new Set<string>();
|
|
286
|
-
const duplicates = new Set<string>();
|
|
156
|
+
type WalkCallback = (key: string, value: unknown, path: string) => unknown;
|
|
287
157
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
158
|
+
/**
|
|
159
|
+
* Recursively walks through an object and calls a function for each key-value pair.
|
|
160
|
+
*
|
|
161
|
+
* @param object_ - The object to walk.
|
|
162
|
+
* @param onVisit - Function called on every visited property (key, value, path).
|
|
163
|
+
* @param basePath - (Internal) Used for recursion to build nested paths.
|
|
164
|
+
*/
|
|
165
|
+
export function walkObject(object_: Record<string, unknown>, onVisit: WalkCallback, basePath = ""): void {
|
|
166
|
+
for (const [key, value] of Object.entries(object_)) {
|
|
167
|
+
const path = basePath ? `${basePath}.${key}` : key;
|
|
168
|
+
const newValue = onVisit(key, value, path);
|
|
169
|
+
|
|
170
|
+
if (newValue !== undefined) {
|
|
171
|
+
object_[key] = newValue;
|
|
292
172
|
}
|
|
293
173
|
|
|
294
|
-
|
|
174
|
+
const target = object_[key];
|
|
175
|
+
if (target && typeof target === "object" && !Array.isArray(target)) {
|
|
176
|
+
walkObject(target as Record<string, unknown>, onVisit, path);
|
|
177
|
+
}
|
|
295
178
|
}
|
|
179
|
+
}
|
|
296
180
|
|
|
297
|
-
|
|
181
|
+
export function Enum<const T extends Record<string, undefined>>(value: T) {
|
|
182
|
+
const casted = value as Record<string, unknown>;
|
|
183
|
+
for (const [key] of Object.entries(casted)) casted[key] = key;
|
|
184
|
+
return Object.freeze(casted) as { [K in keyof T]: K };
|
|
298
185
|
}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(e,o)=>{for(var t in o)__defProp(e,t,{get:o[t],enumerable:!0})},__copyProps=(e,o,t,n)=>{if(o&&"object"==typeof o||"function"==typeof o)for(let r of __getOwnPropNames(o))__hasOwnProp.call(e,r)||r===t||__defProp(e,r,{get:()=>o[r],enumerable:!(n=__getOwnPropDesc(o,r))||n.enumerable});return e},__toCommonJS=e=>__copyProps(__defProp({},"__esModule",{value:!0}),e),bash_autocomplete_script_exports={};__export(bash_autocomplete_script_exports,{generateBashAutocompleteScript:()=>generateBashAutocompleteScript}),module.exports=__toCommonJS(bash_autocomplete_script_exports);var import_parser_utilities=require("../parse/parser-utilities.cjs");function generateBashAutocompleteScript(e){const o=e.subcommands??[],t={};for(const e of o)t[e.name]={options:e.options?Object.keys(e.options).map(e=>(0,import_parser_utilities.transformOptionToArgument)(e)):[],aliases:e.aliases??[]};let n="";for(const[e,{options:o,aliases:r}]of Object.entries(t))n+=` ${e}${r.length>0?"|":""}${r.join("|")})\n`,n+=` opts="${o.join(" ")}"\n`,n+=" ;;\n";if(e.options?.length){n+=' "-"*)\n',n+=` opts="${(e.options?Object.keys(e.options).map(e=>(0,import_parser_utilities.transformOptionToArgument)(e)):[]).join(" ")}"\n`,n+=" ;;\n"}return`# Auto-generated by zod-args-parser\n\n_${e.cliName}_autocomplete() {\n local cur prev commands opts subcommand used_opts filtered_opts\n\n cur="\${COMP_WORDS[COMP_CWORD]}"\n prev="\${COMP_WORDS[COMP_CWORD-1]}"\n subcommand="\${COMP_WORDS[1]}"\n\n commands="${Object.keys(t).join(" ")}"\n\n case "$subcommand" in\n${n}\n esac\n\n used_opts=""\n if [[ " \${commands[@]} " =~ " $subcommand " ]]; then\n for word in "\${COMP_WORDS[@]:2}"; do\n if [[ "$word" =~ ^- ]]; then\n used_opts+=" $word"\n fi\n done\n fi\n\n if [[ -n "$opts" ]]; then\n filtered_opts=""\n for opt in $opts; do\n if [[ ! " $used_opts " =~ " $opt " ]]; then\n filtered_opts+="$opt "\n fi\n done\n COMPREPLY=( $(compgen -W "$filtered_opts" -- "$cur") )\n return\n fi\n\n if [[ "\${COMP_CWORD}" -eq 1 ]]; then\n COMPREPLY=( $(compgen -W "$commands" -- "$cur") )\n fi\n}\n\ncomplete -F _${e.cliName}_autocomplete ${e.cliName}\n`}
|
|
2
|
-
//# sourceMappingURL=bash-autocomplete-script.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["bash_autocomplete_script_exports","__export","generateBashAutocompleteScript","module","exports","__toCommonJS","import_parser_utilities","require","cliDefinition","subcommands","mappedCommands","subcommand","name","options","Object","keys","map","key","transformOptionToArgument","aliases","switchCase","entries","length","join","cliName"],"sources":["../../../src/autocomplete-scripts/bash-autocomplete-script.ts"],"sourcesContent":["import { transformOptionToArgument } from \"../parse/parser-utilities.ts\";\n\nimport type { Cli } from \"../types/definitions-types.ts\";\n\n/**\n * - Generate bash autocomplete script for your CLI\n * - The generated script should be added to your `.bash_profile` or `.bashrc` file:\n *\n * - Run: `nano $HOME/.bash_profile` or `nano $HOME/.bashrc`\n * - Add the following line: `source <generated script path>`\n * - Save and reopen bash to take effect\n */\nexport function generateBashAutocompleteScript(cliDefinition: Cli): string {\n const subcommands = cliDefinition.subcommands ?? [];\n\n type MappedCommands = Record<string, { options: string[]; aliases: string[] }>;\n\n const mappedCommands: MappedCommands = {};\n\n for (const subcommand of subcommands) {\n mappedCommands[subcommand.name] = {\n options: subcommand.options ? Object.keys(subcommand.options).map(key => transformOptionToArgument(key)) : [],\n aliases: subcommand.aliases ?? [],\n };\n }\n\n let switchCase = \"\";\n for (const [key, { options, aliases }] of Object.entries(mappedCommands)) {\n switchCase += ` ${key}${aliases.length > 0 ? \"|\" : \"\"}${aliases.join(\"|\")})\\n`;\n switchCase += ` opts=\"${options.join(\" \")}\"\\n`;\n switchCase += \" ;;\\n\";\n }\n\n if (cliDefinition.options?.length) {\n const optionsNames = cliDefinition.options\n ? Object.keys(cliDefinition.options).map(key => transformOptionToArgument(key))\n : [];\n switchCase += ` \"-\"*)\\n`;\n switchCase += ` opts=\"${optionsNames.join(\" \")}\"\\n`;\n switchCase += \" ;;\\n\";\n }\n\n return `# Auto-generated by zod-args-parser\n\n_${cliDefinition.cliName}_autocomplete() {\n local cur prev commands opts subcommand used_opts filtered_opts\n\n cur=\"\\${COMP_WORDS[COMP_CWORD]}\"\n prev=\"\\${COMP_WORDS[COMP_CWORD-1]}\"\n subcommand=\"\\${COMP_WORDS[1]}\"\n\n commands=\"${Object.keys(mappedCommands).join(\" \")}\"\n\n case \"$subcommand\" in\n${switchCase}\n esac\n\n used_opts=\"\"\n if [[ \" \\${commands[@]} \" =~ \" $subcommand \" ]]; then\n for word in \"\\${COMP_WORDS[@]:2}\"; do\n if [[ \"$word\" =~ ^- ]]; then\n used_opts+=\" $word\"\n fi\n done\n fi\n\n if [[ -n \"$opts\" ]]; then\n filtered_opts=\"\"\n for opt in $opts; do\n if [[ ! \" $used_opts \" =~ \" $opt \" ]]; then\n filtered_opts+=\"$opt \"\n fi\n done\n COMPREPLY=( $(compgen -W \"$filtered_opts\" -- \"$cur\") )\n return\n fi\n\n if [[ \"\\${COMP_CWORD}\" -eq 1 ]]; then\n COMPREPLY=( $(compgen -W \"$commands\" -- \"$cur\") )\n fi\n}\n\ncomplete -F _${cliDefinition.cliName}_autocomplete ${cliDefinition.cliName}\n`;\n}\n"],"mappings":"8iBAAAA,iCAAA,GAAAC,SAAAD,iCAAA,CAAAE,+BAAA,IAAAA,iCAAAC,OAAAC,QAAAC,aAAAL,kCAAA,IAAAM,wBAA0CC,QAAA,iCAYnC,SAASL,+BAA+BM,GAC7C,MAAMC,EAAcD,EAAcC,aAAe,GAI3CC,EAAiC,CAAC,EAExC,UAAWC,KAAcF,EACvBC,EAAeC,EAAWC,MAAQ,CAChCC,QAASF,EAAWE,QAAUC,OAAOC,KAAKJ,EAAWE,SAASG,IAAIC,IAAA,EAAOX,wBAAAY,2BAA0BD,IAAQ,GAC3GE,QAASR,EAAWQ,SAAW,IAInC,IAAIC,EAAa,GACjB,UAAYH,GAAKJ,QAAEA,EAAAM,QAASA,MAAcL,OAAOO,QAAQX,GACvDU,GAAc,OAAOH,IAAME,EAAQG,OAAS,EAAI,IAAM,KAAKH,EAAQI,KAAK,UACxEH,GAAc,eAAeP,EAAQU,KAAK,UAC1CH,GAAc,aAGhB,GAAIZ,EAAcK,SAASS,OAAQ,CAIjCF,GAAc,cACdA,GAAc,gBAJOZ,EAAcK,QAC/BC,OAAOC,KAAKP,EAAcK,SAASG,IAAIC,IAAA,EAAOX,wBAAAY,2BAA0BD,IACxE,IAEsCM,KAAK,UAC/CH,GAAc,YAChB,CAEA,MAAO,2CAENZ,EAAcgB,6NAOHV,OAAOC,KAAKL,GAAgBa,KAAK,qCAG7CH,6lBA4BaZ,EAAcgB,wBAAwBhB,EAAcgB,WAEnE","ignoreList":[]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(e,t)=>{for(var o in t)__defProp(e,o,{get:t[o],enumerable:!0})},__copyProps=(e,t,o,r)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let n of __getOwnPropNames(t))__hasOwnProp.call(e,n)||n===o||__defProp(e,n,{get:()=>t[n],enumerable:!(r=__getOwnPropDesc(t,n))||r.enumerable});return e},__toCommonJS=e=>__copyProps(__defProp({},"__esModule",{value:!0}),e),powershell_autocomplete_script_exports={};__export(powershell_autocomplete_script_exports,{generatePowerShellAutocompleteScript:()=>generatePowerShellAutocompleteScript}),module.exports=__toCommonJS(powershell_autocomplete_script_exports);var import_parser_utilities=require("../parse/parser-utilities.cjs");function generatePowerShellAutocompleteScript(e){const t=e.subcommands??[],o=e.meta??{},r={};for(const e of t)r[e.name]={options:e.options?Object.keys(e.options).map(e=>(0,import_parser_utilities.transformOptionToArgument)(e)):[],aliases:e.aliases??[]};const n=Object.keys(r).map(e=>`'${e}'`).join(", "),a=(e.options?Object.keys(e.options).map(e=>(0,import_parser_utilities.transformOptionToArgument)(e)):[]).map(e=>`'${e}'`).join(", ");let m="switch ($subcommand) {\n";for(const[e,{options:t,aliases:o}]of Object.entries(r)){const r=t.map(e=>`'${e}'`).join(", ");m+=` '${e}' { @(${r}) }\n`;for(const e of o)m+=` '${e}' { @(${r}) }\n`}m+=` default { @(${a}) }\n }`;const s=o.description??o.descriptionMarkdown;let p="";return s&&(p=`<#\n.DESCRIPTION\n${s}\n${o.example?`\n.EXAMPLE\n${o.example}`:""}\n#>`),`# Auto-generated by zod-args-parser\n\n${p}\nfunction ${e.cliName} {\n param(\n [Parameter(Position = 0, Mandatory = $false)]\n [string]$subcommand,\n [Parameter(Position = 1, ValueFromRemainingArguments = $true)]\n [string[]]$arguments\n )\n $scriptPath = (Get-Command '${e.cliName}.ps1').Source\n if ($scriptPath) {\n $argumentList = @($subcommand) + ($arguments | Where-Object { $_ -notin '--', '--%' }) | Where-Object { $_ -ne '' }\n & $scriptPath @argumentList\n return\n }\n Write-Error "Could not find '${e.cliName}.ps1' script"\n}\n\nRegister-ArgumentCompleter -CommandName '${e.cliName}' -ParameterName 'subcommand' -ScriptBlock {\n param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)\n $subcommands = @(${n}${n&&a?", ":""}${a})\n $subcommands | Where-Object { $_ -like "$wordToComplete*" }\n}\n\nRegister-ArgumentCompleter -CommandName '${e.cliName}' -ParameterName 'arguments' -ScriptBlock {\n param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)\n $subcommand = $commandAst.CommandElements[1].Value\n $arguments = ${m}\n $arguments | Where-Object { $_ -like "$wordToComplete*" }\n}`}
|
|
2
|
-
//# sourceMappingURL=powershell-autocomplete-script.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["powershell_autocomplete_script_exports","__export","generatePowerShellAutocompleteScript","module","exports","__toCommonJS","import_parser_utilities","require","cliDefinition","subcommands","meta","mappedCommands","subcommand","name","options","Object","keys","map","key","transformOptionToArgument","aliases","subcommandsString","join","cliOptionsString","option","switchCase","entries","optionsString","a","description","descriptionMarkdown","functionInfo","example","cliName"],"sources":["../../../src/autocomplete-scripts/powershell-autocomplete-script.ts"],"sourcesContent":["import { transformOptionToArgument } from \"../parse/parser-utilities.ts\";\n\nimport type { Cli } from \"../types/definitions-types.ts\";\n\n/**\n * - Generates a PowerShell autocomplete script for your CLI.\n * - The script assumes that your CLI is available as a `.ps1` file in the environment variable. For example:\n * `cliName.ps1`.\n * - This should return a path to your script: `(Get-Command <cliName>.ps1).Source`\n * - The generated script should be added to your `profile.ps1` file:\n *\n * - Run: `notepad $profile`\n * - Add the following line: `. \"<generated script path>\"`\n * - Save and reopen powershell to take effect\n */\nexport function generatePowerShellAutocompleteScript(cliDefinition: Cli): string {\n const subcommands = cliDefinition.subcommands ?? [];\n const meta = cliDefinition.meta ?? {};\n\n type MappedCommands = Record<string, { options: string[]; aliases: string[] }>;\n\n const mappedCommands: MappedCommands = {};\n\n for (const subcommand of subcommands) {\n mappedCommands[subcommand.name] = {\n options: subcommand.options ? Object.keys(subcommand.options).map(key => transformOptionToArgument(key)) : [],\n aliases: subcommand.aliases ?? [],\n };\n }\n\n const subcommandsString = Object.keys(mappedCommands)\n .map(key => `'${key}'`)\n .join(\", \");\n\n const optionsNames = cliDefinition.options\n ? Object.keys(cliDefinition.options).map(key => transformOptionToArgument(key))\n : [];\n const cliOptionsString = optionsNames.map(option => `'${option}'`).join(\", \");\n\n let switchCase = \"switch ($subcommand) {\\n\";\n for (const [key, { options, aliases }] of Object.entries(mappedCommands)) {\n const optionsString = options.map(option => `'${option}'`).join(\", \");\n switchCase += ` '${key}' { @(${optionsString}) }\\n`;\n for (const a of aliases) {\n switchCase += ` '${a}' { @(${optionsString}) }\\n`;\n }\n }\n switchCase += ` default { @(${cliOptionsString}) }\\n }`;\n\n const description = meta.description ?? meta.descriptionMarkdown;\n\n let functionInfo = \"\";\n if (description) {\n functionInfo = `<#\\n.DESCRIPTION\\n${description}\\n${meta.example ? `\\n.EXAMPLE\\n${meta.example}` : \"\"}\\n#>`;\n }\n\n return `# Auto-generated by zod-args-parser\n\n${functionInfo}\nfunction ${cliDefinition.cliName} {\n param(\n [Parameter(Position = 0, Mandatory = $false)]\n [string]$subcommand,\n [Parameter(Position = 1, ValueFromRemainingArguments = $true)]\n [string[]]$arguments\n )\n $scriptPath = (Get-Command '${cliDefinition.cliName}.ps1').Source\n if ($scriptPath) {\n $argumentList = @($subcommand) + ($arguments | Where-Object { $_ -notin '--', '--%' }) | Where-Object { $_ -ne '' }\n & $scriptPath @argumentList\n return\n }\n Write-Error \"Could not find '${cliDefinition.cliName}.ps1' script\"\n}\n\nRegister-ArgumentCompleter -CommandName '${cliDefinition.cliName}' -ParameterName 'subcommand' -ScriptBlock {\n param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)\n $subcommands = @(${subcommandsString}${subcommandsString && cliOptionsString ? \", \" : \"\"}${cliOptionsString})\n $subcommands | Where-Object { $_ -like \"$wordToComplete*\" }\n}\n\nRegister-ArgumentCompleter -CommandName '${cliDefinition.cliName}' -ParameterName 'arguments' -ScriptBlock {\n param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)\n $subcommand = $commandAst.CommandElements[1].Value\n $arguments = ${switchCase}\n $arguments | Where-Object { $_ -like \"$wordToComplete*\" }\n}`;\n}\n"],"mappings":"8iBAAAA,uCA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
|
|
|
1
|
-
"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(e,t)=>{for(var r in t)__defProp(e,r,{get:t[r],enumerable:!0})},__copyProps=(e,t,r,o)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let s of __getOwnPropNames(t))__hasOwnProp.call(e,s)||s===r||__defProp(e,s,{get:()=>t[s],enumerable:!(o=__getOwnPropDesc(t,s))||o.enumerable});return e},__toCommonJS=e=>__copyProps(__defProp({},"__esModule",{value:!0}),e),zsh_autocomplete_script_exports={};__export(zsh_autocomplete_script_exports,{generateZshAutocompleteScript:()=>generateZshAutocompleteScript}),module.exports=__toCommonJS(zsh_autocomplete_script_exports);var import_parser_utilities=require("../parse/parser-utilities.cjs");function generateZshAutocompleteScript(e){const t=e.subcommands??[],r=e=>{return e.options?String.raw`${e.name})
|
|
2
|
-
_arguments \
|
|
3
|
-
${t=e,(t.options?Object.entries(t.options).map(([e,t])=>`'${(0,import_parser_utilities.transformOptionToArgument)(e)}[${t.meta?.description??""}]'`):[]).join(" \\\n ")} \
|
|
4
|
-
'*: :_files' \
|
|
5
|
-
&& ret=0
|
|
6
|
-
;;`:"";var t};return String.raw`# Auto-generated by zod-args-parser
|
|
7
|
-
|
|
8
|
-
_${e.cliName}_autocomplete() {
|
|
9
|
-
local ret=1
|
|
10
|
-
|
|
11
|
-
_arguments -C \
|
|
12
|
-
'1: :_${e.cliName}_commands' \
|
|
13
|
-
'*:: :->subcmds' \
|
|
14
|
-
&& ret=0
|
|
15
|
-
|
|
16
|
-
case $state in
|
|
17
|
-
subcmds)
|
|
18
|
-
case "$words[1]" in
|
|
19
|
-
${t.map(e=>r(e)).filter(Boolean).join("\n ")}
|
|
20
|
-
*)
|
|
21
|
-
_arguments \
|
|
22
|
-
'*: :_files' \
|
|
23
|
-
&& ret=0
|
|
24
|
-
;;
|
|
25
|
-
esac
|
|
26
|
-
;;
|
|
27
|
-
esac
|
|
28
|
-
|
|
29
|
-
return $ret
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
_${e.cliName}_commands() {
|
|
33
|
-
local -a commands=(
|
|
34
|
-
${t.map(e=>`"${e.name}:${e.meta?.description??""}"`).join("\n ")}
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
_describe -t subcommands 'subcommand' commands
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
compdef _${e.cliName}_autocomplete ${e.cliName}
|
|
41
|
-
`}
|
|
42
|
-
//# sourceMappingURL=zsh-autocomplete-script.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["zsh_autocomplete_script_exports","__export","generateZshAutocompleteScript","module","exports","__toCommonJS","import_parser_utilities","require","cliDefinition","subcommands","genSubCommand","subcommand","options","String","raw","name","command","Object","entries","map","value","transformOptionToArgument","meta","description","join","cliName","subCommand","filter","Boolean"],"sources":["../../../src/autocomplete-scripts/zsh-autocomplete-script.ts"],"sourcesContent":["import { transformOptionToArgument } from \"../parse/parser-utilities.ts\";\n\nimport type { Cli, Subcommand } from \"../types/definitions-types.ts\";\n\n/**\n * - Generates a ZSH autocomplete script for your CLI.\n * - The generated script should be added to your `~/.zshrc` or `~/.zsh_profile` file:\n *\n * - Run: `nano $HOME/.zshrc` or `nano $HOME/.zsh_profile`\n * - Add the following line: `source <generated script path>`\n * - Save and reopen zsh to take effect\n */\nexport function generateZshAutocompleteScript(cliDefinition: Cli): string {\n const subcommands = cliDefinition.subcommands ?? [];\n\n const genArguments = (command: Subcommand) => {\n const optionsNameDesc = command.options\n ? Object.entries(command.options).map(\n ([name, value]) => `'${transformOptionToArgument(name)}[${value.meta?.description ?? \"\"}]'`,\n )\n : [];\n\n return optionsNameDesc.join(\" \\\\\\n \");\n };\n\n const genSubCommand = (subcommand: Subcommand) => {\n const options = subcommand.options;\n if (!options) return \"\";\n return String.raw`${subcommand.name})\n _arguments \\\n ${genArguments(subcommand)} \\\n '*: :_files' \\\n && ret=0\n ;;`;\n };\n\n return String.raw`# Auto-generated by zod-args-parser\n\n_${cliDefinition.cliName}_autocomplete() {\n local ret=1\n\n _arguments -C \\\n '1: :_${cliDefinition.cliName}_commands' \\\n '*:: :->subcmds' \\\n && ret=0\n\n case $state in\n subcmds)\n case \"$words[1]\" in\n ${subcommands\n .map(subCommand => genSubCommand(subCommand))\n .filter(Boolean)\n .join(\"\\n \")}\n *)\n _arguments \\\n '*: :_files' \\\n && ret=0\n ;;\n esac\n ;;\n esac\n\n return $ret\n}\n \n_${cliDefinition.cliName}_commands() {\n local -a commands=(\n ${subcommands.map(subcommand => `\"${subcommand.name}:${subcommand.meta?.description ?? \"\"}\"`).join(\"\\n \")}\n )\n\n _describe -t subcommands 'subcommand' commands\n}\n\ncompdef _${cliDefinition.cliName}_autocomplete ${cliDefinition.cliName}\n`;\n}\n"],"mappings":"8iBAAAA,gCAAA,GAAAC,SAAAD,gCAAA,CAAAE,8BAAA,IAAAA,gCAAAC,OAAAC,QAAAC,aAAAL,iCAAA,IAAAM,wBAA0CC,QAAA,iCAYnC,SAASL,8BAA8BM,GAC5C,MAAMC,EAAcD,EAAcC,aAAe,GAY3CC,EAAiBC,IAErB,OADgBA,EAAWC,QAEpBC,OAAOC,GAAA,GAAMH,EAAWI;;cAbXC,EAeGL,GAdCK,EAAQJ,QAC5BK,OAAOC,QAAQF,EAAQJ,SAASO,IAC9B,EAAEJ,EAAMK,KAAW,OAAId,wBAAAe,2BAA0BN,MAASK,EAAME,MAAMC,aAAe,QAEvF,IAEmBC,KAAK;;;cAKP,GAZF,IAACR,GAqBtB,OAAOH,OAAOC,GAAA;;GAEbN,EAAciB;;;;YAILjB,EAAciB;;;;;;;UAOhBhB,EACCU,IAAIO,GAAchB,EAAcgB,IAChCC,OAAOC,SACPJ,KAAK;;;;;;;;;;;;;GAabhB,EAAciB;;MAEXhB,EAAYU,IAAIR,GAAc,IAAIA,EAAWI,QAAQJ,EAAWW,MAAMC,aAAe,OAAOC,KAAK;;;;;;WAM5FhB,EAAciB,wBAAwBjB,EAAciB;CAE/D","ignoreList":[]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(r,e)=>{for(var t in e)__defProp(r,t,{get:e[t],enumerable:!0})},__copyProps=(r,e,t,o)=>{if(e&&"object"==typeof e||"function"==typeof e)for(let n of __getOwnPropNames(e))__hasOwnProp.call(r,n)||n===t||__defProp(r,n,{get:()=>e[n],enumerable:!(o=__getOwnPropDesc(e,n))||o.enumerable});return r},__toCommonJS=r=>__copyProps(__defProp({},"__esModule",{value:!0}),r),coerce_methods_exports={};__export(coerce_methods_exports,{coerce:()=>coerce}),module.exports=__toCommonJS(coerce_methods_exports);var import_string_to_array=require("./string-to-array.cjs"),import_string_to_primitive=require("./string-to-primitive.cjs"),import_string_to_set=require("./string-to-set.cjs"),string=r=>r;string.type="string";var boolean=r=>(0,import_string_to_primitive.stringToBoolean)(r);boolean.type="boolean";var number=r=>(0,import_string_to_primitive.stringToNumber)(r);number.type="number";var json=r=>{const e=e=>JSON.parse(e,r);return e.type="unknown",e},stringArray=r=>{const e=e=>(0,import_string_to_array.stringToStringArray)(e,r);return e.type="string[]",e},numberArray=r=>{const e=e=>(0,import_string_to_array.stringToNumberArray)(e,r);return e.type="number[]",e},booleanArray=r=>{const e=e=>(0,import_string_to_array.stringToBooleanArray)(e,r);return e.type="boolean[]",e},stringSet=r=>{const e=e=>(0,import_string_to_set.stringToStringSet)(e,r);return e.type="set<string>",e},numberSet=r=>{const e=e=>(0,import_string_to_set.stringToNumberSet)(e,r);return e.type="set<number>",e},booleanSet=r=>{const e=e=>(0,import_string_to_set.stringToBooleanSet)(e,r);return e.type="set<boolean>",e},coerce={string:string,boolean:boolean,number:number,stringArray:stringArray,numberArray:numberArray,booleanArray:booleanArray,stringSet:stringSet,numberSet:numberSet,booleanSet:booleanSet,json:json};
|
|
2
|
-
//# sourceMappingURL=coerce-methods.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["coerce_methods_exports","__export","coerce","module","exports","__toCommonJS","import_string_to_array","require","import_string_to_primitive","import_string_to_set","string","terminalInput","type","boolean","stringToBoolean","number","stringToNumber","json","reviver","coerceMethod","JSON","parse","stringArray","separator","stringToStringArray","numberArray","stringToNumberArray","booleanArray","stringToBooleanArray","stringSet","stringToStringSet","numberSet","stringToNumberSet","booleanSet","stringToBooleanSet"],"sources":["../../../src/coerce/coerce-methods.ts"],"sourcesContent":["import { stringToBooleanArray, stringToNumberArray, stringToStringArray } from \"./string-to-array.ts\";\nimport { stringToBoolean, stringToNumber } from \"./string-to-primitive.ts\";\nimport { stringToBooleanSet, stringToNumberSet, stringToStringSet } from \"./string-to-set.ts\";\n\nimport type { CoerceMethod } from \"../types/types.ts\";\n\nconst string: CoerceMethod<string> = terminalInput => terminalInput;\nstring.type = \"string\";\n\nconst boolean: CoerceMethod<boolean> = terminalInput => stringToBoolean(terminalInput);\nboolean.type = \"boolean\";\n\nconst number: CoerceMethod<number> = terminalInput => stringToNumber(terminalInput);\nnumber.type = \"number\";\n\nconst json = <T>(reviver?: (this: any, key: string, value: any) => any): CoerceMethod<T> => {\n const coerceMethod: CoerceMethod<T> = terminalInput => JSON.parse(terminalInput, reviver) as T;\n coerceMethod.type = \"unknown\";\n return coerceMethod;\n};\n\nconst stringArray = (separator: string): CoerceMethod<string[]> => {\n const coerceMethod: CoerceMethod<string[]> = terminalInput => stringToStringArray(terminalInput, separator);\n coerceMethod.type = \"string[]\";\n return coerceMethod;\n};\n\nconst numberArray = (separator: string) => {\n const coerceMethod: CoerceMethod<number[]> = terminalInput => stringToNumberArray(terminalInput, separator);\n coerceMethod.type = \"number[]\";\n return coerceMethod;\n};\n\nconst booleanArray = (separator: string) => {\n const coerceMethod: CoerceMethod<boolean[]> = terminalInput => stringToBooleanArray(terminalInput, separator);\n coerceMethod.type = \"boolean[]\";\n return coerceMethod;\n};\n\nconst stringSet = (separator: string) => {\n const coerceMethod: CoerceMethod<Set<string>> = terminalInput => stringToStringSet(terminalInput, separator);\n coerceMethod.type = \"set<string>\";\n return coerceMethod;\n};\n\nconst numberSet = (separator: string) => {\n const coerceMethod: CoerceMethod<Set<number>> = terminalInput => stringToNumberSet(terminalInput, separator);\n coerceMethod.type = \"set<number>\";\n return coerceMethod;\n};\n\nconst booleanSet = (separator: string) => {\n const coerceMethod: CoerceMethod<Set<boolean>> = terminalInput => stringToBooleanSet(terminalInput, separator);\n coerceMethod.type = \"set<boolean>\";\n return coerceMethod;\n};\n\nexport const coerce = {\n string,\n boolean,\n number,\n /** @param separator - The separator to use to split the string. **Default** is `\",\"` */\n stringArray,\n /** @param separator - The separator to use to split the string. **Default** is `\",\"` */\n numberArray,\n /** @param separator - The separator to use to split the string. **Default** is `\",\"` */\n booleanArray,\n /** @param separator - The separator to use to split the string. **Default** is `\",\"` */\n stringSet,\n /** @param separator - The separator to use to split the string. **Default** is `\",\"` */\n numberSet,\n /** @param separator - The separator to use to split the string. **Default** is `\",\"` */\n booleanSet,\n json,\n};\n"],"mappings":"8iBAAAA,uBAAA,GAAAC,SAAAD,uBAAA,CAAAE,OAAA,IAAAA,SAAAC,OAAAC,QAAAC,aAAAL,wBAAA,IAAAM,uBAA+EC,QAAA,yBAC/EC,2BAAgDD,QAAA,6BAChDE,qBAAyEF,QAAA,uBAInEG,OAA+BC,GAAiBA,EACtDD,OAAOE,KAAO,SAEd,IAAMC,QAAiCF,IAAA,EAAiBH,2BAAAM,iBAAgBH,GACxEE,QAAQD,KAAO,UAEf,IAAMG,OAA+BJ,IAAA,EAAiBH,2BAAAQ,gBAAeL,GACrEI,OAAOH,KAAO,SAEd,IAAMK,KAAWC,IACf,MAAMC,EAAgCR,GAAiBS,KAAKC,MAAMV,EAAeO,GAEjF,OADAC,EAAaP,KAAO,UACbO,GAGHG,YAAeC,IACnB,MAAMJ,EAAuCR,IAAA,EAAiBL,uBAAAkB,qBAAoBb,EAAeY,GAEjG,OADAJ,EAAaP,KAAO,WACbO,GAGHM,YAAeF,IACnB,MAAMJ,EAAuCR,IAAA,EAAiBL,uBAAAoB,qBAAoBf,EAAeY,GAEjG,OADAJ,EAAaP,KAAO,WACbO,GAGHQ,aAAgBJ,IACpB,MAAMJ,EAAwCR,IAAA,EAAiBL,uBAAAsB,sBAAqBjB,EAAeY,GAEnG,OADAJ,EAAaP,KAAO,YACbO,GAGHU,UAAaN,IACjB,MAAMJ,EAA0CR,IAAA,EAAiBF,qBAAAqB,mBAAkBnB,EAAeY,GAElG,OADAJ,EAAaP,KAAO,cACbO,GAGHY,UAAaR,IACjB,MAAMJ,EAA0CR,IAAA,EAAiBF,qBAAAuB,mBAAkBrB,EAAeY,GAElG,OADAJ,EAAaP,KAAO,cACbO,GAGHc,WAAcV,IAClB,MAAMJ,EAA2CR,IAAA,EAAiBF,qBAAAyB,oBAAmBvB,EAAeY,GAEpG,OADAJ,EAAaP,KAAO,eACbO,GAGIjB,OAAS,CACpBQ,cACAG,gBACAE,cAEAO,wBAEAG,wBAEAE,0BAEAE,oBAEAE,oBAEAE,sBACAhB","ignoreList":[]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(r,t)=>{for(var o in t)__defProp(r,o,{get:t[o],enumerable:!0})},__copyProps=(r,t,o,e)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let n of __getOwnPropNames(t))__hasOwnProp.call(r,n)||n===o||__defProp(r,n,{get:()=>t[n],enumerable:!(e=__getOwnPropDesc(t,n))||e.enumerable});return r},__toCommonJS=r=>__copyProps(__defProp({},"__esModule",{value:!0}),r),string_to_array_exports={};__export(string_to_array_exports,{stringToBooleanArray:()=>stringToBooleanArray,stringToNumberArray:()=>stringToNumberArray,stringToStringArray:()=>stringToStringArray}),module.exports=__toCommonJS(string_to_array_exports);var import_string_to_primitive=require("./string-to-primitive.cjs");function stringToStringArray(r,t=","){return r.split(t).map(r=>r.trim()).filter(Boolean)}function stringToNumberArray(r,t=","){return stringToStringArray(r,t).map(r=>(0,import_string_to_primitive.stringToNumber)(r))}function stringToBooleanArray(r,t=","){return stringToStringArray(r,t).map(r=>(0,import_string_to_primitive.stringToBoolean)(r))}
|
|
2
|
-
//# sourceMappingURL=string-to-array.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["string_to_array_exports","__export","stringToBooleanArray","stringToNumberArray","stringToStringArray","module","exports","__toCommonJS","import_string_to_primitive","require","stringValue","separator","split","map","s","trim","filter","Boolean","element","stringToNumber","stringToBoolean"],"sources":["../../../src/coerce/string-to-array.ts"],"sourcesContent":["import { stringToBoolean, stringToNumber } from \"./string-to-primitive.ts\";\n\nexport function stringToStringArray(stringValue: string, separator: string = \",\"): string[] {\n return stringValue\n .split(separator)\n .map(s => s.trim())\n .filter(Boolean);\n}\n\n/** @throws {TypeError} - Because of `stringToNumber` */\nexport function stringToNumberArray(stringValue: string, separator: string = \",\"): number[] {\n return stringToStringArray(stringValue, separator).map(element => stringToNumber(element));\n}\n\n/** @throws {TypeError} - Because of `stringToBoolean` */\nexport function stringToBooleanArray(stringValue: string, separator: string = \",\"): boolean[] {\n return stringToStringArray(stringValue, separator).map(element => stringToBoolean(element));\n}\n"],"mappings":"8iBAAAA,wBAAA,GAAAC,SAAAD,wBAAA,CAAAE,qBAAA,IAAAA,qBAAAC,oBAAA,IAAAA,oBAAAC,oBAAA,IAAAA,sBAAAC,OAAAC,QAAAC,aAAAP,yBAAA,IAAAQ,2BAAgDC,QAAA,6BAEzC,SAASL,oBAAoBM,EAAqBC,EAAoB,KAC3E,OAAOD,EACJE,MAAMD,GACNE,IAAIC,GAAKA,EAAEC,QACXC,OAAOC,QACZ,CAGO,SAASd,oBAAoBO,EAAqBC,EAAoB,KAC3E,OAAOP,oBAAoBM,EAAaC,GAAWE,IAAIK,IAAA,EAAWV,2BAAAW,gBAAeD,GACnF,CAGO,SAAShB,qBAAqBQ,EAAqBC,EAAoB,KAC5E,OAAOP,oBAAoBM,EAAaC,GAAWE,IAAIK,IAAA,EAAWV,2BAAAY,iBAAgBF,GACpF","ignoreList":[]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(e,r)=>{for(var o in r)__defProp(e,o,{get:r[o],enumerable:!0})},__copyProps=(e,r,o,t)=>{if(r&&"object"==typeof r||"function"==typeof r)for(let n of __getOwnPropNames(r))__hasOwnProp.call(e,n)||n===o||__defProp(e,n,{get:()=>r[n],enumerable:!(t=__getOwnPropDesc(r,n))||t.enumerable});return e},__toCommonJS=e=>__copyProps(__defProp({},"__esModule",{value:!0}),e),string_to_primitive_exports={};function stringToBoolean(e){if("true"===e.toLowerCase())return!0;if("false"===e.toLowerCase())return!1;throw new TypeError(`Invalid boolean value: ${e}`)}function stringToNumber(e){const r=e.trim();if(""===r||"+"===r||"-"===r)throw new TypeError(`Invalid number: "${e}"`);const o=Number(r);if(!Number.isFinite(o))throw new TypeError(`Invalid number: "${e}"`);return o}__export(string_to_primitive_exports,{stringToBoolean:()=>stringToBoolean,stringToNumber:()=>stringToNumber}),module.exports=__toCommonJS(string_to_primitive_exports);
|
|
2
|
-
//# sourceMappingURL=string-to-primitive.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["string_to_primitive_exports","stringToBoolean","string","toLowerCase","TypeError","stringToNumber","trimmed","trim","result","Number","isFinite","__export","module","exports","__toCommonJS"],"sources":["../../../src/coerce/string-to-primitive.ts"],"sourcesContent":["/** @throws {TypeError} */\nexport function stringToBoolean(string: string): boolean {\n if (string.toLowerCase() === \"true\") {\n return true;\n }\n\n if (string.toLowerCase() === \"false\") {\n return false;\n }\n\n throw new TypeError(`Invalid boolean value: ${string}`);\n}\n\n/** @throws {TypeError} */\nexport function stringToNumber(string: string): number {\n const trimmed = string.trim();\n\n // Reject empty, whitespace-only, or signs without digits\n if (trimmed === \"\" || trimmed === \"+\" || trimmed === \"-\") {\n throw new TypeError(`Invalid number: \"${string}\"`);\n }\n\n const result = Number(trimmed);\n\n // Reject NaN, Infinity, and -Infinity\n if (!Number.isFinite(result)) {\n throw new TypeError(`Invalid number: \"${string}\"`);\n }\n\n return result;\n}\n"],"mappings":"8iBAAAA,4BAAA,GACO,SAASC,gBAAgBC,GAC9B,GAA6B,SAAzBA,EAAOC,cACT,OAAO,EAGT,GAA6B,UAAzBD,EAAOC,cACT,OAAO,EAGT,MAAM,IAAIC,UAAU,0BAA0BF,IAChD,CAGO,SAASG,eAAeH,GAC7B,MAAMI,EAAUJ,EAAOK,OAGvB,GAAgB,KAAZD,GAA8B,MAAZA,GAA+B,MAAZA,EACvC,MAAM,IAAIF,UAAU,oBAAoBF,MAG1C,MAAMM,EAASC,OAAOH,GAGtB,IAAKG,OAAOC,SAASF,GACnB,MAAM,IAAIJ,UAAU,oBAAoBF,MAG1C,OAAOM,CACT,CA9BAG,SAAAX,4BAAA,CAAAC,gBAAA,IAAAA,gBAAAI,eAAA,IAAAA,iBAAAO,OAAAC,QAAAC,aAAAd","ignoreList":[]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(r,t)=>{for(var e in t)__defProp(r,e,{get:t[e],enumerable:!0})},__copyProps=(r,t,e,o)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let n of __getOwnPropNames(t))__hasOwnProp.call(r,n)||n===e||__defProp(r,n,{get:()=>t[n],enumerable:!(o=__getOwnPropDesc(t,n))||o.enumerable});return r},__toCommonJS=r=>__copyProps(__defProp({},"__esModule",{value:!0}),r),string_to_set_exports={};__export(string_to_set_exports,{stringToBooleanSet:()=>stringToBooleanSet,stringToNumberSet:()=>stringToNumberSet,stringToStringSet:()=>stringToStringSet}),module.exports=__toCommonJS(string_to_set_exports);var import_string_to_array=require("./string-to-array.cjs");function stringToStringSet(r,t=","){return new Set((0,import_string_to_array.stringToStringArray)(r,t))}function stringToNumberSet(r,t=","){return new Set((0,import_string_to_array.stringToNumberArray)(r,t))}function stringToBooleanSet(r,t=","){return new Set((0,import_string_to_array.stringToBooleanArray)(r,t))}
|
|
2
|
-
//# sourceMappingURL=string-to-set.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["string_to_set_exports","__export","stringToBooleanSet","stringToNumberSet","stringToStringSet","module","exports","__toCommonJS","import_string_to_array","require","stringValue","separator","Set","stringToStringArray","stringToNumberArray","stringToBooleanArray"],"sources":["../../../src/coerce/string-to-set.ts"],"sourcesContent":["import { stringToBooleanArray, stringToNumberArray, stringToStringArray } from \"./string-to-array.ts\";\n\nexport function stringToStringSet(stringValue: string, separator: string = \",\"): Set<string> {\n return new Set(stringToStringArray(stringValue, separator));\n}\n\n/** @throws {TypeError} - Because of `stringToNumber` */\nexport function stringToNumberSet(stringValue: string, separator: string = \",\"): Set<number> {\n return new Set(stringToNumberArray(stringValue, separator));\n}\n\n/** @throws {TypeError} - Because of `stringToBoolean` */\nexport function stringToBooleanSet(stringValue: string, separator: string = \",\"): Set<boolean> {\n return new Set(stringToBooleanArray(stringValue, separator));\n}\n"],"mappings":"8iBAAAA,sBAAA,GAAAC,SAAAD,sBAAA,CAAAE,mBAAA,IAAAA,mBAAAC,kBAAA,IAAAA,kBAAAC,kBAAA,IAAAA,oBAAAC,OAAAC,QAAAC,aAAAP,uBAAA,IAAAQ,uBAA+EC,QAAA,yBAExE,SAASL,kBAAkBM,EAAqBC,EAAoB,KACzE,OAAO,IAAIC,KAAA,EAAIJ,uBAAAK,qBAAoBH,EAAaC,GAClD,CAGO,SAASR,kBAAkBO,EAAqBC,EAAoB,KACzE,OAAO,IAAIC,KAAA,EAAIJ,uBAAAM,qBAAoBJ,EAAaC,GAClD,CAGO,SAAST,mBAAmBQ,EAAqBC,EAAoB,KAC1E,OAAO,IAAIC,KAAA,EAAIJ,uBAAAO,sBAAqBL,EAAaC,GACnD","ignoreList":[]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(e,r)=>{for(var t in r)__defProp(e,t,{get:r[t],enumerable:!0})},__copyProps=(e,r,t,o)=>{if(r&&"object"==typeof r||"function"==typeof r)for(let _ of __getOwnPropNames(r))__hasOwnProp.call(e,_)||_===t||__defProp(e,_,{get:()=>r[_],enumerable:!(o=__getOwnPropDesc(r,_))||o.enumerable});return e},__toCommonJS=e=>__copyProps(__defProp({},"__esModule",{value:!0}),e),define_arguments_exports={};__export(define_arguments_exports,{defineArguments:()=>defineArguments}),module.exports=__toCommonJS(define_arguments_exports);var import_utilities=require("../utilities.cjs");function defineArguments(e){return(0,import_utilities.prepareDefinitionTypes)(e),e}
|
|
2
|
-
//# sourceMappingURL=define-arguments.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["define_arguments_exports","__export","defineArguments","module","exports","__toCommonJS","import_utilities","require","arguments_","prepareDefinitionTypes"],"sources":["../../../src/definitions/define-arguments.ts"],"sourcesContent":["import { prepareDefinitionTypes } from \"../utilities.ts\";\n\nimport type { Argument } from \"../types/definitions-types.ts\";\n\nexport function defineArguments<const T extends Record<string, Argument>>(arguments_: {\n [K in keyof T]: T[K] & Argument<T[K][\"schema\"]>;\n}): { [K in keyof T]: Argument<T[K][\"schema\"]> } {\n prepareDefinitionTypes(arguments_);\n return arguments_;\n}\n"],"mappings":"8iBAAAA,yBAAA,GAAAC,SAAAD,yBAAA,CAAAE,gBAAA,IAAAA,kBAAAC,OAAAC,QAAAC,aAAAL,0BAAA,IAAAM,iBAAuCC,QAAA,oBAIhC,SAASL,gBAA0DM,GAIxE,OADA,EAAAF,iBAAAG,wBAAuBD,GAChBA,CACT","ignoreList":[]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(e,t)=>{for(var o in t)__defProp(e,o,{get:t[o],enumerable:!0})},__copyProps=(e,t,o,r)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let n of __getOwnPropNames(t))__hasOwnProp.call(e,n)||n===o||__defProp(e,n,{get:()=>t[n],enumerable:!(r=__getOwnPropDesc(t,n))||r.enumerable});return e},__toCommonJS=e=>__copyProps(__defProp({},"__esModule",{value:!0}),e),define_cli_exports={};__export(define_cli_exports,{defineCLI:()=>defineCLI}),module.exports=__toCommonJS(define_cli_exports);var import_generate_for_cli=require("../help-message/generate-for-cli.cjs"),import_generate_for_subcommand=require("../help-message/generate-for-subcommand.cjs"),import_object_context_builder=require("../parse/context/object-context-builder.cjs"),import_safe_parse=require("../parse/safe-parse.cjs"),import_validate_context=require("../parse/validation/validate-context.cjs"),import_utilities=require("../utilities.cjs");function defineCLI(e){const t=e;if((0,import_utilities.prepareDefinitionTypes)(t.options),(0,import_utilities.prepareDefinitionTypes)(t.arguments),t.subcommands)for(const e of Object.values(t.subcommands))(0,import_utilities.prepareDefinitionTypes)(e.options),(0,import_utilities.prepareDefinitionTypes)(e.arguments);const o={generateCliHelpMessage:e=>(0,import_generate_for_cli.generateCliHelpMessage)(t,e),generateSubcommandHelpMessage(e,o){const r=t.subcommands?.find(t=>t.name===e);if(!r)throw new Error(`Subcommand ${e} not found`);return(0,import_generate_for_subcommand.generateSubcommandHelpMessage)(r,o,t.cliName)}};if(Object.assign(t,o),t.subcommands)for(const e of t.subcommands)Object.assign(e,o);return Object.assign(t,{execute:e=>{if(e??(e={}),!t._onExecute)throw new Error("Action is not defined");const o=(0,import_object_context_builder.buildObjectContext)(e,t),r=(0,import_validate_context.validate)(o,t);if(t._onExecute)for(const e of t._onExecute)e(r)},onExecute:e=>(t._onExecute??(t._onExecute=[]),t._onExecute.push(e),()=>{const o=t._onExecute?.indexOf(e);!o||o<0||t._onExecute?.splice(o,1)}),run:e=>(0,import_safe_parse.safeParse)(e,t),runAsync:e=>(0,import_safe_parse.safeParseAsync)(e,t)})}
|
|
2
|
-
//# sourceMappingURL=define-cli.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["define_cli_exports","__export","defineCLI","module","exports","__toCommonJS","import_generate_for_cli","require","import_generate_for_subcommand","import_object_context_builder","import_safe_parse","import_validate_context","import_utilities","input","cliSchema","prepareDefinitionTypes","options","arguments","subcommands","subcommand","Object","values","generateHelpMethods","generateCliHelpMessage","generateSubcommandHelpMessage","subcommandName","foundSubcommand","find","s","name","Error","cliName","assign","subcommandSchema","execute","inputValues","_onExecute","context","buildObjectContext","validateResult","validate","handler","onExecute","push","handlerIndex","indexOf","splice","run","stringOrArgv","safeParse","runAsync","safeParseAsync"],"sources":["../../../src/definitions/define-cli.ts"],"sourcesContent":["import { generateCliHelpMessage } from \"../help-message/generate-for-cli.ts\";\nimport { generateSubcommandHelpMessage } from \"../help-message/generate-for-subcommand.ts\";\nimport { buildObjectContext } from \"../parse/context/object-context-builder.ts\";\nimport { safeParse, safeParseAsync } from \"../parse/safe-parse.ts\";\nimport { validate } from \"../parse/validation/validate-context.ts\";\nimport { prepareDefinitionTypes } from \"../utilities.ts\";\n\nimport type { Argument, Cli, Option, Subcommand } from \"../types/definitions-types.ts\";\nimport type { PrintHelpOptions } from \"../types/help-message-types.ts\";\nimport type { AttachedMethods, AttachedMethodsWide, ValidateMethods } from \"../types/types.ts\";\nimport type { Prettify } from \"../types/utilities-types.ts\";\n\ntype OptionsInput<T> =\n T extends Record<string, Option> ? { [OptionName in keyof T]: Option<T[OptionName][\"schema\"]> } : T;\n\ntype ArgumentsInput<T> =\n T extends Record<string, Argument> ? { [ArgumentName in keyof T]: Argument<T[ArgumentName][\"schema\"]> } : T;\n\ntype SubcommandsInput<T extends readonly [Subcommand, ...Subcommand[]]> = {\n [SubcommandIndex in keyof T]: {\n [K in keyof T[SubcommandIndex]]: T[SubcommandIndex][K] extends Record<string, Option>\n ? OptionsInput<T[SubcommandIndex][K]>\n : T[SubcommandIndex][K] extends Record<string, Argument>\n ? ArgumentsInput<T[SubcommandIndex][K]>\n : T[SubcommandIndex][K];\n } & Subcommand;\n};\n\n// This will prevent extra keys and enable jsdoc on hover\ntype CliInput<T extends Cli> = {\n [K in keyof T]: K extends keyof Cli\n ? T[K] extends readonly [Subcommand, ...Subcommand[]]\n ? SubcommandsInput<T[K]>\n : K extends \"options\"\n ? OptionsInput<T[K]>\n : K extends \"arguments\"\n ? ArgumentsInput<T[K]>\n : T[K]\n : never;\n};\n\nexport function defineCLI<T extends Cli>(input: CliInput<T> & Cli) {\n const cliSchema = input as Prettify<T & AttachedMethods<T> & ValidateMethods<T>>;\n\n prepareDefinitionTypes(cliSchema.options);\n prepareDefinitionTypes(cliSchema.arguments);\n\n if (cliSchema.subcommands) {\n for (const subcommand of Object.values(cliSchema.subcommands)) {\n prepareDefinitionTypes(subcommand.options);\n prepareDefinitionTypes(subcommand.arguments);\n }\n }\n\n const onExecute = (handler: (Cli[\"_onExecute\"] & {})[number]) => {\n cliSchema._onExecute ??= [];\n cliSchema._onExecute.push(handler);\n\n return () => {\n const handlerIndex = cliSchema._onExecute?.indexOf(handler);\n if (!handlerIndex || handlerIndex < 0) return;\n cliSchema._onExecute?.splice(handlerIndex, 1);\n };\n };\n\n const execute: AttachedMethodsWide[\"execute\"] = inputValues => {\n inputValues ??= {};\n if (!cliSchema._onExecute) throw new Error(\"Action is not defined\");\n const context = buildObjectContext(inputValues, cliSchema);\n const validateResult = validate(context, cliSchema);\n\n if (cliSchema._onExecute) {\n for (const handler of cliSchema._onExecute) {\n handler(validateResult);\n }\n }\n };\n\n // Add print methods for CLI schema and its subcommands\n const generateHelpMethods: Pick<AttachedMethodsWide, \"generateCliHelpMessage\" | \"generateSubcommandHelpMessage\"> = {\n generateCliHelpMessage(options?: PrintHelpOptions) {\n return generateCliHelpMessage(cliSchema, options);\n },\n generateSubcommandHelpMessage(subcommandName: string, options?: PrintHelpOptions) {\n const foundSubcommand = cliSchema.subcommands?.find(s => s.name === subcommandName);\n if (!foundSubcommand) throw new Error(`Subcommand ${subcommandName} not found`);\n return generateSubcommandHelpMessage(foundSubcommand, options, cliSchema.cliName);\n },\n };\n\n Object.assign(cliSchema, generateHelpMethods);\n\n if (cliSchema.subcommands) {\n for (const subcommandSchema of cliSchema.subcommands) {\n Object.assign(subcommandSchema, generateHelpMethods);\n }\n }\n\n return Object.assign(cliSchema, {\n execute,\n onExecute,\n run: (stringOrArgv: string | string[]) => safeParse(stringOrArgv, cliSchema),\n runAsync: (stringOrArgv: string | string[]) => safeParseAsync(stringOrArgv, cliSchema),\n });\n}\n"],"mappings":"8iBAAAA,mBAAA,GAAAC,SAAAD,mBAAA,CAAAE,UAAA,IAAAA,YAAAC,OAAAC,QAAAC,aAAAL,oBAAA,IAAAM,wBAAuCC,QAAA,wCACvCC,+BAA8CD,QAAA,+CAC9CE,8BAAmCF,QAAA,+CACnCG,kBAA0CH,QAAA,2BAC1CI,wBAAyBJ,QAAA,4CACzBK,iBAAuCL,QAAA,oBAoChC,SAASL,UAAyBW,GACvC,MAAMC,EAAYD,EAKlB,IAHA,EAAAD,iBAAAG,wBAAuBD,EAAUE,UACjC,EAAAJ,iBAAAG,wBAAuBD,EAAUG,WAE7BH,EAAUI,YACZ,UAAWC,KAA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OwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(e,o)=>{for(var t in o)__defProp(e,t,{get:o[t],enumerable:!0})},__copyProps=(e,o,t,r)=>{if(o&&"object"==typeof o||"function"==typeof o)for(let _ of __getOwnPropNames(o))__hasOwnProp.call(e,_)||_===t||__defProp(e,_,{get:()=>o[_],enumerable:!(r=__getOwnPropDesc(o,_))||r.enumerable});return e},__toCommonJS=e=>__copyProps(__defProp({},"__esModule",{value:!0}),e),define_options_exports={};__export(define_options_exports,{defineOptions:()=>defineOptions}),module.exports=__toCommonJS(define_options_exports);var import_utilities=require("../utilities.cjs");function defineOptions(e){return(0,import_utilities.prepareDefinitionTypes)(e),e}
|
|
2
|
-
//# sourceMappingURL=define-options.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["define_options_exports","__export","defineOptions","module","exports","__toCommonJS","import_utilities","require","options","prepareDefinitionTypes"],"sources":["../../../src/definitions/define-options.ts"],"sourcesContent":["import { prepareDefinitionTypes } from \"../utilities.ts\";\n\nimport type { Option } from \"../types/definitions-types.ts\";\n\nexport function defineOptions<T extends Record<string, Option>>(options: {\n [K in keyof T]: T[K] & Option<T[K][\"schema\"]>;\n}): {\n [K in keyof T]: Option<T[K][\"schema\"]>;\n} {\n prepareDefinitionTypes(options);\n return options;\n}\n"],"mappings":"8iBAAAA,uBAAA,GAAAC,SAAAD,uBAAA,CAAAE,cAAA,IAAAA,gBAAAC,OAAAC,QAAAC,aAAAL,wBAAA,IAAAM,iBAAuCC,QAAA,oBAIhC,SAASL,cAAgDM,GAM9D,OADA,EAAAF,iBAAAG,wBAAuBD,GAChBA,CACT","ignoreList":[]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(e,t)=>{for(var o in t)__defProp(e,o,{get:t[o],enumerable:!0})},__copyProps=(e,t,o,r)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let n of __getOwnPropNames(t))__hasOwnProp.call(e,n)||n===o||__defProp(e,n,{get:()=>t[n],enumerable:!(r=__getOwnPropDesc(t,n))||r.enumerable});return e},__toCommonJS=e=>__copyProps(__defProp({},"__esModule",{value:!0}),e),define_subcommand_exports={};__export(define_subcommand_exports,{defineSubcommand:()=>defineSubcommand}),module.exports=__toCommonJS(define_subcommand_exports);var import_object_context_builder=require("../parse/context/object-context-builder.cjs"),import_validate_context=require("../parse/validation/validate-context.cjs"),import_utilities=require("../utilities.cjs");function defineSubcommand(e){const t=e;(0,import_utilities.prepareDefinitionTypes)(t.options),(0,import_utilities.prepareDefinitionTypes)(t.arguments);return Object.assign(t,{onExecute:e=>(t._onExecute??(t._onExecute=[]),t._onExecute.push(e),()=>{const o=t._onExecute?.indexOf(e);!o||o<0||t._onExecute?.splice(o,1)}),execute:e=>{if(e??(e={}),!t._onExecute)throw new Error("Action is not defined");const o=(0,import_object_context_builder.buildObjectContext)(e,t),r=(0,import_validate_context.validate)(o,t);if(t._onExecute)for(const e of t._onExecute)e(r)}})}
|
|
2
|
-
//# sourceMappingURL=define-subcommand.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["define_subcommand_exports","__export","defineSubcommand","module","exports","__toCommonJS","import_object_context_builder","require","import_validate_context","import_utilities","input","subcommandSchema","prepareDefinitionTypes","options","arguments","Object","assign","onExecute","handler","_onExecute","push","handlerIndex","indexOf","splice","execute","inputValues","Error","context","buildObjectContext","validateResult","validate"],"sources":["../../../src/definitions/define-subcommand.ts"],"sourcesContent":["import { buildObjectContext } from \"../parse/context/object-context-builder.ts\";\nimport { validate } from \"../parse/validation/validate-context.ts\";\nimport { prepareDefinitionTypes } from \"../utilities.ts\";\n\nimport type { Argument, Option, Subcommand } from \"../types/definitions-types.ts\";\nimport type { AttachedMethods, AttachedMethodsWide } from \"../types/types.ts\";\nimport type { Prettify } from \"../types/utilities-types.ts\";\n\ntype OptionsInput<T> =\n T extends Record<string, Option> ? { [OptionName in keyof T]: Option<T[OptionName][\"schema\"]> } : T;\n\ntype ArgumentsInput<T> =\n T extends Record<string, Argument> ? { [ArgumentName in keyof T]: Argument<T[ArgumentName][\"schema\"]> } : T;\n\n// This will prevent extra keys and enable jsdoc on hover\ntype SubcommandInput<T extends Subcommand> = {\n [K in keyof T]: K extends keyof Subcommand\n ? K extends \"options\"\n ? OptionsInput<T[K]>\n : K extends \"arguments\"\n ? ArgumentsInput<T[K]>\n : T[K]\n : never;\n};\n\nexport function defineSubcommand<T extends Subcommand>(input: SubcommandInput<T> & Subcommand) {\n const subcommandSchema = input as Prettify<T & AttachedMethods<T>>;\n\n prepareDefinitionTypes(subcommandSchema.options);\n prepareDefinitionTypes(subcommandSchema.arguments);\n\n const onExecute = (handler: (Subcommand[\"_onExecute\"] & {})[number]) => {\n subcommandSchema._onExecute ??= [];\n subcommandSchema._onExecute.push(handler);\n\n return () => {\n const handlerIndex = subcommandSchema._onExecute?.indexOf(handler);\n if (!handlerIndex || handlerIndex < 0) return;\n subcommandSchema._onExecute?.splice(handlerIndex, 1);\n };\n };\n\n const execute: AttachedMethodsWide[\"execute\"] = inputValues => {\n inputValues ??= {};\n if (!subcommandSchema._onExecute) throw new Error(\"Action is not defined\");\n const context = buildObjectContext(inputValues, subcommandSchema);\n const validateResult = validate(context, subcommandSchema);\n\n if (subcommandSchema._onExecute) {\n for (const handler of subcommandSchema._onExecute) {\n handler(validateResult);\n }\n }\n };\n\n return Object.assign(subcommandSchema, { onExecute, execute });\n}\n"],"mappings":"8iBAAAA,0BAAA,GAAAC,SAAAD,0BAAA,CAAAE,iBAAA,IAAAA,mBAAAC,OAAAC,QAAAC,aAAAL,2BAAA,IAAAM,8BAAmCC,QAAA,+CACnCC,wBAAyBD,QAAA,4CACzBE,iBAAuCF,QAAA,oBAuBhC,SAASL,iBAAuCQ,GACrD,MAAMC,EAAmBD,GAEzB,EAAAD,iBAAAG,wBAAuBD,EAAiBE,UACxC,EAAAJ,iBAAAG,wBAAuBD,EAAiBG,WA0BxC,OAAOC,OAAOC,OAAOL,EAAkB,CAAEM,UAxBtBC,IACjBP,EAAiBQ,aAAjBR,EAAiBQ,WAAe,IAChCR,EAAiBQ,WAAWC,KAAKF,GAE1B,KACL,MAAMG,EAAeV,EAAiBQ,YAAYG,QAAQJ,IACrDG,GAAgBA,EAAe,GACpCV,EAAiBQ,YAAYI,OAAOF,EAAc,KAiBFG,QAbJC,IAE9C,GADAA,MAAgB,CAAC,IACZd,EAAiBQ,WAAY,MAAM,IAAIO,MAAM,yBAClD,MAAMC,GAAA,EAAUrB,8BAAAsB,oBAAmBH,EAAad,GAC1CkB,GAAA,EAAiBrB,wBAAAsB,UAASH,EAAShB,GAEzC,GAAIA,EAAiBQ,WACnB,UAAWD,KAAWP,EAAiBQ,WACrCD,EAAQW,KAMhB","ignoreList":[]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(t,i)=>{for(var e in i)__defProp(t,e,{get:i[e],enumerable:!0})},__copyProps=(t,i,e,n)=>{if(i&&"object"==typeof i||"function"==typeof i)for(let o of __getOwnPropNames(i))__hasOwnProp.call(t,o)||o===e||__defProp(t,o,{get:()=>i[o],enumerable:!(n=__getOwnPropDesc(i,o))||n.enumerable});return t},__toCommonJS=t=>__copyProps(__defProp({},"__esModule",{value:!0}),t),validate_cli_definition_exports={};__export(validate_cli_definition_exports,{validateCliDefinition:()=>validateCliDefinition}),module.exports=__toCommonJS(validate_cli_definition_exports);var import_parser_utilities=require("../parse/parser-utilities.cjs"),import_utilities=require("../utilities.cjs");function validateCliDefinition(t){if(!t.cliName)throw new Error('invalid cli definition: "cliName" property is required.');validateOptions(t),validateArguments(t);const i=t.subcommands;if(!i)return;if(0===i.length)throw new Error(`invalid cli definition "${t.cliName}": "subcommands" property is optional but cannot be empty.`);const e=i.map(t=>t.name);if(e.some(t=>!t))throw new Error('invalid subcommand definition: subcommand\'s "name" property is required.');const n=(0,import_utilities.findDuplicateStrings)(e).map(t=>`"${t}"`);if(n.length>0)throw new Error(`invalid cli definition "${t.cliName}" has duplicated subcommands: ${n.join(", ")}.`);for(const t of i){if(t.aliases){const n=(0,import_utilities.findDuplicateStrings)(t.aliases).map(t=>`"${t}"`);if(n.length>0)throw new Error(`subcommand "${t.name}" has duplicated aliases: ${n.join(", ")}.`);for(const n of t.aliases){if(""===n)throw new Error(`subcommand "${t.name}" has an empty string alias.`);if(e.includes(n))throw new Error(`subcommand "${t.name}" alias "${n}" conflicts with another subcommand name.`);const o=i.filter(i=>i.name!==t.name&&i.aliases?.includes(n));if(o.length>0)throw new Error(`subcommand "${t.name}" alias "${n}" conflicts with another subcommand alias: "${o[0].name}".`)}}validateOptions(t),validateArguments(t)}}function validateOptions(t){if(!t.options)return;const i="cliName"in t,e=i?t.cliName:t.name,n=t=>new Error(`invalid ${i?"cli":"subcommand"} definition "${e}": ${t}`),o=Object.entries(t.options);if(0===o.length)throw n('"options" property is optional but cannot be empty.');for(const[i,e]of o){if(!e.schema)throw n(`the option "${i}" missing a required property: "schema".`);if(!e._preparedType)throw n(`internal error: missing prepared type for option "${i}".`);if(isNegatedOptionName(i))throw n(`the option "${i}" is a negated option name.`);if(t.arguments&&i in t.arguments)throw n(`the option "${i}" name conflicts with an argument name.`);if(e.aliases){const r=(0,import_utilities.findDuplicateStrings)(e.aliases);if(r.length>0)throw n(`the option "${i}" has duplicated aliases: ${r.join(", ")}.`);for(const r of e.aliases){if(""===r)throw n(`the option "${i}" has an empty string alias.`);if(isNegatedOptionName(r))throw n(`the alias "${r}" of the option "${i}" is a negated option name.`);if(t.options[r])throw n(`the alias "${r}" of the option "${i}" conflicts with another option name.`);if(t.arguments&&r in t.arguments)throw n(`the alias "${r}" of the option "${i}" conflicts with an argument name.`);const e=o.find(([t,e])=>t!==i&&e.aliases?.includes(r));if(e)throw n(`the alias "${r}" of the option "${i}" conflicts with another alias name of the option "${e[0]}".`)}}if(e.requires){if(e.requires.includes(i))throw n(`the option "${i}" cannot require itself.`);const o=(0,import_utilities.findDuplicateStrings)(e.requires).map(t=>`"${t}"`);if(o.length>0)throw n(`the option "${i}" has duplicate requires: ${o.join(", ")}.`);for(const o of e.requires){if(!(o in t.options||o in(t.arguments??[])))throw n(`the option "${i}" requires "${o}", but it does not exist.`)}}if(e.conflictWith){if(e.conflictWith.includes(i))throw n(`the option "${i}" cannot conflict itself.`);const o=(0,import_utilities.findDuplicateStrings)(e.conflictWith).map(t=>`"${t}"`);if(o.length>0)throw n(`the option "${i}" has duplicate conflicts: ${o.join(", ")}.`);for(const o of e.conflictWith){if(!(o in t.options||o in(t.arguments??[])))throw n(`the option "${i}" conflict with "${o}", but it does not exist.`)}}if(e.requires&&e.conflictWith){const t=new Set(e.requires),o=new Set(e.conflictWith),r=t.intersection(o),a=Array.from(r).map(t=>`"${t}"`);if(a.length>0){const t=a.length>1?"s":"";throw n(`the option "${i}" cannot require and conflict with the same name${t}: ${a.join(", ")}.`)}}}}function validateArguments(t){if(!t.arguments)return;const i="cliName"in t,e=i?t.cliName:t.name,n=t=>new Error(`invalid ${i?"cli":"subcommand"} definition "${e}": ${t}`);if(t.arguments){const i=Object.entries(t.arguments);if(0===i.length)throw n('"arguments" property is optional but cannot be empty.');for(const[e,[o,r]]of i.entries()){if(/^\d+$/.test(o))throw n(`the argument "${o}" name cannot be a number.`);if(!r._preparedType)throw n(`internal error: missing prepared type for argument "${o}".`);if(!r.schema)throw n(`the argument "${o}" missing a required property: "schema".`);if(t.options&&o in t.options)throw n(`the argument "${o}" name conflicts with an option name.`);if(r._preparedType.optional){if(t.allowPositionals)throw n(`the argument "${o}" cannot be optional when "allowPositionals" is enabled.`);if(e!==i.length-1)throw n(`the argument "${o}" cannot be optional unless it is the last argument.`);if(r.requires){if(r.requires.includes(o))throw n(`the argument "${o}" cannot require itself.`);const i=(0,import_utilities.findDuplicateStrings)(r.requires).map(t=>`"${t}"`);if(i.length>0)throw n(`the argument "${o}" has duplicate requires: ${i.join(", ")}.`);for(const i of r.requires){if(!(i in(t.options??{})||i in t.arguments))throw n(`the argument "${o}" requires "${i}", but it does not exist.`)}}if(r.conflictWith){if(r.conflictWith.includes(o))throw n(`the argument "${o}" cannot conflict itself.`);const i=(0,import_utilities.findDuplicateStrings)(r.conflictWith).map(t=>`"${t}"`);if(i.length>0)throw n(`the argument "${o}" has duplicate conflicts: ${i.join(", ")}.`);for(const i of r.conflictWith){if(!(i in(t.options??{})||i in t.arguments))throw n(`the argument "${o}" conflict with "${i}", but it does not exist.`)}}if(r.requires&&r.conflictWith){const t=new Set(r.requires),i=new Set(r.conflictWith),e=t.intersection(i),a=Array.from(e).map(t=>`"${t}"`);if(a.length>0){throw n(`the argument "${o}" cannot require and conflict with the same name${a.length>1?"s":""}: ${a.join(", ")}.`)}}}}}}function isNegatedOptionName(t){return(0,import_parser_utilities.transformOptionToArgument)(t).startsWith("--no-")}
|
|
2
|
-
//# sourceMappingURL=validate-cli-definition.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["validate_cli_definition_exports","__export","validateCliDefinition","module","exports","__toCommonJS","import_parser_utilities","require","import_utilities","cliDefinition","cliName","Error","validateOptions","validateArguments","subcommands","length","commandsNames","map","c","name","some","commandsNamesDuplicates","findDuplicateStrings","join","subcommand","aliases","aliasesDuplicates","alias","includes","aliasConflicts","filter","commandDefinition","options","isCli","createError","message","optionsDefinitionEntries","Object","entries","option","schema","_preparedType","isNegatedOptionName","arguments","findConflict","find","n","d","requires","duplicateRequires","required","conflictWith","conflict","requiresSet","Set","conflictsSet","intersection","intersectionArray","Array","from","s","argumentsDefinitionEntries","index","argument","test","optional","allowPositionals","transformOptionToArgument","startsWith"],"sources":["../../../src/definitions/validate-cli-definition.ts"],"sourcesContent":["import { transformOptionToArgument } from \"../parse/parser-utilities.ts\";\nimport { findDuplicateStrings } from \"../utilities.ts\";\n\nimport type { Cli, Subcommand } from \"../types/definitions-types.ts\";\n\n/** @throws {Error} If validation fails. */\nexport function validateCliDefinition(cliDefinition: Cli) {\n if (!cliDefinition.cliName) {\n throw new Error(`invalid cli definition: \"cliName\" property is required.`);\n }\n\n // validate cli options\n validateOptions(cliDefinition);\n\n // validate cli arguments\n validateArguments(cliDefinition);\n\n const subcommands = cliDefinition.subcommands;\n if (!subcommands) return; // ok\n\n // no empty subcommands array\n if (subcommands.length === 0) {\n throw new Error(\n `invalid cli definition \"${cliDefinition.cliName}\": \"subcommands\" property is optional but cannot be empty.`,\n );\n }\n\n const commandsNames = subcommands.map(c => c.name);\n\n // required subcommand name\n if (commandsNames.some(c => !c)) {\n throw new Error(`invalid subcommand definition: subcommand's \"name\" property is required.`);\n }\n\n // no duplicate subcommand names\n const commandsNamesDuplicates = findDuplicateStrings(commandsNames).map(c => `\"${c}\"`);\n if (commandsNamesDuplicates.length > 0) {\n throw new Error(\n `invalid cli definition \"${cliDefinition.cliName}\" has duplicated subcommands: ${commandsNamesDuplicates.join(\", \")}.`,\n );\n }\n\n for (const subcommand of subcommands) {\n // command aliases check\n if (subcommand.aliases) {\n // no duplicated aliases\n const aliasesDuplicates = findDuplicateStrings(subcommand.aliases).map(c => `\"${c}\"`);\n if (aliasesDuplicates.length > 0) {\n throw new Error(`subcommand \"${subcommand.name}\" has duplicated aliases: ${aliasesDuplicates.join(\", \")}.`);\n }\n\n for (const alias of subcommand.aliases) {\n // no empty alias\n if (alias === \"\") {\n throw new Error(`subcommand \"${subcommand.name}\" has an empty string alias.`);\n }\n\n // no conflict with subcommand name\n if (commandsNames.includes(alias)) {\n throw new Error(`subcommand \"${subcommand.name}\" alias \"${alias}\" conflicts with another subcommand name.`);\n }\n\n // no conflict with another alias\n const aliasConflicts = subcommands.filter(c => c.name !== subcommand.name && c.aliases?.includes(alias));\n if (aliasConflicts.length > 0) {\n throw new Error(\n `subcommand \"${subcommand.name}\" alias \"${alias}\" conflicts with another subcommand alias: \"${aliasConflicts[0].name}\".`,\n );\n }\n }\n }\n\n // validate subcommand options\n validateOptions(subcommand);\n\n // validate subcommand arguments\n validateArguments(subcommand);\n }\n}\n\nfunction validateOptions(commandDefinition: Cli | Subcommand) {\n if (!commandDefinition.options) return; // ok\n\n const isCli = \"cliName\" in commandDefinition;\n const name = isCli ? commandDefinition.cliName : commandDefinition.name;\n\n const createError = (message: string) => {\n return new Error(`invalid ${isCli ? \"cli\" : \"subcommand\"} definition \"${name}\": ${message}`);\n };\n\n const optionsDefinitionEntries = Object.entries(commandDefinition.options);\n\n // no empty options\n if (optionsDefinitionEntries.length === 0) {\n throw createError(`\"options\" property is optional but cannot be empty.`);\n }\n\n for (const [name, option] of optionsDefinitionEntries) {\n // required type\n if (!option.schema) {\n throw createError(`the option \"${name}\" missing a required property: \"schema\".`);\n }\n\n // should not happen\n if (!option._preparedType) {\n throw createError(`internal error: missing prepared type for option \"${name}\".`);\n }\n\n // no negated option name for boolean options\n if (isNegatedOptionName(name)) {\n throw createError(`the option \"${name}\" is a negated option name.`);\n }\n\n // no conflict with argument name\n if (commandDefinition.arguments && name in commandDefinition.arguments) {\n throw createError(`the option \"${name}\" name conflicts with an argument name.`);\n }\n\n if (option.aliases) {\n // no duplicate aliases\n const aliasesDuplicates = findDuplicateStrings(option.aliases);\n if (aliasesDuplicates.length > 0) {\n throw createError(`the option \"${name}\" has duplicated aliases: ${aliasesDuplicates.join(\", \")}.`);\n }\n\n for (const alias of option.aliases) {\n // no empty string aliases\n if (alias === \"\") {\n throw createError(`the option \"${name}\" has an empty string alias.`);\n }\n\n // no negated alias name for boolean options\n if (isNegatedOptionName(alias)) {\n throw createError(`the alias \"${alias}\" of the option \"${name}\" is a negated option name.`);\n }\n\n // no alias name should conflict with any option name\n if (commandDefinition.options[alias]) {\n throw createError(`the alias \"${alias}\" of the option \"${name}\" conflicts with another option name.`);\n }\n\n // no alias name should conflict with any argument name\n if (commandDefinition.arguments && alias in commandDefinition.arguments) {\n throw createError(`the alias \"${alias}\" of the option \"${name}\" conflicts with an argument name.`);\n }\n\n // no alias name should conflict with any other alias name\n const findConflict = optionsDefinitionEntries.find(([n, d]) => n !== name && d.aliases?.includes(alias));\n if (findConflict) {\n throw createError(\n `the alias \"${alias}\" of the option \"${name}\" conflicts with another alias name of the option \"${findConflict[0]}\".`,\n );\n }\n }\n }\n\n if (option.requires) {\n // no self require\n if (option.requires.includes(name)) {\n throw createError(`the option \"${name}\" cannot require itself.`);\n }\n\n // no duplicate requires\n const duplicateRequires = findDuplicateStrings(option.requires).map(required => `\"${required}\"`);\n if (duplicateRequires.length > 0) {\n throw createError(`the option \"${name}\" has duplicate requires: ${duplicateRequires.join(\", \")}.`);\n }\n\n // no unknown required name\n for (const required of option.requires) {\n const exits = required in commandDefinition.options || required in (commandDefinition.arguments ?? []);\n if (!exits) {\n throw createError(`the option \"${name}\" requires \"${required}\", but it does not exist.`);\n }\n }\n }\n\n if (option.conflictWith) {\n // no self conflict\n if (option.conflictWith.includes(name)) {\n throw createError(`the option \"${name}\" cannot conflict itself.`);\n }\n\n // no duplicate conflicts\n const duplicateRequires = findDuplicateStrings(option.conflictWith).map(conflict => `\"${conflict}\"`);\n if (duplicateRequires.length > 0) {\n throw createError(`the option \"${name}\" has duplicate conflicts: ${duplicateRequires.join(\", \")}.`);\n }\n\n // no unknown conflict name\n for (const required of option.conflictWith) {\n const exits = required in commandDefinition.options || required in (commandDefinition.arguments ?? []);\n if (!exits) {\n throw createError(`the option \"${name}\" conflict with \"${required}\", but it does not exist.`);\n }\n }\n }\n\n // no intersection between requires and conflicts\n if (option.requires && option.conflictWith) {\n const requiresSet = new Set(option.requires);\n const conflictsSet = new Set(option.conflictWith);\n\n const intersection = requiresSet.intersection(conflictsSet);\n const intersectionArray = Array.from(intersection).map(name => `\"${name}\"`);\n\n if (intersectionArray.length > 0) {\n const s = intersectionArray.length > 1 ? \"s\" : \"\";\n throw createError(\n `the option \"${name}\" cannot require and conflict with the same name${s}: ${intersectionArray.join(\", \")}.`,\n );\n }\n }\n }\n}\n\nfunction validateArguments(commandDefinition: Cli | Subcommand) {\n if (!commandDefinition.arguments) return; // ok\n\n const isCli = \"cliName\" in commandDefinition;\n const name = isCli ? commandDefinition.cliName : commandDefinition.name;\n\n const createError = (message: string) => {\n return new Error(`invalid ${isCli ? \"cli\" : \"subcommand\"} definition \"${name}\": ${message}`);\n };\n\n if (commandDefinition.arguments) {\n const argumentsDefinitionEntries = Object.entries(commandDefinition.arguments);\n\n // no empty arguments record\n if (argumentsDefinitionEntries.length === 0) {\n throw createError(`\"arguments\" property is optional but cannot be empty.`);\n }\n\n for (const [index, [name, argument]] of argumentsDefinitionEntries.entries()) {\n // no number key name\n if (/^\\d+$/.test(name)) {\n throw createError(`the argument \"${name}\" name cannot be a number.`);\n }\n\n // should not happen\n if (!argument._preparedType) {\n throw createError(`internal error: missing prepared type for argument \"${name}\".`);\n }\n\n // no missing type\n if (!argument.schema) {\n throw createError(`the argument \"${name}\" missing a required property: \"schema\".`);\n }\n\n // no conflicting option\n if (commandDefinition.options && name in commandDefinition.options) {\n throw createError(`the argument \"${name}\" name conflicts with an option name.`);\n }\n\n if (!argument._preparedType.optional) continue; // ok\n\n // no optional argument when \"allowPositionals\" is enabled\n if (commandDefinition.allowPositionals) {\n throw createError(`the argument \"${name}\" cannot be optional when \"allowPositionals\" is enabled.`);\n }\n\n // only last argument can be optional\n if (index !== argumentsDefinitionEntries.length - 1) {\n throw createError(`the argument \"${name}\" cannot be optional unless it is the last argument.`);\n }\n\n if (argument.requires) {\n // no self require\n if (argument.requires.includes(name)) {\n throw createError(`the argument \"${name}\" cannot require itself.`);\n }\n\n // no duplicate requires\n const duplicateRequires = findDuplicateStrings(argument.requires).map(required => `\"${required}\"`);\n if (duplicateRequires.length > 0) {\n throw createError(`the argument \"${name}\" has duplicate requires: ${duplicateRequires.join(\", \")}.`);\n }\n\n // no unknown require\n for (const required of argument.requires) {\n const exits = required in (commandDefinition.options ?? {}) || required in commandDefinition.arguments;\n if (!exits) {\n throw createError(`the argument \"${name}\" requires \"${required}\", but it does not exist.`);\n }\n }\n }\n\n if (argument.conflictWith) {\n // no self conflict\n if (argument.conflictWith.includes(name)) {\n throw createError(`the argument \"${name}\" cannot conflict itself.`);\n }\n\n // no duplicate conflicts\n const duplicateRequires = findDuplicateStrings(argument.conflictWith).map(conflict => `\"${conflict}\"`);\n if (duplicateRequires.length > 0) {\n throw createError(`the argument \"${name}\" has duplicate conflicts: ${duplicateRequires.join(\", \")}.`);\n }\n\n // no unknown conflict\n for (const required of argument.conflictWith) {\n const exits = required in (commandDefinition.options ?? {}) || required in commandDefinition.arguments;\n if (!exits) {\n throw createError(`the argument \"${name}\" conflict with \"${required}\", but it does not exist.`);\n }\n }\n }\n\n // no intersection between requires and conflicts\n if (argument.requires && argument.conflictWith) {\n const requiresSet = new Set(argument.requires);\n const conflictsSet = new Set(argument.conflictWith);\n\n const intersection = requiresSet.intersection(conflictsSet);\n const intersectionArray = Array.from(intersection).map(name => `\"${name}\"`);\n\n if (intersectionArray.length > 0) {\n const s = intersectionArray.length > 1 ? \"s\" : \"\";\n throw createError(\n `the argument \"${name}\" cannot require and conflict with the same name${s}: ${intersectionArray.join(\", \")}.`,\n );\n }\n }\n }\n }\n}\n\nfunction isNegatedOptionName(name: string) {\n return transformOptionToArgument(name).startsWith(\"--no-\");\n}\n"],"mappings":"8iBAAAA,gCAAA,GAAAC,SAAAD,gCAAA,CAAAE,sBAAA,IAAAA,wBAAAC,OAAAC,QAAAC,aAAAL,iCAAA,IAAAM,wBAA0CC,QAAA,iCAC1CC,iBAAqCD,QAAA,oBAK9B,SAASL,sBAAsBO,GACpC,IAAKA,EAAcC,QACjB,MAAM,IAAIC,MAAM,2DAIlBC,gBAAgBH,GAGhBI,kBAAkBJ,GAElB,MAAMK,EAAcL,EAAcK,YAClC,IA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AAanB,EAAkBC,SAAW,CAAC,IAAMkB,KAAYnB,EAAkBY,WAE3F,MAAMT,EAAY,iBAAiBf,qBAAwB+B,6BAE/D,CACF,CAGA,GAAIa,EAASf,UAAYe,EAASZ,aAAc,CAC9C,MAAME,EAAc,IAAIC,IAAIS,EAASf,UAC/BO,EAAe,IAAID,IAAIS,EAASZ,cAEhCK,EAAeH,EAAYG,aAAaD,GACxCE,EAAoBC,MAAMC,KAAKH,GAAcvC,IAAIE,GAAQ,IAAIA,MAEnE,GAAIsC,EAAkB1C,OAAS,EAAG,CAEhC,MAAMmB,EACJ,iBAAiBf,oDAFTsC,EAAkB1C,OAAS,EAAI,IAAM,OAEiC0C,EAAkBlC,KAAK,SAEzG,CACF,CApEsC,CAqExC,CACF,CACF,CAEA,SAASmB,oBAAoBvB,GAC3B,SAAOb,wBAAA6D,2BAA0BhD,GAAMiD,WAAW,QACpD","ignoreList":[]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(e,t)=>{for(var i in t)__defProp(e,i,{get:t[i],enumerable:!0})},__copyProps=(e,t,i,r)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let n of __getOwnPropNames(t))__hasOwnProp.call(e,n)||n===i||__defProp(e,n,{get:()=>t[n],enumerable:!(r=__getOwnPropDesc(t,n))||r.enumerable});return e},__toCommonJS=e=>__copyProps(__defProp({},"__esModule",{value:!0}),e),format_arguments_exports={};__export(format_arguments_exports,{formatHelpMessageArguments:()=>formatHelpMessageArguments}),module.exports=__toCommonJS(format_arguments_exports);var import_utilities=require("../utilities.cjs"),import_terminal_markdown=require("./terminal-markdown.cjs");function formatHelpMessageArguments(e,t){if(0===e.length)return"";const{style:i,indentBeforeName:r,indentAfterName:n,indentBeforePlaceholder:o,newLineIndent:s,longest:l,argumentsTitle:p,defaultKeyword:a,optionalKeyword:m,exampleKeyword:_,emptyLines:u,emptyLinesBeforeTitle:d,emptyLinesAfterTitle:f,markdownRenderer:c,kebabCaseArgumentName:g}=t;let w=(0,import_utilities.ln)(d)+(0,import_utilities.indent)(1)+i.title(p)+(0,import_utilities.ln)(1+f);const P=l+r+n+o+s;for(const t of e){if(t.hidden)continue;let e=t.description?i.description(t.description):(0,import_terminal_markdown.terminalMarkdown)(t.descriptionMarkdown,c,i.description);e=(0,import_utilities.indentLines)(e,P);let s="";t.defaultValueAsString&&(s=i.default(a.replace("{{ value }}",t.defaultValueAsString))),t.optional&&!s&&(s=i.optional(m));const p=l-t.name.length;if(w+=(0,import_utilities.indent)(r)+i.argument(g?(0,import_utilities.toKebabCase)(t.name):t.name)+(0,import_utilities.indent)(o+n)+(0,import_utilities.indent)(p)+(0,import_utilities.insertAtEndOfFirstLine)(e,s)+(0,import_utilities.ln)(1+u),t.example){const e=(0,import_utilities.indentLines)(t.example,P+_.length+1);w+=(0,import_utilities.indent)(P)+i.exampleTitle(_)+(0,import_utilities.indent)(1)+i.example(e)+(0,import_utilities.ln)(1)}}return w}
|
|
2
|
-
//# sourceMappingURL=format-arguments.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["format_arguments_exports","__export","formatHelpMessageArguments","module","exports","__toCommonJS","import_utilities","require","import_terminal_markdown","argumentsMetadata","options","length","style","indentBeforeName","indentAfterName","indentBeforePlaceholder","newLineIndent","longest","argumentsTitle","defaultKeyword","optionalKeyword","exampleKeyword","emptyLines","emptyLinesBeforeTitle","emptyLinesAfterTitle","markdownRenderer","kebabCaseArgumentName","message","ln","indent","title","totalSpacing","metadata","hidden","description","terminalMarkdown","descriptionMarkdown","indentLines","defaultOrOptional","defaultValueAsString","default","replace","optional","spacing","name","argument","toKebabCase","insertAtEndOfFirstLine","example","normalizeExample","exampleTitle"],"sources":["../../../src/help-message/format-arguments.ts"],"sourcesContent":["import { indent, indentLines, insertAtEndOfFirstLine, ln, toKebabCase } from \"../utilities.ts\";\nimport { terminalMarkdown } from \"./terminal-markdown.ts\";\n\nimport type { ArgumentMetadata } from \"../types/metadata-types.ts\";\nimport type { FormatOptions } from \"./generate-for-cli.ts\";\n\nexport function formatHelpMessageArguments(argumentsMetadata: ArgumentMetadata[], options: FormatOptions): string {\n if (argumentsMetadata.length === 0) return \"\";\n\n const {\n style,\n indentBeforeName,\n indentAfterName,\n indentBeforePlaceholder,\n newLineIndent,\n longest,\n argumentsTitle,\n defaultKeyword,\n optionalKeyword,\n exampleKeyword,\n emptyLines,\n emptyLinesBeforeTitle,\n emptyLinesAfterTitle,\n markdownRenderer,\n kebabCaseArgumentName,\n } = options;\n\n let message = ln(emptyLinesBeforeTitle) + indent(1) + style.title(argumentsTitle) + ln(1 + emptyLinesAfterTitle);\n\n // the space from the beginning to the start of the next column.\n const totalSpacing = longest + indentBeforeName + indentAfterName + indentBeforePlaceholder + newLineIndent;\n\n for (const metadata of argumentsMetadata) {\n if (metadata.hidden) continue;\n\n let description = metadata.description\n ? style.description(metadata.description)\n : terminalMarkdown(metadata.descriptionMarkdown, markdownRenderer, style.description);\n\n description = indentLines(description, totalSpacing);\n\n let defaultOrOptional = \"\";\n\n if (metadata.defaultValueAsString) {\n defaultOrOptional = style.default(defaultKeyword.replace(\"{{ value }}\", metadata.defaultValueAsString));\n }\n\n if (metadata.optional && !defaultOrOptional) {\n defaultOrOptional = style.optional(optionalKeyword);\n }\n\n const spacing = longest - metadata.name.length;\n\n message +=\n indent(indentBeforeName) +\n style.argument(kebabCaseArgumentName ? toKebabCase(metadata.name) : metadata.name) +\n indent(indentBeforePlaceholder + indentAfterName) +\n indent(spacing) +\n insertAtEndOfFirstLine(description, defaultOrOptional) +\n ln(1 + emptyLines);\n\n if (metadata.example) {\n const normalizeExample = indentLines(metadata.example, totalSpacing + exampleKeyword.length + 1); // +1 for the space after the keyword\n message +=\n indent(totalSpacing) + style.exampleTitle(exampleKeyword) + indent(1) + style.example(normaliz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AI,EACjFtC,iBAAAuB,QAAOd,EAA0BD,IAAe,EAChDR,iBAAAuB,QAAOc,IAAO,EACdrC,iBAAAyC,wBAAuBb,EAAaI,IAAiB,EACrDhC,iBAAAsB,IAAG,EAAIN,GAELU,EAASgB,QAAS,CACpB,MAAMC,GAAA,EAAmB3C,iBAAA+B,aAAYL,EAASgB,QAASjB,EAAeV,EAAeV,OAAS,GAC9FgB,IAAA,EACErB,iBAAAuB,QAAOE,GAAgBnB,EAAMsC,aAAa7B,IAAc,EAAIf,iBAAAuB,QAAO,GAAKjB,EAAMoC,QAAQC,IAAgB,EAAI3C,iBAAAsB,IAAG,EACjH,CACF,CAEA,OAAOD,CACT","ignoreList":[]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(e,t)=>{for(var i in t)__defProp(e,i,{get:t[i],enumerable:!0})},__copyProps=(e,t,i,o)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let n of __getOwnPropNames(t))__hasOwnProp.call(e,n)||n===i||__defProp(e,n,{get:()=>t[n],enumerable:!(o=__getOwnPropDesc(t,n))||o.enumerable});return e},__toCommonJS=e=>__copyProps(__defProp({},"__esModule",{value:!0}),e),format_options_exports={};__export(format_options_exports,{formatHelpMessageOptions:()=>formatHelpMessageOptions}),module.exports=__toCommonJS(format_options_exports);var import_utilities=require("../utilities.cjs"),import_terminal_markdown=require("./terminal-markdown.cjs");function formatHelpMessageOptions(e,t){if(0===e.length)return"";const{style:i,indentBeforeName:o,indentAfterName:n,indentBeforePlaceholder:r,newLineIndent:p,emptyLines:s,longest:l,exampleKeyword:a,optionalKeyword:_,defaultKeyword:m,optionsTitle:d,emptyLinesBeforeTitle:u,emptyLinesAfterTitle:c,markdownRenderer:f}=t;let g=(0,import_utilities.ln)(u)+(0,import_utilities.indent)(1)+i.title(d)+(0,import_utilities.ln)(1+c);const w=l+o+n+r+p;for(const t of e){if(t.hidden)continue;const e=[...t.aliasesAsArgs,t.nameAsArg],p=e.map(e=>i.option(e)).join(i.punctuation(", "));let d=t.description?i.description(t.description):(0,import_terminal_markdown.terminalMarkdown)(t.descriptionMarkdown,f,i.description);d=(0,import_utilities.indentLines)(d,w);let u="";t.defaultValueAsString&&(u=i.default(m.replace("{{ value }}",t.defaultValueAsString))),t.optional&&!u&&(u=i.optional(_));const c=l-(e.join(", ").length+t.placeholder.length);if(g+=(0,import_utilities.indent)(o)+p+(0,import_utilities.indent)(r)+i.placeholder(t.placeholder)+(0,import_utilities.indent)(n)+(0,import_utilities.indent)(c)+(0,import_utilities.insertAtEndOfFirstLine)(d,u)+(0,import_utilities.ln)(1+s),t.example){const e=(0,import_utilities.indentLines)(t.example,w+a.length+1);g+=(0,import_utilities.indent)(w)+i.exampleTitle(a)+(0,import_utilities.indent)(1)+i.example(e)+(0,import_utilities.ln)(1)}}return g}
|
|
2
|
-
//# sourceMappingURL=format-options.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["format_options_exports","__export","formatHelpMessageOptions","module","exports","__toCommonJS","import_utilities","require","import_terminal_markdown","optionsMetadata","options","length","style","indentBeforeName","indentAfterName","indentBeforePlaceholder","newLineIndent","emptyLines","longest","exampleKeyword","optionalKeyword","defaultKeyword","optionsTitle","emptyLinesBeforeTitle","emptyLinesAfterTitle","markdownRenderer","message","ln","indent","title","totalSpacing","metadata","hidden","names","aliasesAsArgs","nameAsArg","coloredNames","map","name","option","join","punctuation","description","terminalMarkdown","descriptionMarkdown","indentLines","defaultOrOptional","defaultValueAsString","default","replace","optional","spacing","placeholder","insertAtEndOfFirstLine","example","normalizeExample","exampleTitle"],"sources":["../../../src/help-message/format-options.ts"],"sourcesContent":["import { indent, indentLines, insertAtEndOfFirstLine, ln } from \"../utilities.ts\";\nimport { terminalMarkdown } from \"./terminal-markdown.ts\";\n\nimport type { OptionMetadata } from \"../types/metadata-types.ts\";\nimport type { FormatOptions } from \"./generate-for-cli.ts\";\n\nexport function formatHelpMessageOptions(optionsMetadata: OptionMetadata[], options: FormatOptions): string {\n if (optionsMetadata.length === 0) return \"\";\n\n const {\n style,\n indentBeforeName,\n indentAfterName,\n indentBeforePlaceholder,\n newLineIndent,\n emptyLines,\n longest,\n exampleKeyword,\n optionalKeyword,\n defaultKeyword,\n optionsTitle,\n emptyLinesBeforeTitle,\n emptyLinesAfterTitle,\n markdownRenderer,\n } = options;\n\n let message = ln(emptyLinesBeforeTitle) + indent(1) + style.title(optionsTitle) + ln(1 + emptyLinesAfterTitle);\n\n // the space from the beginning to the start of the next column.\n const totalSpacing = longest + indentBeforeName + indentAfterName + indentBeforePlaceholder + newLineIndent;\n\n for (const metadata of optionsMetadata) {\n if (metadata.hidden) continue;\n\n const names = [...metadata.aliasesAsArgs, metadata.nameAsArg];\n const coloredNames = names.map(name => style.option(name)).join(style.punctuation(\", \"));\n\n let description = metadata.description\n ? style.description(metadata.description)\n : terminalMarkdown(metadata.descriptionMarkdown, markdownRenderer, style.description);\n\n description = indentLines(description, totalSpacing);\n\n let defaultOrOptional = \"\";\n\n if (metadata.defaultValueAsString) {\n defaultOrOptional = style.default(defaultKeyword.replace(\"{{ value }}\", metadata.defaultValueAsString));\n }\n\n if (metadata.optional && !defaultOrOptional) {\n defaultOrOptional = style.optional(optionalKeyword);\n }\n\n // space between the option and the description\n const optLength = names.join(\", \").length + metadata.placeholder.length;\n const spacing = longest - optLength;\n\n message +=\n indent(indentBeforeName) +\n coloredNames +\n indent(indentBeforePlaceholder) +\n style.placeholder(metadata.placeholder) +\n indent(indentAfterName) +\n indent(spacing) +\n insertAtEndOfFirstLine(description, defaultOrOptional) +\n ln(1 + emptyLines);\n\n if (metadata.example) {\n const normalizeExample = indentLines(metadata.example, totalSpacing + exampleKeyword.length + 1); // + 1 for the space after the keyword\n message +=\n indent(totalSpacing) + style.exampleTitle(exampleKeyword) + indent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e,EAAMO,KAAK,MAAM7B,OAASoB,EAASqB,YAAYzC,QAajE,GAVAe,IAAA,EACEpB,iBAAAsB,QAAOf,GACPuB,GAAA,EACA9B,iBAAAsB,QAAOb,GACPH,EAAMwC,YAAYrB,EAASqB,cAAW,EACtC9C,iBAAAsB,QAAOd,IAAe,EACtBR,iBAAAsB,QAAOuB,IAAO,EACd7C,iBAAA+C,wBAAuBX,EAAaI,IAAiB,EACrDxC,iBAAAqB,IAAG,EAAIV,GAELc,EAASuB,QAAS,CACpB,MAAMC,GAAA,EAAmBjD,iBAAAuC,aAAYd,EAASuB,QAASxB,EAAeX,EAAeR,OAAS,GAC9Fe,IAAA,EACEpB,iBAAAsB,QAAOE,GAAgBlB,EAAM4C,aAAarC,IAAc,EAAIb,iBAAAsB,QAAO,GAAKhB,EAAM0C,QAAQC,IAAgB,EAAIjD,iBAAAqB,IAAG,EACjH,CACF,CAEA,OAAOD,CACT","ignoreList":[]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(e,t)=>{for(var o in t)__defProp(e,o,{get:t[o],enumerable:!0})},__copyProps=(e,t,o,i)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let n of __getOwnPropNames(t))__hasOwnProp.call(e,n)||n===o||__defProp(e,n,{get:()=>t[n],enumerable:!(i=__getOwnPropDesc(t,n))||i.enumerable});return e},__toCommonJS=e=>__copyProps(__defProp({},"__esModule",{value:!0}),e),format_subcommands_exports={};__export(format_subcommands_exports,{formatHelpMessageCommands:()=>formatHelpMessageCommands}),module.exports=__toCommonJS(format_subcommands_exports);var import_utilities=require("../utilities.cjs"),import_terminal_markdown=require("./terminal-markdown.cjs");function formatHelpMessageCommands(e,t){if(0===e.length)return"";const{style:o,indentBeforeName:i,indentAfterName:n,indentBeforePlaceholder:r,newLineIndent:s,longest:m,commandsTitle:p,emptyLines:_,emptyLinesBeforeTitle:a,emptyLinesAfterTitle:l,markdownRenderer:d}=t;let c=(0,import_utilities.ln)(a)+(0,import_utilities.indent)(1)+o.title(p)+(0,import_utilities.ln)(1+l);const u=m+i+n+r+s;for(const t of e){if(t.hidden)continue;const e=t.aliases.concat([t.name]),s=(0,import_utilities.subcommandPlaceholder)(t);let p=t.description?o.description(t.description):(0,import_terminal_markdown.terminalMarkdown)(t.descriptionMarkdown,d,o.description);p=(0,import_utilities.indentLines)(p,u);const a=m-(e.join(", ").length+s.length),l=e.map(e=>o.command(e)).join(o.punctuation(", "));c+=(0,import_utilities.indent)(i)+l+(0,import_utilities.indent)(r)+o.placeholder(s)+(0,import_utilities.indent)(n)+(0,import_utilities.indent)(a)+p+(0,import_utilities.ln)(1+_)}return c}
|
|
2
|
-
//# sourceMappingURL=format-subcommands.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["format_subcommands_exports","__export","formatHelpMessageCommands","module","exports","__toCommonJS","import_utilities","require","import_terminal_markdown","subcommandsMetadata","options","length","style","indentBeforeName","indentAfterName","indentBeforePlaceholder","newLineIndent","longest","commandsTitle","emptyLines","emptyLinesBeforeTitle","emptyLinesAfterTitle","markdownRenderer","message","ln","indent","title","totalSpacing","metadata","hidden","names","aliases","concat","name","placeholder","subcommandPlaceholder","description","terminalMarkdown","descriptionMarkdown","indentLines","spacing","join","coloredNames","map","command","punctuation"],"sources":["../../../src/help-message/format-subcommands.ts"],"sourcesContent":["import { indent, indentLines, ln, subcommandPlaceholder } from \"../utilities.ts\";\nimport { terminalMarkdown } from \"./terminal-markdown.ts\";\n\nimport type { SubcommandMetadata } from \"../types/metadata-types.ts\";\nimport type { FormatOptions } from \"./generate-for-cli.ts\";\n\nexport function formatHelpMessageCommands(subcommandsMetadata: SubcommandMetadata[], options: FormatOptions): string {\n if (subcommandsMetadata.length === 0) return \"\";\n\n const {\n style,\n indentBeforeName,\n indentAfterName,\n indentBeforePlaceholder,\n newLineIndent,\n longest,\n commandsTitle,\n emptyLines,\n emptyLinesBeforeTitle,\n emptyLinesAfterTitle,\n markdownRenderer,\n } = options;\n\n let message = ln(emptyLinesBeforeTitle) + indent(1) + style.title(commandsTitle) + ln(1 + emptyLinesAfterTitle);\n\n // the space from the beginning to the start of the next column.\n const totalSpacing = longest + indentBeforeName + indentAfterName + indentBeforePlaceholder + newLineIndent;\n\n for (const metadata of subcommandsMetadata) {\n if (metadata.hidden) continue;\n\n const names = metadata.aliases.concat([metadata.name]);\n const placeholder = subcommandPlaceholder(metadata);\n\n let description = metadata.description\n ? style.description(metadata.description)\n : terminalMarkdown(metadata.descriptionMarkdown, markdownRenderer, style.description);\n\n description = indentLines(description, totalSpacing);\n\n const optLength = names.join(\", \").length + placeholder.length;\n const spacing = longest - optLength;\n\n const coloredNames = names.map(name => style.command(name)).join(style.punctuation(\", \"));\n\n message +=\n indent(indentBeforeName) +\n coloredNames +\n indent(indentBeforePlaceholder) +\n style.placeholder(placeholder) +\n indent(indentAfterName) +\n indent(spacing) +\n description +\n ln(1 + emptyLines);\n }\n\n return message;\n}\n"],"mappings":"8iBAAAA,2BAAA,GAAAC,SAAAD,2BAAA,CAAAE,0BAAA,IAAAA,4BAAAC,OAAAC,QAAAC,aAAAL,4BAAA,IAAAM,iBAA+DC,QAAA,oBAC/DC,yBAAiCD,QAAA,2BAK1B,SAASL,0BAA0BO,EAA2CC,GACnF,GAAmC,IAA/BD,EAAoBE,OAAc,MAAO,GAE7C,MAAMC,MACJA,EAAAC,iBACAA,EAAAC,gBACAA,EAAAC,wBACAA,EAAAC,cACAA,EAAAC,QACAA,EAAAC,cACAA,EAAAC,WACAA,EAAAC,sBACAA,EAAAC,qBACAA,EAAAC,iBACAA,GACEZ,EAEJ,IAAIa,GAAA,EAAUjB,iBAAAkB,IAAGJ,IAAqB,EAAId,iBAAAmB,QAAO,GAAKb,EAAMc,MAAMR,IAAa,EAAIZ,iBAAAkB,IAAG,EAAIH,GAG1F,MAAMM,EAAeV,EAAUJ,EAAmBC,EAAkBC,EAA0BC,EAE9F,UAAWY,KAAYnB,EAAqB,CAC1C,GAAImB,EAASC,OAAQ,SAErB,MAAMC,EAAQF,EAASG,QAAQC,OAAO,CAACJ,EAASK,OAC1CC,GAAA,EAAc5B,iBAAA6B,uBAAsBP,GAE1C,IAAIQ,EAAcR,EAASQ,YACvBxB,EAAMwB,YAAYR,EAASQ,cAAW,EACtC5B,yBAAA6B,kBAAiBT,EAASU,oBAAqBhB,EAAkBV,EAAMwB,aAE3EA,GAAA,EAAc9B,iBAAAiC,aAAYH,EAAaT,GAEvC,MACMa,EAAUvB,GADEa,EAAMW,KAAK,MAAM9B,OAASuB,EAAYvB,QAGlD+B,EAAeZ,EAAMa,IAAIV,GAAQrB,EAAMgC,QAAQX,IAAOQ,KAAK7B,EAAMiC,YAAY,OAEnFtB,IAAA,EACEjB,iBAAAmB,QAAOZ,GACP6B,GAAA,EACApC,iBAAAmB,QAAOV,GACPH,EAAMsB,YAAYA,IAAW,EAC7B5B,iBAAAmB,QAAOX,IAAe,EACtBR,iBAAAmB,QAAOe,GACPJ,GAAA,EACA9B,iBAAAkB,IAAG,EAAIL,EACX,CAEA,OAAOI,CACT","ignoreList":[]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(e,t)=>{for(var i in t)__defProp(e,i,{get:t[i],enumerable:!0})},__copyProps=(e,t,i,o)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let r of __getOwnPropNames(t))__hasOwnProp.call(e,r)||r===i||__defProp(e,r,{get:()=>t[r],enumerable:!(o=__getOwnPropDesc(t,r))||o.enumerable});return e},__toCommonJS=e=>__copyProps(__defProp({},"__esModule",{value:!0}),e),generate_for_cli_exports={};__export(generate_for_cli_exports,{generateCliHelpMessage:()=>generateCliHelpMessage}),module.exports=__toCommonJS(generate_for_cli_exports);var import_cli_metadata=require("../metadata/cli-metadata.cjs"),import_utilities=require("../utilities.cjs"),import_format_arguments=require("./format-arguments.cjs"),import_format_options=require("./format-options.cjs"),import_format_subcommands=require("./format-subcommands.cjs"),import_set_defaults=require("./set-defaults.cjs"),import_styles=require("./styles.cjs"),import_terminal_markdown=require("./terminal-markdown.cjs");function generateCliHelpMessage(e,t={}){const i=(0,import_set_defaults.setPrintHelpOptionsDefaults)(t),o={...import_styles.helpMessageStyles.default,...i.style},r=(0,import_cli_metadata.getCliMetadata)(e),n=e=>(0,import_utilities.indent)(1)+o.title(e);let s="",a=r.usage;if(a||(a=o.punctuation("$"),a+=r.name?o.description("",r.name):"",a+=r.subcommands.length>0?o.command("","[command]"):"",a+=r.options.length>0?o.option("","[options]"):"",a+=r.arguments.length>0?o.argument("","<arguments>"):"",a+=r.allowPositionals?o.argument("","<positionals>"):""),s+=n(i.usageTitle)+(0,import_utilities.ln)(1+i.emptyLinesAfterTitle),s+=(0,import_utilities.indent)(i.indentBeforeName)+a+(0,import_utilities.ln)(1),r.description||r.descriptionMarkdown){s+=(0,import_utilities.ln)(i.emptyLinesBeforeTitle)+n(i.descriptionTitle)+(0,import_utilities.ln)(1+i.emptyLinesAfterTitle);let e=r.description?o.description(r.description):(0,import_terminal_markdown.terminalMarkdown)(r.descriptionMarkdown,i.markdownRenderer,o.description);e=(0,import_utilities.indentLines)(e,i.indentBeforeName),s+=(0,import_utilities.indent)(i.indentBeforeName)+e+(0,import_utilities.ln)(1)}let m=0;const l=r.options;let p=0;for(const e of l){const t=[...e.aliasesAsArgs,e.nameAsArg].join(", ").length+e.placeholder.length;p=Math.max(t,p)}m=Math.max(p,m);const _=r.subcommands;let c=0;for(const e of _){const t=[...e.aliases,e.name].join(", "),i=(0,import_utilities.subcommandPlaceholder)(e),o=t.length+i.length;c=Math.max(o,c)}m=Math.max(c,m);const u=r.arguments;let d=0;for(const e of u)d=Math.max(e.name.length,d);m=Math.max(d,m);const f=Object.assign({...i},{style:o,longest:m});if(s+=(0,import_format_options.formatHelpMessageOptions)(l,f),s+=(0,import_format_subcommands.formatHelpMessageCommands)(_,f),s+=(0,import_format_arguments.formatHelpMessageArguments)(u,f),r.example){s+=(0,import_utilities.ln)(i.emptyLinesBeforeTitle)+n(i.exampleTitle)+(0,import_utilities.ln)(1+i.emptyLinesAfterTitle);const e=(0,import_utilities.indentLines)(r.example,i.indentBeforeName);s+=(0,import_utilities.indent)(i.indentBeforeName)+o.example(e)}return s}
|
|
2
|
-
//# sourceMappingURL=generate-for-cli.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["generate_for_cli_exports","__export","generateCliHelpMessage","module","exports","__toCommonJS","import_cli_metadata","require","import_utilities","import_format_arguments","import_format_options","import_format_subcommands","import_set_defaults","import_styles","import_terminal_markdown","cliDefinition","printOptions","options","setPrintHelpOptionsDefaults","style","helpMessageStyles","default","metadata","getCliMetadata","formatTitle","title","indent","message","usage","punctuation","name","description","subcommands","length","command","option","arguments","argument","allowPositionals","usageTitle","ln","emptyLinesAfterTitle","indentBeforeName","descriptionMarkdown","emptyLinesBeforeTitle","descriptionTitle","terminalMarkdown","markdownRenderer","indentLines","longest","optionsMetadata","longestOptionTitle","optLength","aliasesAsArgs","nameAsArg","join","placeholder","Math","max","subcommandsMetadata","longestSubcommandTitle","names","aliases","subcommandPlaceholder","argumentsMetadata","longestArgumentTitle","formatOptions","Object","assign","formatHelpMessageOptions","formatHelpMessageCommands","formatHelpMessageArguments","example","exampleTitle","normalizeExample"],"sources":["../../../src/help-message/generate-for-cli.ts"],"sourcesContent":["import { getCliMetadata } from \"../metadata/cli-metadata.ts\";\nimport { indent, indentLines, ln, subcommandPlaceholder } from \"../utilities.ts\";\nimport { formatHelpMessageArguments } from \"./format-arguments.ts\";\nimport { formatHelpMessageOptions } from \"./format-options.ts\";\nimport { formatHelpMessageCommands } from \"./format-subcommands.ts\";\nimport { setPrintHelpOptionsDefaults } from \"./set-defaults.ts\";\nimport { helpMessageStyles } from \"./styles.ts\";\nimport { terminalMarkdown } from \"./terminal-markdown.ts\";\n\nimport type { Cli } from \"../types/definitions-types.ts\";\nimport type { HelpMessageStyleImpl, PrintHelpOptions } from \"../types/help-message-types.ts\";\n\nexport interface FormatOptions extends Required<PrintHelpOptions> {\n style: HelpMessageStyleImpl;\n longest: number;\n}\n\nexport function generateCliHelpMessage(cliDefinition: Cli, printOptions: PrintHelpOptions = {}): string {\n const options = setPrintHelpOptionsDefaults(printOptions);\n\n const style = { ...helpMessageStyles.default, ...options.style };\n\n const metadata = getCliMetadata(cliDefinition);\n\n const formatTitle = (title: string) => indent(1) + style.title(title);\n\n let message = \"\";\n\n // CLI usage\n let usage = metadata.usage;\n if (!usage) {\n usage = style.punctuation(\"$\");\n usage += metadata.name ? style.description(\"\", metadata.name) : \"\";\n usage += metadata.subcommands.length > 0 ? style.command(\"\", \"[command]\") : \"\";\n usage += metadata.options.length > 0 ? style.option(\"\", \"[options]\") : \"\";\n usage += metadata.arguments.length > 0 ? style.argument(\"\", \"<arguments>\") : \"\";\n usage += metadata.allowPositionals ? style.argument(\"\", \"<positionals>\") : \"\";\n }\n\n message += formatTitle(options.usageTitle) + ln(1 + options.emptyLinesAfterTitle);\n message += indent(options.indentBeforeName) + usage + ln(1);\n\n // CLI description\n if (metadata.description || metadata.descriptionMarkdown) {\n message +=\n ln(options.emptyLinesBeforeTitle) + formatTitle(options.descriptionTitle) + ln(1 + options.emptyLinesAfterTitle);\n\n let description = metadata.description\n ? style.description(metadata.description)\n : terminalMarkdown(metadata.descriptionMarkdown, options.markdownRenderer, style.description);\n\n description = indentLines(description, options.indentBeforeName);\n\n message += indent(options.indentBeforeName) + description + ln(1);\n }\n\n let longest = 0;\n\n // Prepare CLI options\n const optionsMetadata = metadata.options;\n\n let longestOptionTitle = 0;\n for (const metadata of optionsMetadata) {\n const names = [...metadata.aliasesAsArgs, metadata.nameAsArg].join(\", \");\n const optLength = names.length + metadata.placeholder.length;\n longestOptionTitle = Math.max(optLength, longestOptionTitle);\n }\n\n longest = Math.max(longestOptionTitle, longest);\n\n // Prepare CLI commands\n const subcommandsMetadata = metadata.subcommands;\n\n let longestSubcommandTitle = 0;\n for (const metadata of subcommandsMetadata) {\n const names = [...metadata.aliases, metadata.name].join(\", \");\n const placeholder = subcommandPlaceholder(metadata);\n const optLength = names.length + placeholder.length;\n longestSubcommandTitle = Math.max(optLength, longestSubcommandTitle);\n }\n\n longest = Math.max(longestSubcommandTitle, longest);\n\n // Prepare CLI arguments\n const argumentsMetadata = metadata.arguments;\n\n let longestArgumentTitle = 0;\n for (const argument of argumentsMetadata) {\n longestArgumentTitle = Math.max(argument.name.length, longestArgumentTitle);\n }\n\n longest = Math.max(longestArgumentTitle, longest);\n\n const formatOptions = Object.assign({ ...options }, { style, longest }) as FormatOptions;\n\n // CLI options\n message += formatHelpMessageOptions(optionsMetadata, formatOptions);\n\n // CLI commands\n message += formatHelpMessageCommands(subcommandsMetadata, formatOptions);\n\n // CLI arguments\n message += formatHelpMessageArguments(argumentsMetadata, formatOptions);\n\n // CLI example\n if (metadata.example) {\n message +=\n ln(options.emptyLinesBeforeTitle) + formatTitle(options.exampleTitle) + ln(1 + options.emptyLinesAfterTitle);\n const normalizeExample = indentLines(metadata.example, options.indentBeforeName);\n message += indent(options.indentBeforeName) + style.example(normalizeExample);\n }\n\n return message;\n}\n"],"mappings":"8iBAAAA,yBAAA,GAAAC,SAAAD,yBAAA,CAAAE,uBAAA,IAAAA,yBAAAC,OAAAC,QAAAC,aAAAL,0BAAA,IAAAM,oBAA+BC,QAAA,gCAC/BC,iBAA+DD,QAAA,oBAC/DE,wBAA2CF,QAAA,0BAC3CG,sBAAyCH,QAAA,wBACzCI,0BAA0CJ,QAAA,4BAC1CK,oBAA4CL,QAAA,sBAC5CM,cAAkCN,QAAA,gBAClCO,yBAAiCP,QAAA,2BAU1B,SAASL,uBAAuBa,EAAoB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