feat: read split input from stdin (pipe support)#22
Merged
Conversation
`yamlx split` now reads its document from stdin when the argument is `-`
or omitted on a pipe, so it composes with other tools:
aws quicksight describe-data-set ... --output yaml | yamlx split - --out-dir ds/
split.Run is refactored into a thin file-opening wrapper over a new
RunReader(io.Reader, srcName, ...), preserving the existing signature and
its fs.ErrNotExist behavior. The CLI auto-detects a piped stdin via the
existing isTerminal helper; a bare interactive invocation is a usage
error rather than a silent wait on stdin.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Address go-pr-reviewer suggestions: use one arg form ([input.yml|-]) in the Use string, error message, and help; add a test pinning that empty stdin (bare io.EOF) classifies as invalid (exit 1), guarding against any future narrowing of RunReader's error wrapping. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
yamlx splitnow reads its document from stdin when the argument is-or omitted while piping, so it composes with other tools:Why
Previously
splitrequired a file-path argument, forcing a temp file to bridge any pipeline. The engine already read through anio.Reader(yamltree.Load), and split output is named from identity keys rather than the input filename, so no real file is needed.How
internal/split/split.go— newRunReader(io.Reader, srcName, outDir, opts);Run(path, …)is now a thin file-opening wrapper over it. Theos.Openfailure stays inRun, so a missing file still surfaces asfs.ErrNotExist→ usage error (exit 2).internal/cli/commands.go—splittakes 0-or-1 args; reads stdin on a literal-or an auto-detected pipe (reusing the existingisTerminalhelper +cmd.InOrStdin()). A bare interactive invocation is a usage error rather than a silent wait on stdin.--output yamlcaveat;RunReaderunit tests and CLI tests for-, auto-detect, malformed-stdin (exit 1), and missing--out-dir(exit 2). Help golden regenerated.Scope
splitonly.joinconsumes a directory tree (not a stream) andverifyreads its input twice, so both are out of scope.Verification
go build,go vet,golangci-lint(0 issues), andgo test ./...all pass. Manually verified: explicit-, auto-detected pipe, malformed stdin → 1, missing--out-dir→ 2, path still works, missing file → 2.🤖 Generated with Claude Code