feat: Add support for passthrough/unknown CLI options #171
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Implements support for passing arbitrary CLI flags through to procedures without explicitly defining each one in the schema. This resolves #161.
Key changes:
allowUnknownOptions?: booleantoTrpcCliMetainterfacehasAdditionalProperties?: booleantoParsedProcedureinterfaceadditionalPropertiesinstead of rejecting themparseUnknownOptions()helper to parse and merge unknown CLI options into procedure inputadditionalPropertiesstill fall back to JSON input mode unlessallowUnknownOptionsis explicitly enabledUsage
mycli forward --known value --unknown-flag foo --another-flag bar # input: { known: "value", unknownFlag: "foo", anotherFlag: "bar" }Features
--my-optionbecomesmyOption--flagsetsflag: true--no-flagsetsflag: false--key=valueworks as expected"true"/"false"become booleansRequirements
Both conditions must be met for passthrough to work:
allowUnknownOptions: true.passthrough()orz.record())Use Case
This is particularly useful for building CLI wrappers around other tools (like the Ultracite/Biome example mentioned in the issue) where you want to forward flags without manually enumerating every possible option.
Test plan
allowUnknownOptionswith passthrough schemaallowUnknownOptionswith record schemaadditionalPropertiesbut withoutallowUnknownOptionsfall back to JSON input)allowUnknownOptionsalone (without schema support) doesn't enable passthroughDocumentation
allowUnknownOptionsCloses #161