zod-args-parser 1.2.8 → 2.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +525 -588
- package/lib/cjs/autocomplete-scripts/bash-autocomplete-script.cjs +2 -0
- package/lib/cjs/autocomplete-scripts/bash-autocomplete-script.cjs.map +1 -0
- package/lib/cjs/autocomplete-scripts/powershell-autocomplete-script.cjs +2 -0
- package/lib/cjs/autocomplete-scripts/powershell-autocomplete-script.cjs.map +1 -0
- package/lib/cjs/autocomplete-scripts/zsh-autocomplete-script.cjs +42 -0
- package/lib/cjs/autocomplete-scripts/zsh-autocomplete-script.cjs.map +1 -0
- package/lib/cjs/coerce/coerce-methods.cjs +2 -0
- package/lib/cjs/coerce/coerce-methods.cjs.map +1 -0
- package/lib/cjs/coerce/string-to-array.cjs +2 -0
- package/lib/cjs/coerce/string-to-array.cjs.map +1 -0
- package/lib/cjs/coerce/string-to-primitive.cjs +2 -0
- package/lib/cjs/coerce/string-to-primitive.cjs.map +1 -0
- package/lib/cjs/coerce/string-to-set.cjs +2 -0
- package/lib/cjs/coerce/string-to-set.cjs.map +1 -0
- package/lib/cjs/definitions/define-arguments.cjs +2 -0
- package/lib/cjs/definitions/define-arguments.cjs.map +1 -0
- package/lib/cjs/definitions/define-cli.cjs +2 -0
- package/lib/cjs/definitions/define-cli.cjs.map +1 -0
- package/lib/cjs/definitions/define-options.cjs +2 -0
- package/lib/cjs/definitions/define-options.cjs.map +1 -0
- package/lib/cjs/definitions/define-subcommand.cjs +2 -0
- package/lib/cjs/definitions/define-subcommand.cjs.map +1 -0
- package/lib/cjs/definitions/validate-cli-definition.cjs +2 -0
- package/lib/cjs/definitions/validate-cli-definition.cjs.map +1 -0
- package/lib/cjs/help-message/format-arguments.cjs +2 -0
- package/lib/cjs/help-message/format-arguments.cjs.map +1 -0
- package/lib/cjs/help-message/format-options.cjs +2 -0
- package/lib/cjs/help-message/format-options.cjs.map +1 -0
- package/lib/cjs/help-message/format-subcommands.cjs +2 -0
- package/lib/cjs/help-message/format-subcommands.cjs.map +1 -0
- package/lib/cjs/help-message/generate-for-cli.cjs +2 -0
- package/lib/cjs/help-message/generate-for-cli.cjs.map +1 -0
- package/lib/cjs/help-message/generate-for-subcommand.cjs +2 -0
- package/lib/cjs/help-message/generate-for-subcommand.cjs.map +1 -0
- package/lib/cjs/help-message/print-help.cjs +2 -0
- package/lib/cjs/help-message/print-help.cjs.map +1 -0
- package/lib/cjs/help-message/set-defaults.cjs +2 -0
- package/lib/cjs/help-message/set-defaults.cjs.map +1 -0
- package/lib/cjs/help-message/styles.cjs +2 -0
- package/lib/cjs/help-message/styles.cjs.map +1 -0
- package/lib/cjs/help-message/terminal-markdown.cjs +2 -0
- package/lib/cjs/help-message/terminal-markdown.cjs.map +1 -0
- package/lib/cjs/index.cjs +2 -0
- package/lib/cjs/index.cjs.map +1 -0
- package/lib/cjs/markdown/generate-markdown.cjs +2 -0
- package/lib/cjs/markdown/generate-markdown.cjs.map +1 -0
- package/lib/cjs/metadata/arguments-metadata.cjs +2 -0
- package/lib/cjs/metadata/arguments-metadata.cjs.map +1 -0
- package/lib/cjs/metadata/cli-metadata.cjs +2 -0
- package/lib/cjs/metadata/cli-metadata.cjs.map +1 -0
- package/lib/cjs/metadata/options-metadata.cjs +2 -0
- package/lib/cjs/metadata/options-metadata.cjs.map +1 -0
- package/lib/cjs/metadata/subcommands-metadata.cjs +2 -0
- package/lib/cjs/metadata/subcommands-metadata.cjs.map +1 -0
- package/lib/cjs/parse/context/cli-context-builder.cjs +2 -0
- package/lib/cjs/parse/context/cli-context-builder.cjs.map +1 -0
- package/lib/cjs/parse/context/object-context-builder.cjs +2 -0
- package/lib/cjs/parse/context/object-context-builder.cjs.map +1 -0
- package/lib/cjs/parse/parser-utilities.cjs +2 -0
- package/lib/cjs/parse/parser-utilities.cjs.map +1 -0
- package/lib/cjs/parse/safe-parse.cjs +2 -0
- package/lib/cjs/parse/safe-parse.cjs.map +1 -0
- package/lib/cjs/parse/validation/validate-context.cjs +2 -0
- package/lib/cjs/parse/validation/validate-context.cjs.map +1 -0
- package/lib/cjs/parse/validation/validators/arguments.cjs +2 -0
- package/lib/cjs/parse/validation/validators/arguments.cjs.map +1 -0
- package/lib/cjs/parse/validation/validators/conflict.cjs +2 -0
- package/lib/cjs/parse/validation/validators/conflict.cjs.map +1 -0
- package/lib/cjs/parse/validation/validators/exclusive.cjs +2 -0
- package/lib/cjs/parse/validation/validators/exclusive.cjs.map +1 -0
- package/lib/cjs/parse/validation/validators/explicitly-passed.cjs +2 -0
- package/lib/cjs/parse/validation/validators/explicitly-passed.cjs.map +1 -0
- package/lib/cjs/parse/validation/validators/options.cjs +2 -0
- package/lib/cjs/parse/validation/validators/options.cjs.map +1 -0
- package/lib/cjs/parse/validation/validators/requires.cjs +2 -0
- package/lib/cjs/parse/validation/validators/requires.cjs.map +1 -0
- package/lib/cjs/utilities.cjs +2 -0
- package/lib/cjs/utilities.cjs.map +1 -0
- package/lib/esm/autocomplete-scripts/bash-autocomplete-script.js +2 -0
- package/lib/esm/autocomplete-scripts/bash-autocomplete-script.js.map +1 -0
- package/lib/esm/autocomplete-scripts/powershell-autocomplete-script.js +2 -0
- package/lib/esm/autocomplete-scripts/powershell-autocomplete-script.js.map +1 -0
- package/lib/esm/autocomplete-scripts/zsh-autocomplete-script.js +42 -0
- package/lib/esm/autocomplete-scripts/zsh-autocomplete-script.js.map +1 -0
- package/lib/esm/coerce/coerce-methods.js +2 -0
- package/lib/esm/coerce/coerce-methods.js.map +1 -0
- package/lib/esm/coerce/string-to-array.js +2 -0
- package/lib/esm/coerce/string-to-array.js.map +1 -0
- package/lib/esm/coerce/string-to-primitive.js +2 -0
- package/lib/esm/coerce/string-to-primitive.js.map +1 -0
- package/lib/esm/coerce/string-to-set.js +2 -0
- package/lib/esm/coerce/string-to-set.js.map +1 -0
- package/lib/esm/definitions/define-arguments.js +2 -0
- package/lib/esm/definitions/define-arguments.js.map +1 -0
- package/lib/esm/definitions/define-cli.js +2 -0
- package/lib/esm/definitions/define-cli.js.map +1 -0
- package/lib/esm/definitions/define-options.js +2 -0
- package/lib/esm/definitions/define-options.js.map +1 -0
- package/lib/esm/definitions/define-subcommand.js +2 -0
- package/lib/esm/definitions/define-subcommand.js.map +1 -0
- package/lib/esm/definitions/validate-cli-definition.js +2 -0
- package/lib/esm/definitions/validate-cli-definition.js.map +1 -0
- package/lib/esm/help-message/format-arguments.js +2 -0
- package/lib/esm/help-message/format-arguments.js.map +1 -0
- package/lib/esm/help-message/format-options.js +2 -0
- package/lib/esm/help-message/format-options.js.map +1 -0
- package/lib/esm/help-message/format-subcommands.js +2 -0
- package/lib/esm/help-message/format-subcommands.js.map +1 -0
- package/lib/esm/help-message/generate-for-cli.js +2 -0
- package/lib/esm/help-message/generate-for-cli.js.map +1 -0
- package/lib/esm/help-message/generate-for-subcommand.js +2 -0
- package/lib/esm/help-message/generate-for-subcommand.js.map +1 -0
- package/lib/esm/help-message/print-help.js +2 -0
- package/lib/esm/help-message/print-help.js.map +1 -0
- package/lib/esm/help-message/set-defaults.js +2 -0
- package/lib/esm/help-message/set-defaults.js.map +1 -0
- package/lib/esm/help-message/styles.js +2 -0
- package/lib/esm/help-message/styles.js.map +1 -0
- package/lib/esm/help-message/terminal-markdown.js +2 -0
- package/lib/esm/help-message/terminal-markdown.js.map +1 -0
- package/lib/esm/index.js +2 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/markdown/generate-markdown.js +2 -0
- package/lib/esm/markdown/generate-markdown.js.map +1 -0
- package/lib/esm/metadata/arguments-metadata.js +2 -0
- package/lib/esm/metadata/arguments-metadata.js.map +1 -0
- package/lib/esm/metadata/cli-metadata.js +2 -0
- package/lib/esm/metadata/cli-metadata.js.map +1 -0
- package/lib/esm/metadata/options-metadata.js +2 -0
- package/lib/esm/metadata/options-metadata.js.map +1 -0
- package/lib/esm/metadata/subcommands-metadata.js +2 -0
- package/lib/esm/metadata/subcommands-metadata.js.map +1 -0
- package/lib/esm/parse/context/cli-context-builder.js +2 -0
- package/lib/esm/parse/context/cli-context-builder.js.map +1 -0
- package/lib/esm/parse/context/object-context-builder.js +2 -0
- package/lib/esm/parse/context/object-context-builder.js.map +1 -0
- package/lib/esm/parse/parser-utilities.js +2 -0
- package/lib/esm/parse/parser-utilities.js.map +1 -0
- package/lib/esm/parse/safe-parse.js +2 -0
- package/lib/esm/parse/safe-parse.js.map +1 -0
- package/lib/esm/parse/validation/validate-context.js +2 -0
- package/lib/esm/parse/validation/validate-context.js.map +1 -0
- package/lib/esm/parse/validation/validators/arguments.js +2 -0
- package/lib/esm/parse/validation/validators/arguments.js.map +1 -0
- package/lib/esm/parse/validation/validators/conflict.js +2 -0
- package/lib/esm/parse/validation/validators/conflict.js.map +1 -0
- package/lib/esm/parse/validation/validators/exclusive.js +2 -0
- package/lib/esm/parse/validation/validators/exclusive.js.map +1 -0
- package/lib/esm/parse/validation/validators/explicitly-passed.js +2 -0
- package/lib/esm/parse/validation/validators/explicitly-passed.js.map +1 -0
- package/lib/esm/parse/validation/validators/options.js +2 -0
- package/lib/esm/parse/validation/validators/options.js.map +1 -0
- package/lib/esm/parse/validation/validators/requires.js +2 -0
- package/lib/esm/parse/validation/validators/requires.js.map +1 -0
- package/lib/esm/utilities.js +2 -0
- package/lib/esm/utilities.js.map +1 -0
- package/lib/iife/index.js +2 -0
- package/lib/iife/index.js.map +1 -0
- package/lib/mjs/autocomplete-scripts/bash-autocomplete-script.mjs +2 -0
- package/lib/mjs/autocomplete-scripts/bash-autocomplete-script.mjs.map +1 -0
- package/lib/mjs/autocomplete-scripts/powershell-autocomplete-script.mjs +2 -0
- package/lib/mjs/autocomplete-scripts/powershell-autocomplete-script.mjs.map +1 -0
- package/lib/mjs/autocomplete-scripts/zsh-autocomplete-script.mjs +42 -0
- package/lib/mjs/autocomplete-scripts/zsh-autocomplete-script.mjs.map +1 -0
- package/lib/mjs/coerce/coerce-methods.mjs +2 -0
- package/lib/mjs/coerce/coerce-methods.mjs.map +1 -0
- package/lib/mjs/coerce/string-to-array.mjs +2 -0
- package/lib/mjs/coerce/string-to-array.mjs.map +1 -0
- package/lib/mjs/coerce/string-to-primitive.mjs +2 -0
- package/lib/mjs/coerce/string-to-primitive.mjs.map +1 -0
- package/lib/mjs/coerce/string-to-set.mjs +2 -0
- package/lib/mjs/coerce/string-to-set.mjs.map +1 -0
- package/lib/mjs/definitions/define-arguments.mjs +2 -0
- package/lib/mjs/definitions/define-arguments.mjs.map +1 -0
- package/lib/mjs/definitions/define-cli.mjs +2 -0
- package/lib/mjs/definitions/define-cli.mjs.map +1 -0
- package/lib/mjs/definitions/define-options.mjs +2 -0
- package/lib/mjs/definitions/define-options.mjs.map +1 -0
- package/lib/mjs/definitions/define-subcommand.mjs +2 -0
- package/lib/mjs/definitions/define-subcommand.mjs.map +1 -0
- package/lib/mjs/definitions/validate-cli-definition.mjs +2 -0
- package/lib/mjs/definitions/validate-cli-definition.mjs.map +1 -0
- package/lib/mjs/help-message/format-arguments.mjs +2 -0
- package/lib/mjs/help-message/format-arguments.mjs.map +1 -0
- package/lib/mjs/help-message/format-options.mjs +2 -0
- package/lib/mjs/help-message/format-options.mjs.map +1 -0
- package/lib/mjs/help-message/format-subcommands.mjs +2 -0
- package/lib/mjs/help-message/format-subcommands.mjs.map +1 -0
- package/lib/mjs/help-message/generate-for-cli.mjs +2 -0
- package/lib/mjs/help-message/generate-for-cli.mjs.map +1 -0
- package/lib/mjs/help-message/generate-for-subcommand.mjs +2 -0
- package/lib/mjs/help-message/generate-for-subcommand.mjs.map +1 -0
- package/lib/mjs/help-message/print-help.mjs +2 -0
- package/lib/mjs/help-message/print-help.mjs.map +1 -0
- package/lib/mjs/help-message/set-defaults.mjs +2 -0
- package/lib/mjs/help-message/set-defaults.mjs.map +1 -0
- package/lib/mjs/help-message/styles.mjs +2 -0
- package/lib/mjs/help-message/styles.mjs.map +1 -0
- package/lib/mjs/help-message/terminal-markdown.mjs +2 -0
- package/lib/mjs/help-message/terminal-markdown.mjs.map +1 -0
- package/lib/mjs/index.mjs +2 -0
- package/lib/mjs/index.mjs.map +1 -0
- package/lib/mjs/markdown/generate-markdown.mjs +2 -0
- package/lib/mjs/markdown/generate-markdown.mjs.map +1 -0
- package/lib/mjs/metadata/arguments-metadata.mjs +2 -0
- package/lib/mjs/metadata/arguments-metadata.mjs.map +1 -0
- package/lib/mjs/metadata/cli-metadata.mjs +2 -0
- package/lib/mjs/metadata/cli-metadata.mjs.map +1 -0
- package/lib/mjs/metadata/options-metadata.mjs +2 -0
- package/lib/mjs/metadata/options-metadata.mjs.map +1 -0
- package/lib/mjs/metadata/subcommands-metadata.mjs +2 -0
- package/lib/mjs/metadata/subcommands-metadata.mjs.map +1 -0
- package/lib/mjs/parse/context/cli-context-builder.mjs +2 -0
- package/lib/mjs/parse/context/cli-context-builder.mjs.map +1 -0
- package/lib/mjs/parse/context/object-context-builder.mjs +2 -0
- package/lib/mjs/parse/context/object-context-builder.mjs.map +1 -0
- package/lib/mjs/parse/parser-utilities.mjs +2 -0
- package/lib/mjs/parse/parser-utilities.mjs.map +1 -0
- package/lib/mjs/parse/safe-parse.mjs +2 -0
- package/lib/mjs/parse/safe-parse.mjs.map +1 -0
- package/lib/mjs/parse/validation/validate-context.mjs +2 -0
- package/lib/mjs/parse/validation/validate-context.mjs.map +1 -0
- package/lib/mjs/parse/validation/validators/arguments.mjs +2 -0
- package/lib/mjs/parse/validation/validators/arguments.mjs.map +1 -0
- package/lib/mjs/parse/validation/validators/conflict.mjs +2 -0
- package/lib/mjs/parse/validation/validators/conflict.mjs.map +1 -0
- package/lib/mjs/parse/validation/validators/exclusive.mjs +2 -0
- package/lib/mjs/parse/validation/validators/exclusive.mjs.map +1 -0
- package/lib/mjs/parse/validation/validators/explicitly-passed.mjs +2 -0
- package/lib/mjs/parse/validation/validators/explicitly-passed.mjs.map +1 -0
- package/lib/mjs/parse/validation/validators/options.mjs +2 -0
- package/lib/mjs/parse/validation/validators/options.mjs.map +1 -0
- package/lib/mjs/parse/validation/validators/requires.mjs +2 -0
- package/lib/mjs/parse/validation/validators/requires.mjs.map +1 -0
- package/lib/mjs/utilities.mjs +2 -0
- package/lib/mjs/utilities.mjs.map +1 -0
- package/lib/typescript/autocomplete-scripts/bash-autocomplete-script.d.ts +2 -2
- package/lib/typescript/autocomplete-scripts/bash-autocomplete-script.d.ts.map +1 -1
- package/lib/typescript/autocomplete-scripts/powershell-autocomplete-script.d.ts +2 -2
- package/lib/typescript/autocomplete-scripts/powershell-autocomplete-script.d.ts.map +1 -1
- package/lib/typescript/autocomplete-scripts/zsh-autocomplete-script.d.ts +2 -2
- package/lib/typescript/autocomplete-scripts/zsh-autocomplete-script.d.ts.map +1 -1
- package/lib/typescript/coerce/coerce-methods.d.ts +20 -0
- package/lib/typescript/coerce/coerce-methods.d.ts.map +1 -0
- package/lib/typescript/coerce/string-to-array.d.ts +6 -0
- package/lib/typescript/coerce/string-to-array.d.ts.map +1 -0
- package/lib/typescript/coerce/string-to-primitive.d.ts +5 -0
- package/lib/typescript/coerce/string-to-primitive.d.ts.map +1 -0
- package/lib/typescript/coerce/string-to-set.d.ts +6 -0
- package/lib/typescript/coerce/string-to-set.d.ts.map +1 -0
- package/lib/typescript/definitions/define-arguments.d.ts +7 -0
- package/lib/typescript/definitions/define-arguments.d.ts.map +1 -0
- package/lib/typescript/definitions/define-cli.d.ts +24 -0
- package/lib/typescript/definitions/define-cli.d.ts.map +1 -0
- package/lib/typescript/definitions/define-options.d.ts +7 -0
- package/lib/typescript/definitions/define-options.d.ts.map +1 -0
- package/lib/typescript/definitions/define-subcommand.d.ts +17 -0
- package/lib/typescript/definitions/define-subcommand.d.ts.map +1 -0
- package/lib/typescript/definitions/validate-cli-definition.d.ts +4 -0
- package/lib/typescript/definitions/validate-cli-definition.d.ts.map +1 -0
- package/lib/typescript/help-message/format-arguments.d.ts +3 -3
- package/lib/typescript/help-message/format-arguments.d.ts.map +1 -1
- package/lib/typescript/help-message/format-options.d.ts +3 -3
- package/lib/typescript/help-message/format-options.d.ts.map +1 -1
- package/lib/typescript/help-message/format-subcommands.d.ts +3 -3
- package/lib/typescript/help-message/format-subcommands.d.ts.map +1 -1
- package/lib/typescript/help-message/generate-for-cli.d.ts +8 -0
- package/lib/typescript/help-message/generate-for-cli.d.ts.map +1 -0
- package/lib/typescript/help-message/generate-for-subcommand.d.ts +4 -0
- package/lib/typescript/help-message/generate-for-subcommand.d.ts.map +1 -0
- package/lib/typescript/help-message/print-help.d.ts +5 -0
- package/lib/typescript/help-message/print-help.d.ts.map +1 -0
- package/lib/typescript/help-message/set-defaults.d.ts +4 -0
- package/lib/typescript/help-message/set-defaults.d.ts.map +1 -0
- package/lib/typescript/help-message/styles.d.ts +30 -106
- package/lib/typescript/help-message/styles.d.ts.map +1 -1
- package/lib/typescript/help-message/terminal-markdown.d.ts +3 -0
- package/lib/typescript/help-message/terminal-markdown.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +23 -35
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/markdown/generate-markdown.d.ts +2 -2
- package/lib/typescript/markdown/generate-markdown.d.ts.map +1 -1
- package/lib/typescript/metadata/arguments-metadata.d.ts +4 -0
- package/lib/typescript/metadata/arguments-metadata.d.ts.map +1 -0
- package/lib/typescript/metadata/cli-metadata.d.ts +4 -0
- package/lib/typescript/metadata/cli-metadata.d.ts.map +1 -0
- package/lib/typescript/metadata/options-metadata.d.ts +4 -0
- package/lib/typescript/metadata/options-metadata.d.ts.map +1 -0
- package/lib/typescript/metadata/subcommands-metadata.d.ts +4 -0
- package/lib/typescript/metadata/subcommands-metadata.d.ts.map +1 -0
- package/lib/typescript/parse/context/cli-context-builder.d.ts +9 -0
- package/lib/typescript/parse/context/cli-context-builder.d.ts.map +1 -0
- package/lib/typescript/parse/context/object-context-builder.d.ts +6 -0
- package/lib/typescript/parse/context/object-context-builder.d.ts.map +1 -0
- package/lib/typescript/{parser/parse/parser-helpers.d.ts → parse/parser-utilities.d.ts} +18 -9
- package/lib/typescript/parse/parser-utilities.d.ts.map +1 -0
- package/lib/typescript/parse/safe-parse.d.ts +5 -0
- package/lib/typescript/parse/safe-parse.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validate-context.d.ts +6 -0
- package/lib/typescript/parse/validation/validate-context.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validators/arguments.d.ts +12 -0
- package/lib/typescript/parse/validation/validators/arguments.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validators/conflict.d.ts +16 -0
- package/lib/typescript/parse/validation/validators/conflict.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validators/exclusive.d.ts +16 -0
- package/lib/typescript/parse/validation/validators/exclusive.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validators/explicitly-passed.d.ts +5 -0
- package/lib/typescript/parse/validation/validators/explicitly-passed.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validators/options.d.ts +12 -0
- package/lib/typescript/parse/validation/validators/options.d.ts.map +1 -0
- package/lib/typescript/parse/validation/validators/requires.d.ts +18 -0
- package/lib/typescript/parse/validation/validators/requires.d.ts.map +1 -0
- package/lib/typescript/types/context-types.d.ts +135 -0
- package/lib/typescript/types/context-types.d.ts.map +1 -0
- package/lib/typescript/types/definitions-types.d.ts +294 -0
- package/lib/typescript/types/definitions-types.d.ts.map +1 -0
- package/lib/typescript/types/help-message-types.d.ts +134 -0
- package/lib/typescript/types/help-message-types.d.ts.map +1 -0
- package/lib/typescript/types/io-types.d.ts +96 -0
- package/lib/typescript/types/io-types.d.ts.map +1 -0
- package/lib/typescript/types/metadata-types.d.ts +75 -0
- package/lib/typescript/types/metadata-types.d.ts.map +1 -0
- package/lib/typescript/types/schema-types.d.ts +6 -0
- package/lib/typescript/types/schema-types.d.ts.map +1 -0
- package/lib/typescript/types/types.d.ts +61 -0
- package/lib/typescript/types/types.d.ts.map +1 -0
- package/lib/typescript/types/utilities-types.d.ts +17 -0
- package/lib/typescript/types/utilities-types.d.ts.map +1 -0
- package/lib/typescript/utilities.d.ts +24 -10
- package/lib/typescript/utilities.d.ts.map +1 -1
- package/package.json +29 -26
- package/src/autocomplete-scripts/bash-autocomplete-script.ts +13 -9
- package/src/autocomplete-scripts/powershell-autocomplete-script.ts +21 -13
- package/src/autocomplete-scripts/zsh-autocomplete-script.ts +27 -23
- package/src/coerce/coerce-methods.ts +75 -0
- package/src/coerce/string-to-array.ts +18 -0
- package/src/coerce/string-to-primitive.ts +31 -0
- package/src/coerce/string-to-set.ts +15 -0
- package/src/definitions/define-arguments.ts +10 -0
- package/src/definitions/define-cli.ts +105 -0
- package/src/definitions/define-options.ts +12 -0
- package/src/definitions/define-subcommand.ts +57 -0
- package/src/definitions/validate-cli-definition.ts +331 -0
- package/src/help-message/format-arguments.ts +57 -33
- package/src/help-message/format-options.ts +59 -34
- package/src/help-message/format-subcommands.ts +43 -21
- package/src/help-message/generate-for-cli.ts +114 -0
- package/src/help-message/generate-for-subcommand.ts +32 -0
- package/src/help-message/print-help.ts +13 -0
- package/src/help-message/set-defaults.ts +34 -0
- package/src/help-message/styles.ts +148 -103
- package/src/help-message/terminal-markdown.ts +147 -0
- package/src/index.ts +28 -97
- package/src/markdown/generate-markdown.ts +47 -58
- package/src/metadata/arguments-metadata.ts +28 -0
- package/src/metadata/cli-metadata.ts +26 -0
- package/src/metadata/options-metadata.ts +38 -0
- package/src/metadata/subcommands-metadata.ts +35 -0
- package/src/parse/context/cli-context-builder.ts +246 -0
- package/src/parse/context/object-context-builder.ts +63 -0
- package/src/{parser/parse/parser-helpers.ts → parse/parser-utilities.ts} +46 -25
- package/src/parse/safe-parse.ts +76 -0
- package/src/parse/validation/validate-context.ts +23 -0
- package/src/parse/validation/validators/arguments.ts +59 -0
- package/src/parse/validation/validators/conflict.ts +68 -0
- package/src/parse/validation/validators/exclusive.ts +70 -0
- package/src/parse/validation/validators/explicitly-passed.ts +15 -0
- package/src/parse/validation/validators/options.ts +59 -0
- package/src/parse/validation/validators/requires.ts +82 -0
- package/src/types/context-types.ts +171 -0
- package/src/types/definitions-types.ts +340 -0
- package/src/types/help-message-types.ts +153 -0
- package/src/types/io-types.ts +131 -0
- package/src/types/metadata-types.ts +104 -0
- package/src/types/schema-types.ts +9 -0
- package/src/types/types.ts +72 -0
- package/src/types/utilities-types.ts +26 -0
- package/src/utilities.ts +200 -23
- package/lib/commonjs/autocomplete-scripts/bash-autocomplete-script.cjs +0 -42
- package/lib/commonjs/autocomplete-scripts/bash-autocomplete-script.cjs.map +0 -1
- package/lib/commonjs/autocomplete-scripts/powershell-autocomplete-script.cjs +0 -31
- package/lib/commonjs/autocomplete-scripts/powershell-autocomplete-script.cjs.map +0 -1
- package/lib/commonjs/autocomplete-scripts/zsh-autocomplete-script.cjs +0 -41
- package/lib/commonjs/autocomplete-scripts/zsh-autocomplete-script.cjs.map +0 -1
- package/lib/commonjs/help-message/format-arguments.cjs +0 -1
- package/lib/commonjs/help-message/format-arguments.cjs.map +0 -1
- package/lib/commonjs/help-message/format-cli.cjs +0 -1
- package/lib/commonjs/help-message/format-cli.cjs.map +0 -1
- package/lib/commonjs/help-message/format-options.cjs +0 -1
- package/lib/commonjs/help-message/format-options.cjs.map +0 -1
- package/lib/commonjs/help-message/format-subcommands.cjs +0 -1
- package/lib/commonjs/help-message/format-subcommands.cjs.map +0 -1
- package/lib/commonjs/help-message/styles.cjs +0 -1
- package/lib/commonjs/help-message/styles.cjs.map +0 -1
- package/lib/commonjs/index.cjs +0 -1
- package/lib/commonjs/index.cjs.map +0 -1
- package/lib/commonjs/markdown/generate-markdown.cjs +0 -1
- package/lib/commonjs/markdown/generate-markdown.cjs.map +0 -1
- package/lib/commonjs/metadata/get-arguments-metadata.cjs +0 -1
- package/lib/commonjs/metadata/get-arguments-metadata.cjs.map +0 -1
- package/lib/commonjs/metadata/get-cli-metadata.cjs +0 -1
- package/lib/commonjs/metadata/get-cli-metadata.cjs.map +0 -1
- package/lib/commonjs/metadata/get-options-metadata.cjs +0 -1
- package/lib/commonjs/metadata/get-options-metadata.cjs.map +0 -1
- package/lib/commonjs/metadata/get-subcommands-metadata.cjs +0 -1
- package/lib/commonjs/metadata/get-subcommands-metadata.cjs.map +0 -1
- package/lib/commonjs/parser/parse/parse.cjs +0 -1
- package/lib/commonjs/parser/parse/parse.cjs.map +0 -1
- package/lib/commonjs/parser/parse/parser-helpers.cjs +0 -1
- package/lib/commonjs/parser/parse/parser-helpers.cjs.map +0 -1
- package/lib/commonjs/parser/safe-parse.cjs +0 -1
- package/lib/commonjs/parser/safe-parse.cjs.map +0 -1
- package/lib/commonjs/parser/unsafe-parse.cjs +0 -1
- package/lib/commonjs/parser/unsafe-parse.cjs.map +0 -1
- package/lib/commonjs/parser/validate/validate-type.cjs +0 -1
- package/lib/commonjs/parser/validate/validate-type.cjs.map +0 -1
- package/lib/commonjs/parser/validate/validate.cjs +0 -1
- package/lib/commonjs/parser/validate/validate.cjs.map +0 -1
- package/lib/commonjs/utilities.cjs +0 -1
- package/lib/commonjs/utilities.cjs.map +0 -1
- package/lib/commonjs/zod-utilities.cjs +0 -1
- package/lib/commonjs/zod-utilities.cjs.map +0 -1
- package/lib/module/autocomplete-scripts/bash-autocomplete-script.mjs +0 -42
- package/lib/module/autocomplete-scripts/bash-autocomplete-script.mjs.map +0 -1
- package/lib/module/autocomplete-scripts/powershell-autocomplete-script.mjs +0 -31
- package/lib/module/autocomplete-scripts/powershell-autocomplete-script.mjs.map +0 -1
- package/lib/module/autocomplete-scripts/zsh-autocomplete-script.mjs +0 -41
- package/lib/module/autocomplete-scripts/zsh-autocomplete-script.mjs.map +0 -1
- package/lib/module/help-message/format-arguments.mjs +0 -1
- package/lib/module/help-message/format-arguments.mjs.map +0 -1
- package/lib/module/help-message/format-cli.mjs +0 -1
- package/lib/module/help-message/format-cli.mjs.map +0 -1
- package/lib/module/help-message/format-options.mjs +0 -1
- package/lib/module/help-message/format-options.mjs.map +0 -1
- package/lib/module/help-message/format-subcommands.mjs +0 -1
- package/lib/module/help-message/format-subcommands.mjs.map +0 -1
- package/lib/module/help-message/styles.mjs +0 -1
- package/lib/module/help-message/styles.mjs.map +0 -1
- package/lib/module/index.mjs +0 -1
- package/lib/module/index.mjs.map +0 -1
- package/lib/module/markdown/generate-markdown.mjs +0 -1
- package/lib/module/markdown/generate-markdown.mjs.map +0 -1
- package/lib/module/metadata/get-arguments-metadata.mjs +0 -1
- package/lib/module/metadata/get-arguments-metadata.mjs.map +0 -1
- package/lib/module/metadata/get-cli-metadata.mjs +0 -1
- package/lib/module/metadata/get-cli-metadata.mjs.map +0 -1
- package/lib/module/metadata/get-options-metadata.mjs +0 -1
- package/lib/module/metadata/get-options-metadata.mjs.map +0 -1
- package/lib/module/metadata/get-subcommands-metadata.mjs +0 -1
- package/lib/module/metadata/get-subcommands-metadata.mjs.map +0 -1
- package/lib/module/parser/parse/parse.mjs +0 -1
- package/lib/module/parser/parse/parse.mjs.map +0 -1
- package/lib/module/parser/parse/parser-helpers.mjs +0 -1
- package/lib/module/parser/parse/parser-helpers.mjs.map +0 -1
- package/lib/module/parser/safe-parse.mjs +0 -1
- package/lib/module/parser/safe-parse.mjs.map +0 -1
- package/lib/module/parser/unsafe-parse.mjs +0 -1
- package/lib/module/parser/unsafe-parse.mjs.map +0 -1
- package/lib/module/parser/validate/validate-type.mjs +0 -1
- package/lib/module/parser/validate/validate-type.mjs.map +0 -1
- package/lib/module/parser/validate/validate.mjs +0 -1
- package/lib/module/parser/validate/validate.mjs.map +0 -1
- package/lib/module/utilities.mjs +0 -1
- package/lib/module/utilities.mjs.map +0 -1
- package/lib/module/zod-utilities.mjs +0 -1
- package/lib/module/zod-utilities.mjs.map +0 -1
- package/lib/typescript/help-message/format-cli.d.ts +0 -6
- package/lib/typescript/help-message/format-cli.d.ts.map +0 -1
- package/lib/typescript/metadata/get-arguments-metadata.d.ts +0 -4
- package/lib/typescript/metadata/get-arguments-metadata.d.ts.map +0 -1
- package/lib/typescript/metadata/get-cli-metadata.d.ts +0 -4
- package/lib/typescript/metadata/get-cli-metadata.d.ts.map +0 -1
- package/lib/typescript/metadata/get-options-metadata.d.ts +0 -4
- package/lib/typescript/metadata/get-options-metadata.d.ts.map +0 -1
- package/lib/typescript/metadata/get-subcommands-metadata.d.ts +0 -4
- package/lib/typescript/metadata/get-subcommands-metadata.d.ts.map +0 -1
- package/lib/typescript/metadata/metadata-types.d.ts +0 -80
- package/lib/typescript/metadata/metadata-types.d.ts.map +0 -1
- package/lib/typescript/parser/parse/parse-types.d.ts +0 -85
- package/lib/typescript/parser/parse/parse-types.d.ts.map +0 -1
- package/lib/typescript/parser/parse/parse.d.ts +0 -4
- package/lib/typescript/parser/parse/parse.d.ts.map +0 -1
- package/lib/typescript/parser/parse/parser-helpers.d.ts.map +0 -1
- package/lib/typescript/parser/safe-parse.d.ts +0 -4
- package/lib/typescript/parser/safe-parse.d.ts.map +0 -1
- package/lib/typescript/parser/unsafe-parse.d.ts +0 -4
- package/lib/typescript/parser/unsafe-parse.d.ts.map +0 -1
- package/lib/typescript/parser/validate/validate-type.d.ts +0 -22
- package/lib/typescript/parser/validate/validate-type.d.ts.map +0 -1
- package/lib/typescript/parser/validate/validate.d.ts +0 -11
- package/lib/typescript/parser/validate/validate.d.ts.map +0 -1
- package/lib/typescript/types.d.ts +0 -294
- package/lib/typescript/types.d.ts.map +0 -1
- package/lib/typescript/zod-utilities.d.ts +0 -28
- package/lib/typescript/zod-utilities.d.ts.map +0 -1
- package/src/help-message/format-cli.ts +0 -141
- package/src/metadata/get-arguments-metadata.ts +0 -25
- package/src/metadata/get-cli-metadata.ts +0 -23
- package/src/metadata/get-options-metadata.ts +0 -35
- package/src/metadata/get-subcommands-metadata.ts +0 -32
- package/src/metadata/metadata-types.ts +0 -114
- package/src/parser/parse/parse-types.ts +0 -89
- package/src/parser/parse/parse.ts +0 -230
- package/src/parser/safe-parse.ts +0 -103
- package/src/parser/unsafe-parse.ts +0 -98
- package/src/parser/validate/validate-type.ts +0 -21
- package/src/parser/validate/validate.ts +0 -66
- package/src/types.ts +0 -365
- package/src/zod-utilities.ts +0 -214
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { Context, ContextWide } from "./context-types.ts";
|
|
2
|
+
import type { Argument, Cli, Option, Subcommand } from "./definitions-types.ts";
|
|
3
|
+
import type { InferSchemaInputType, InferSchemaOutputType } from "./schema-types.ts";
|
|
4
|
+
import type { Prettify, ToOptional, AllowUndefinedIfOptional as AddUndefinedIfAllOptional } from "./utilities-types.ts";
|
|
5
|
+
|
|
6
|
+
/** Output options type */
|
|
7
|
+
type OptionsOutputType<T extends Record<string, Option>> = Prettify<
|
|
8
|
+
ToOptional<{ [K in keyof T]: InferSchemaOutputType<T[K]["schema"]> }>
|
|
9
|
+
>;
|
|
10
|
+
|
|
11
|
+
/** Input options type */
|
|
12
|
+
type OptionsInputType<T extends Record<string, Option>> = Prettify<
|
|
13
|
+
ToOptional<{ [K in keyof T]: InferSchemaInputType<T[K]["schema"]> }>
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
/** Output arguments type */
|
|
17
|
+
type ArgumentsOutputType<T extends Record<string, Argument>> = Prettify<
|
|
18
|
+
ToOptional<{ [K in keyof T]: InferSchemaOutputType<T[K]["schema"]> }>
|
|
19
|
+
>;
|
|
20
|
+
|
|
21
|
+
/** Input arguments type */
|
|
22
|
+
type ArgumentsInputType<T extends Record<string, Argument>> = Prettify<
|
|
23
|
+
ToOptional<{ [K in keyof T]: InferSchemaInputType<T[K]["schema"]> }>
|
|
24
|
+
>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* - Infer options output type.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const myCommand = defineSubcommand({ name: "my-command", options: [...] });
|
|
31
|
+
* type MyCommandOptionsOutput = InferOptionsOutputType<typeof myCommand>;
|
|
32
|
+
*/
|
|
33
|
+
export type InferOptionsOutputType<T extends Cli | Subcommand> =
|
|
34
|
+
T["options"] extends Record<string, Option> ? OptionsOutputType<T["options"]> : undefined;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* - Infer arguments output type.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* const myCommand = defineSubcommand({ name: "my-command", arguments: [...] });
|
|
41
|
+
* type MyCommandArgumentsOutput = InferArgumentsOutputType<typeof myCommand>;
|
|
42
|
+
*/
|
|
43
|
+
export type InferArgumentsOutputType<T extends Cli | Subcommand> =
|
|
44
|
+
T["arguments"] extends Record<string, Argument> ? ArgumentsOutputType<T["arguments"]> : undefined;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* - Infer arguments input type.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* const myCommand = defineSubcommand({ name: "my-command", arguments: [...] });
|
|
51
|
+
* type MyCommandArgumentsInput = InferArgumentsInputType<typeof myCommand>;
|
|
52
|
+
*/
|
|
53
|
+
export type InferArgumentsInputType<T extends Cli | Subcommand> =
|
|
54
|
+
T["arguments"] extends Record<string, Argument> ? ArgumentsInputType<T["arguments"]> : undefined;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* - Infer options input type.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* const myCommand = defineSubcommand({ name: "my-command", options: [...] });
|
|
61
|
+
* type MyCommandOptionsInput = inferOptionsInputType<typeof myCommand>;
|
|
62
|
+
*/
|
|
63
|
+
export type inferOptionsInputType<T extends Cli | Subcommand> =
|
|
64
|
+
T["options"] extends Record<string, Option> ? OptionsInputType<T["options"]> : undefined;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* - Infer options, arguments, and positionals input types from the CLI/subcommand definition.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* const myCommand = defineSubcommand({ name: "my-command", ... });
|
|
71
|
+
* type MyCommandInput = InferInputType<typeof myCommand>;
|
|
72
|
+
*/
|
|
73
|
+
export type InferInputType<T extends Cli | Subcommand> = Prettify<
|
|
74
|
+
// Add undefined if all properties are optional
|
|
75
|
+
AddUndefinedIfAllOptional<
|
|
76
|
+
// Make properties that can be undefined optional
|
|
77
|
+
ToOptional<{
|
|
78
|
+
positionals: T["allowPositionals"] extends true ? string[] : undefined;
|
|
79
|
+
|
|
80
|
+
options: T["options"] extends Record<string, Option>
|
|
81
|
+
? // Add undefined if all properties are optional
|
|
82
|
+
AddUndefinedIfAllOptional<
|
|
83
|
+
// Options types as record
|
|
84
|
+
OptionsInputType<T["options"]>
|
|
85
|
+
>
|
|
86
|
+
: undefined;
|
|
87
|
+
|
|
88
|
+
arguments: T["arguments"] extends Record<string, Argument>
|
|
89
|
+
? // Add undefined if all properties are optional
|
|
90
|
+
AddUndefinedIfAllOptional<
|
|
91
|
+
// Arguments types as record
|
|
92
|
+
ArgumentsInputType<T["arguments"]>
|
|
93
|
+
>
|
|
94
|
+
: undefined;
|
|
95
|
+
}>
|
|
96
|
+
>
|
|
97
|
+
>;
|
|
98
|
+
|
|
99
|
+
export interface InputTypeWide {
|
|
100
|
+
arguments?: Record<string, unknown>;
|
|
101
|
+
options?: Record<string, unknown>;
|
|
102
|
+
positionals?: string[];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* - Infer schema output type.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* const myCommand = defineSubcommand({ name: "my-command", ... });
|
|
110
|
+
* type MyCommandOutput = InferOutputType<typeof myCommand>;
|
|
111
|
+
*/
|
|
112
|
+
export type InferOutputType<T extends Cli | Subcommand> = Prettify<{
|
|
113
|
+
subcommand: "name" extends keyof T ? T["name"] : undefined;
|
|
114
|
+
options: T["options"] extends Record<string, Option> ? OptionsOutputType<T["options"]> : never;
|
|
115
|
+
arguments: T["arguments"] extends Record<string, Argument> ? ArgumentsOutputType<T["arguments"]> : never;
|
|
116
|
+
positionals: T["allowPositionals"] extends true ? string[] : never;
|
|
117
|
+
context: Context<[T]>;
|
|
118
|
+
}>;
|
|
119
|
+
|
|
120
|
+
/** Same as `InferOutputType` but for multiple subcommands/cli */
|
|
121
|
+
export type OutputType<S extends readonly (Cli | Subcommand)[]> = {
|
|
122
|
+
[K in keyof S]: InferOutputType<S[K]>;
|
|
123
|
+
}[number];
|
|
124
|
+
|
|
125
|
+
export interface OutputTypeWide {
|
|
126
|
+
subcommand: string | undefined;
|
|
127
|
+
positionals?: string[];
|
|
128
|
+
arguments?: Record<string, unknown>;
|
|
129
|
+
options?: Record<string, unknown>;
|
|
130
|
+
context: ContextWide;
|
|
131
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { SchemaType } from "./schema-types.ts";
|
|
2
|
+
|
|
3
|
+
interface MetadataBase {
|
|
4
|
+
/** Empty string if not provided */
|
|
5
|
+
description: string;
|
|
6
|
+
|
|
7
|
+
/** Empty string if not provided */
|
|
8
|
+
descriptionMarkdown: string;
|
|
9
|
+
|
|
10
|
+
/** Empty string if not provided */
|
|
11
|
+
example: string;
|
|
12
|
+
|
|
13
|
+
/** Whether the metadata is hidden from the documentation. */
|
|
14
|
+
hidden: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface CliMetadata extends Omit<MetadataBase, "hidden"> {
|
|
18
|
+
/** The name of the cli program. */
|
|
19
|
+
name: string;
|
|
20
|
+
|
|
21
|
+
/** Empty string if not provided */
|
|
22
|
+
usage: string;
|
|
23
|
+
|
|
24
|
+
/** Whether the cli program allows positionals arguments. */
|
|
25
|
+
allowPositionals: boolean;
|
|
26
|
+
|
|
27
|
+
/** Empty array if not provided */
|
|
28
|
+
options: OptionMetadata[];
|
|
29
|
+
|
|
30
|
+
/** Empty array if not provided */
|
|
31
|
+
arguments: ArgumentMetadata[];
|
|
32
|
+
|
|
33
|
+
/** Empty array if not provided */
|
|
34
|
+
subcommands: SubcommandMetadata[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface SubcommandMetadata extends MetadataBase {
|
|
38
|
+
/** The subcommand name. */
|
|
39
|
+
name: string;
|
|
40
|
+
|
|
41
|
+
/** Empty array if not provided */
|
|
42
|
+
aliases: string[];
|
|
43
|
+
|
|
44
|
+
/** Empty string if not provided */
|
|
45
|
+
placeholder: string;
|
|
46
|
+
|
|
47
|
+
/** Empty string if not provided */
|
|
48
|
+
usage: string;
|
|
49
|
+
|
|
50
|
+
/** Whether the subcommand allows positionals arguments. */
|
|
51
|
+
allowPositionals: boolean;
|
|
52
|
+
|
|
53
|
+
/** Empty array if not provided */
|
|
54
|
+
options: OptionMetadata[];
|
|
55
|
+
|
|
56
|
+
/** Empty array if not provided */
|
|
57
|
+
arguments: ArgumentMetadata[];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface OptionMetadata extends MetadataBase {
|
|
61
|
+
/** The option name. */
|
|
62
|
+
name: string;
|
|
63
|
+
|
|
64
|
+
/** The option name as argument. E.g. `--option-name` */
|
|
65
|
+
nameAsArg: string;
|
|
66
|
+
|
|
67
|
+
/** Empty array if not provided. */
|
|
68
|
+
aliases: string[];
|
|
69
|
+
|
|
70
|
+
/** Empty array if not provided. E.g. `[--alias-name, ...]` */
|
|
71
|
+
aliasesAsArgs: string[];
|
|
72
|
+
|
|
73
|
+
/** Empty string if not provided */
|
|
74
|
+
placeholder: string;
|
|
75
|
+
|
|
76
|
+
/** The default value of the option. */
|
|
77
|
+
defaultValue: unknown;
|
|
78
|
+
|
|
79
|
+
/** Empty string if not provided. */
|
|
80
|
+
defaultValueAsString: string;
|
|
81
|
+
|
|
82
|
+
/** Is optional. */
|
|
83
|
+
optional: boolean;
|
|
84
|
+
|
|
85
|
+
/** Standard Schema V1. */
|
|
86
|
+
schema: SchemaType;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface ArgumentMetadata extends MetadataBase {
|
|
90
|
+
/** The argument name. */
|
|
91
|
+
name: string;
|
|
92
|
+
|
|
93
|
+
/** The default value of the argument. */
|
|
94
|
+
defaultValue: unknown;
|
|
95
|
+
|
|
96
|
+
/** The default value of the argument as string. */
|
|
97
|
+
defaultValueAsString: string;
|
|
98
|
+
|
|
99
|
+
/** Is optional. */
|
|
100
|
+
optional: boolean;
|
|
101
|
+
|
|
102
|
+
/** Standard Schema V1. */
|
|
103
|
+
schema: SchemaType;
|
|
104
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
|
|
3
|
+
export type SchemaType<T = unknown> = StandardSchemaV1<T>;
|
|
4
|
+
|
|
5
|
+
export type InferSchemaInputType<T extends SchemaType> = StandardSchemaV1.InferInput<T>;
|
|
6
|
+
|
|
7
|
+
export type InferSchemaOutputType<T extends SchemaType> = StandardSchemaV1.InferOutput<T>;
|
|
8
|
+
|
|
9
|
+
export type SchemaResult<T = unknown> = StandardSchemaV1.Result<T>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Cli, Subcommand } from "./definitions-types.ts";
|
|
2
|
+
import type { PrintHelpOptions } from "./help-message-types.ts";
|
|
3
|
+
import type { InferInputType, InputTypeWide, OutputType, OutputTypeWide } from "./io-types.ts";
|
|
4
|
+
|
|
5
|
+
type PrimitiveTypeNames = "string" | "number" | "boolean" | "object" | "unknown";
|
|
6
|
+
export type CoerceTypes = PrimitiveTypeNames | `${PrimitiveTypeNames}[]` | `set<${PrimitiveTypeNames}>` | (string & {});
|
|
7
|
+
|
|
8
|
+
export interface CoerceMethod<Value> {
|
|
9
|
+
(terminalInput: string): Value;
|
|
10
|
+
type?: CoerceTypes;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type GetSubcommandsNames<T extends Partial<Subcommand>> = T extends Cli
|
|
14
|
+
? T["subcommands"] extends infer S extends readonly [Subcommand, ...Subcommand[]]
|
|
15
|
+
? { [Index in keyof S]: S[Index] extends { name: string } ? S[Index]["name"] : never }[number]
|
|
16
|
+
: never
|
|
17
|
+
: never;
|
|
18
|
+
|
|
19
|
+
type Unsubscribe = () => void;
|
|
20
|
+
|
|
21
|
+
export interface AttachedMethods<T extends Cli | Subcommand> {
|
|
22
|
+
/**
|
|
23
|
+
* Add a handler to be called when the subcommand/cli is executed.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* const unsubscribe = cli.onExecute(result => console.log(result));
|
|
27
|
+
*/
|
|
28
|
+
onExecute: (handler: (data: OutputType<[T]>) => void) => Unsubscribe;
|
|
29
|
+
|
|
30
|
+
// Make the argument optional if it has undefined type
|
|
31
|
+
execute: InferInputType<T> extends infer InputType
|
|
32
|
+
? undefined extends InputType
|
|
33
|
+
? (input?: InputType) => void
|
|
34
|
+
: (input: InputType) => void
|
|
35
|
+
: never;
|
|
36
|
+
|
|
37
|
+
/** **WARNING**: This will only be available after the CLI schema has been created */
|
|
38
|
+
generateCliHelpMessage?: (options?: PrintHelpOptions) => string;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* **WARNING**: This will only be available after the CLI schema has been created
|
|
42
|
+
*
|
|
43
|
+
* @throws {Error} - When the subcommand is not found
|
|
44
|
+
*/
|
|
45
|
+
generateSubcommandHelpMessage?: (
|
|
46
|
+
subcommandName: GetSubcommandsNames<T> | (string & {}),
|
|
47
|
+
options?: PrintHelpOptions,
|
|
48
|
+
) => string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface AttachedMethodsWide {
|
|
52
|
+
onExecute: (handler: (data: OutputTypeWide) => void) => Unsubscribe;
|
|
53
|
+
execute: (input?: InputTypeWide) => void;
|
|
54
|
+
generateCliHelpMessage?: (options?: PrintHelpOptions) => void;
|
|
55
|
+
/** @throws {Error} - When the subcommand is not found */
|
|
56
|
+
generateSubcommandHelpMessage?: (subcommandName: string, options?: PrintHelpOptions) => void;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type CliOutputType<S extends Cli> =
|
|
60
|
+
| OutputType<[S]>
|
|
61
|
+
| (S["subcommands"] extends readonly [Subcommand, ...Subcommand[]] ? OutputType<S["subcommands"]> : never);
|
|
62
|
+
|
|
63
|
+
export type CliParseResult<S extends Cli> =
|
|
64
|
+
| { value: CliOutputType<S>; error?: undefined }
|
|
65
|
+
| { value?: never; error: Error };
|
|
66
|
+
|
|
67
|
+
export type CliParseResultWide = { value: OutputTypeWide; error?: undefined } | { value?: never; error: Error };
|
|
68
|
+
|
|
69
|
+
export interface ValidateMethods<S extends Cli> {
|
|
70
|
+
run(input: string | string[]): CliParseResult<S>;
|
|
71
|
+
runAsync(input: string | string[]): Promise<CliParseResult<S>>;
|
|
72
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** `{ some props } & { other props }` => `{ some props, other props }` */
|
|
2
|
+
export type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
3
|
+
|
|
4
|
+
/** Extract the undefined properties from an object */
|
|
5
|
+
export type UndefinedProperties<T> = { [P in keyof T]-?: undefined extends T[P] ? P : never }[keyof T];
|
|
6
|
+
|
|
7
|
+
/** Make undefined properties optional? */
|
|
8
|
+
export type ToOptional<T> = Partial<Pick<T, UndefinedProperties<T>>> &
|
|
9
|
+
Pick<T, Exclude<keyof T, UndefinedProperties<T>>>;
|
|
10
|
+
|
|
11
|
+
/** If every property in a record is optional, widen the type to `T | undefined`. */
|
|
12
|
+
export type AllowUndefinedIfOptional<T> = {
|
|
13
|
+
[K in keyof T]-?: object extends Pick<T, K> ? never : K;
|
|
14
|
+
}[keyof T] extends never
|
|
15
|
+
? T | undefined
|
|
16
|
+
: T;
|
|
17
|
+
|
|
18
|
+
/** Widen literal and tuples */
|
|
19
|
+
// prettier-ignore
|
|
20
|
+
export type Widen<T> =
|
|
21
|
+
T extends string ? string :
|
|
22
|
+
T extends number ? number :
|
|
23
|
+
T extends boolean ? boolean :
|
|
24
|
+
T extends readonly (infer U)[] ? Widen<U>[] :
|
|
25
|
+
T extends Set<infer U> ? Set<Widen<U>> :
|
|
26
|
+
T;
|
package/src/utilities.ts
CHANGED
|
@@ -1,21 +1,56 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Argument, Option, PreparedType } from "./types/definitions-types.ts";
|
|
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";
|
|
2
5
|
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*/
|
|
9
|
-
export function stringToBoolean(string: string): boolean | string {
|
|
10
|
-
if (string.toLowerCase() === "true") {
|
|
11
|
-
return true;
|
|
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");
|
|
12
11
|
}
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
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
|
+
}
|
|
16
49
|
}
|
|
50
|
+
}
|
|
17
51
|
|
|
18
|
-
|
|
52
|
+
export function toKebabCase(input: string): string {
|
|
53
|
+
return input.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
19
54
|
}
|
|
20
55
|
|
|
21
56
|
/**
|
|
@@ -68,10 +103,9 @@ export function indent(count: number) {
|
|
|
68
103
|
return " ".repeat(count);
|
|
69
104
|
}
|
|
70
105
|
|
|
71
|
-
/**
|
|
72
|
-
export function
|
|
73
|
-
|
|
74
|
-
return messages.join(" ");
|
|
106
|
+
/** Indents every line in the given text by the provided number of spaces. Empty lines are preserved. */
|
|
107
|
+
export function indentLines(text: string, spaces: number): string {
|
|
108
|
+
return text.replace(/\n/g, "\n" + indent(spaces));
|
|
75
109
|
}
|
|
76
110
|
|
|
77
111
|
export function stringifyValue(value: unknown): string {
|
|
@@ -93,7 +127,7 @@ export function stringifyValue(value: unknown): string {
|
|
|
93
127
|
/** Insert text at the end of the first line */
|
|
94
128
|
export function insertAtEndOfFirstLine(string: string, insert: string) {
|
|
95
129
|
const lines = string.split("\n");
|
|
96
|
-
lines[0] += " " + insert;
|
|
130
|
+
lines[0] += (lines[0] ? " " : "") + insert;
|
|
97
131
|
return lines.join("\n");
|
|
98
132
|
}
|
|
99
133
|
|
|
@@ -101,15 +135,19 @@ export function insertAtEndOfFirstLine(string: string, insert: string) {
|
|
|
101
135
|
export function subcommandPlaceholder(metadata: SubcommandMetadata): string {
|
|
102
136
|
let placeholder = metadata.placeholder;
|
|
103
137
|
|
|
104
|
-
if (
|
|
105
|
-
placeholder
|
|
138
|
+
if (placeholder) {
|
|
139
|
+
return placeholder;
|
|
106
140
|
}
|
|
107
141
|
|
|
108
|
-
if (
|
|
109
|
-
placeholder
|
|
142
|
+
if (metadata.options.length > 0) {
|
|
143
|
+
placeholder += (placeholder ? " " : "") + "[options]";
|
|
110
144
|
}
|
|
111
145
|
|
|
112
|
-
if (metadata.
|
|
146
|
+
if (metadata.arguments.length > 0) {
|
|
147
|
+
placeholder += (placeholder ? " " : "") + "<arguments>";
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (metadata.allowPositionals) {
|
|
113
151
|
placeholder += (placeholder ? " " : "") + "<positionals>";
|
|
114
152
|
}
|
|
115
153
|
|
|
@@ -119,3 +157,142 @@ export function subcommandPlaceholder(metadata: SubcommandMetadata): string {
|
|
|
119
157
|
|
|
120
158
|
return placeholder;
|
|
121
159
|
}
|
|
160
|
+
|
|
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
|
+
/**
|
|
241
|
+
* Escape HTML characters inside HTML tags in a Markdown string, but leave code blocks, inline code, and HTML comments
|
|
242
|
+
* unchanged.
|
|
243
|
+
*/
|
|
244
|
+
export function escapeHtmlTags(markdown: string): string {
|
|
245
|
+
const escapeMap: Record<string, string> = { "&": "&", "<": "<", ">": ">" };
|
|
246
|
+
|
|
247
|
+
// Captures:
|
|
248
|
+
// 1) fenced code blocks or inline code
|
|
249
|
+
// 2) HTML comments <!-- ... -->
|
|
250
|
+
// 3) other HTML tags like <b>, <div attr="x">, etc.
|
|
251
|
+
const re = /(```[\s\S]*?```|`[^`]*`)|(<!--[\s\S]*?-->)|(<[^>]+>)/g;
|
|
252
|
+
|
|
253
|
+
return markdown.replace(re, (fullMatch: string, code?: string, comment?: string, tag?: string) => {
|
|
254
|
+
if (code) return code;
|
|
255
|
+
if (comment) return comment;
|
|
256
|
+
if (!tag) return fullMatch;
|
|
257
|
+
|
|
258
|
+
return tag.replace(/[&<>]/g, ch => escapeMap[ch]);
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** Credits: https://github.com/chalk/ansi-regex */
|
|
263
|
+
function ansiRegex({ onlyFirst = false } = {}) {
|
|
264
|
+
// Valid string terminator sequences are BEL, ESC\, and 0x9c
|
|
265
|
+
const ST = String.raw`(?:\u0007|\u001B\u005C|\u009C)`;
|
|
266
|
+
|
|
267
|
+
// OSC sequences only: ESC ] ... ST (non-greedy until the first ST)
|
|
268
|
+
const osc = String.raw`(?:\u001B\][\s\S]*?${ST})`;
|
|
269
|
+
|
|
270
|
+
// CSI and related: ESC/C1, optional intermediates, optional params (supports ; and :) then final byte
|
|
271
|
+
const csi = String.raw`[\u001B\u009B][[\]()#;?]*(?:\d{1,4}(?:[;:]\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]`;
|
|
272
|
+
|
|
273
|
+
const pattern = `${osc}|${csi}`;
|
|
274
|
+
|
|
275
|
+
return new RegExp(pattern, onlyFirst ? undefined : "g");
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const regex = ansiRegex();
|
|
279
|
+
|
|
280
|
+
export function stripAnsi(string: string): string {
|
|
281
|
+
return string.replace(regex, "");
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export function findDuplicateStrings(values: readonly string[]): string[] {
|
|
285
|
+
const seen = new Set<string>();
|
|
286
|
+
const duplicates = new Set<string>();
|
|
287
|
+
|
|
288
|
+
for (const value of values) {
|
|
289
|
+
if (seen.has(value)) {
|
|
290
|
+
duplicates.add(value);
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
seen.add(value);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
return Array.from(duplicates);
|
|
298
|
+
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.generateBashAutocompleteScript=generateBashAutocompleteScript;var _parserHelpers=require("../parser/parse/parser-helpers.cjs");function generateBashAutocompleteScript(...parameters){const[cli,...subcommands]=parameters;const mappedCommands={};for(const subcommand of subcommands){mappedCommands[subcommand.name]={options:subcommand.options?.map(option=>(0,_parserHelpers.transformOptionToArgument)(option.name))??[],aliases:subcommand.aliases??[]}}let switchCase="";for(const[key,{options,aliases}]of Object.entries(mappedCommands)){switchCase+=` ${key}${aliases.length>0?"|":""}${aliases.join("|")})\n`;switchCase+=` opts="${options.join(" ")}"\n`;switchCase+=" ;;\n"}if(cli.options?.length){switchCase+=` "-"*)\n`;switchCase+=` opts="${cli.options.map(option=>(0,_parserHelpers.transformOptionToArgument)(option.name)).join(" ")}"\n`;switchCase+=" ;;\n"}return`# Auto-generated by zod-args-parser
|
|
2
|
-
|
|
3
|
-
_${cli.cliName}_autocomplete() {
|
|
4
|
-
local cur prev commands opts subcommand used_opts filtered_opts
|
|
5
|
-
|
|
6
|
-
cur="\${COMP_WORDS[COMP_CWORD]}"
|
|
7
|
-
prev="\${COMP_WORDS[COMP_CWORD-1]}"
|
|
8
|
-
subcommand="\${COMP_WORDS[1]}"
|
|
9
|
-
|
|
10
|
-
commands="${Object.keys(mappedCommands).join(" ")}"
|
|
11
|
-
|
|
12
|
-
case "$subcommand" in
|
|
13
|
-
${switchCase}
|
|
14
|
-
esac
|
|
15
|
-
|
|
16
|
-
used_opts=""
|
|
17
|
-
if [[ " \${commands[@]} " =~ " $subcommand " ]]; then
|
|
18
|
-
for word in "\${COMP_WORDS[@]:2}"; do
|
|
19
|
-
if [[ "$word" =~ ^- ]]; then
|
|
20
|
-
used_opts+=" $word"
|
|
21
|
-
fi
|
|
22
|
-
done
|
|
23
|
-
fi
|
|
24
|
-
|
|
25
|
-
if [[ -n "$opts" ]]; then
|
|
26
|
-
filtered_opts=""
|
|
27
|
-
for opt in $opts; do
|
|
28
|
-
if [[ ! " $used_opts " =~ " $opt " ]]; then
|
|
29
|
-
filtered_opts+="$opt "
|
|
30
|
-
fi
|
|
31
|
-
done
|
|
32
|
-
COMPREPLY=( $(compgen -W "$filtered_opts" -- "$cur") )
|
|
33
|
-
return
|
|
34
|
-
fi
|
|
35
|
-
|
|
36
|
-
if [[ "\${COMP_CWORD}" -eq 1 ]]; then
|
|
37
|
-
COMPREPLY=( $(compgen -W "$commands" -- "$cur") )
|
|
38
|
-
fi
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
complete -F _${cli.cliName}_autocomplete ${cli.cliName}
|
|
42
|
-
`}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_parserHelpers","require","generateBashAutocompleteScript","parameters","cli","subcommands","mappedCommands","subcommand","name","options","map","option","transformOptionToArgument","aliases","switchCase","key","Object","entries","length","join","cliName","keys"],"sourceRoot":"../../../src/autocomplete-scripts","sources":["bash-autocomplete-script.ts"],"sourcesContent":["import { transformOptionToArgument } from \"../parser/parse/parser-helpers.js\";\n\nimport type { Cli, Subcommand } from \"../types.js\";\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(...parameters: [Cli, ...Subcommand[]]): string {\n const [cli, ...subcommands] = parameters;\n\n type MappedCommands = Record<string, { options: string[]; aliases: string[] }>;\n\n const mappedCommands: MappedCommands = {};\n for (const subcommand of subcommands) {\n mappedCommands[subcommand.name] = {\n options: subcommand.options?.map(option => transformOptionToArgument(option.name)) ?? [],\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 (cli.options?.length) {\n switchCase += ` \"-\"*)\\n`;\n switchCase += ` opts=\"${cli.options.map(option => transformOptionToArgument(option.name)).join(\" \")}\"\\n`;\n switchCase += \" ;;\\n\";\n }\n\n return `# Auto-generated by zod-args-parser\n\n_${cli.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 _${cli.cliName}_autocomplete ${cli.cliName}\n`;\n}\n"],"mappings":"4IAAA,IAAAA,cAAA,CAAAC,OAAA,uCAYO,QAAS,CAAAC,8BAA8BA,CAAC,GAAGC,UAAkC,CAAU,CAC5F,KAAM,CAACC,GAAG,CAAE,GAAGC,WAAW,CAAC,CAAGF,UAAU,CAIxC,KAAM,CAAAG,cAA8B,CAAG,CAAC,CAAC,CACzC,IAAK,KAAM,CAAAC,UAAU,GAAI,CAAAF,WAAW,CAAE,CACpCC,cAAc,CAACC,UAAU,CAACC,IAAI,CAAC,CAAG,CAChCC,OAAO,CAAEF,UAAU,CAACE,OAAO,EAAEC,GAAG,CAACC,MAAM,EAAI,GAAAC,wCAAyB,EAACD,MAAM,CAACH,IAAI,CAAC,CAAC,EAAI,EAAE,CACxFK,OAAO,CAAEN,UAAU,CAACM,OAAO,EAAI,EACjC,CACF,CAEA,GAAI,CAAAC,UAAU,CAAG,EAAE,CACnB,IAAK,KAAM,CAACC,GAAG,CAAE,CAAEN,OAAO,CAAEI,OAAQ,CAAC,CAAC,EAAI,CAAAG,MAAM,CAACC,OAAO,CAACX,cAAc,CAAC,CAAE,CACxEQ,UAAU,EAAI,OAAOC,GAAG,GAAGF,OAAO,CAACK,MAAM,CAAG,CAAC,CAAG,GAAG,CAAG,EAAE,GAAGL,OAAO,CAACM,IAAI,CAAC,GAAG,CAAC,KAAK,CACjFL,UAAU,EAAI,eAAeL,OAAO,CAACU,IAAI,CAAC,GAAG,CAAC,KAAK,CACnDL,UAAU,EAAI,YAChB,CAEA,GAAIV,GAAG,CAACK,OAAO,EAAES,MAAM,CAAE,CACvBJ,UAAU,EAAI,aAAa,CAC3BA,UAAU,EAAI,eAAeV,GAAG,CAACK,OAAO,CAACC,GAAG,CAACC,MAAM,EAAI,GAAAC,wCAAyB,EAACD,MAAM,CAACH,IAAI,CAAC,CAAC,CAACW,IAAI,CAAC,GAAG,CAAC,KAAK,CAC7GL,UAAU,EAAI,YAChB,CAEA,MAAO;AACT;AACA,GAAGV,GAAG,CAACgB,OAAO;AACd;AACA;AACA;AACA;AACA;AACA;AACA,cAAcJ,MAAM,CAACK,IAAI,CAACf,cAAc,CAAC,CAACa,IAAI,CAAC,GAAG,CAAC;AACnD;AACA;AACA,EAAEL,UAAU;AACZ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAeV,GAAG,CAACgB,OAAO,iBAAiBhB,GAAG,CAACgB,OAAO;AACtD,CACA","ignoreList":[]}
|