Skip to content

feat: read split input from stdin (pipe support)#22

Merged
NickMoignard merged 2 commits into
masterfrom
feat/stdin-split
Jul 11, 2026
Merged

feat: read split input from stdin (pipe support)#22
NickMoignard merged 2 commits into
masterfrom
feat/stdin-split

Conversation

@NickMoignard

Copy link
Copy Markdown
Owner

What

yamlx split now reads its document from stdin when the argument is - or omitted while piping, so it composes with other tools:

# AWS CLI defaults to JSON — ask for YAML, then split the stream straight in.
aws quicksight describe-data-set \
  --aws-account-id "$ACCOUNT_ID" --region "$REGION" \
  --data-set-id "$DATASET_ID" --output yaml \
  | yamlx split - --out-dir dataset/

Why

Previously split required a file-path argument, forcing a temp file to bridge any pipeline. The engine already read through an io.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 — new RunReader(io.Reader, srcName, outDir, opts); Run(path, …) is now a thin file-opening wrapper over it. The os.Open failure stays in Run, so a missing file still surfaces as fs.ErrNotExist → usage error (exit 2).
  • internal/cli/commands.gosplit takes 0-or-1 args; reads stdin on a literal - or an auto-detected pipe (reusing the existing isTerminal helper + cmd.InOrStdin()). A bare interactive invocation is a usage error rather than a silent wait on stdin.
  • Docs + tests: README piping example with the --output yaml caveat; RunReader unit tests and CLI tests for -, auto-detect, malformed-stdin (exit 1), and missing --out-dir (exit 2). Help golden regenerated.

Scope

split only. join consumes a directory tree (not a stream) and verify reads its input twice, so both are out of scope.

Verification

go build, go vet, golangci-lint (0 issues), and go 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

NickMoignard and others added 2 commits July 12, 2026 02:49
`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>
@NickMoignard NickMoignard merged commit 5cd1143 into master Jul 11, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant