feat: add typed decode results - #10
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Add
DecodeChain.As[T], which runs the configured command and returns a decoded value directly. It uses the same decoder, output-source selection, trimming, execution, and error wrapping asInto;IntoandDecodeWithremain unchanged.Raise the root, docs, and examples modules to Go 1.27, add minimum-version and stable CI coverage, regenerate the API docs, and retain 100% statement coverage across success and failure paths. Older toolchains can remain on the v1.1 line.
Before and after
Decoded command results no longer need a temporary variable and mutable pointer:
DecodeChain.As
Before:
After:
The chain now describes the whole operation and produces its typed result in one expression, while
Intoremains available when callers intentionally want to populate an existing value.Why
The pointer-only result shape existed because earlier Go versions could not add a result type to a method. Go 1.27 lets the decode chain own that type, making the common case concise without changing the decoder interface or error contract.
Performance
End-to-end benchmarks include subprocess startup and JSON decoding.
IntoandAsboth remain at 88,787 B and 163 allocations, and both run in the same roughly 268–283 microsecond range on linux/arm64 with one P.