Skip to content

Add --to output format option to shaping commands (0.8.0) - #10

Merged
rmkr-dev merged 1 commit into
mainfrom
feat/output-format
Oct 14, 2026
Merged

rmkr-dev merged 1 commit into
mainfrom
feat/output-format

Conversation

@rmkr-dev

@rmkr-dev rmkr-dev commented Oct 14, 2026 •

Copy link
Copy Markdown
Owner

Adds -t, --to json|yaml|csv|ndjson to every shaping command (select, pick, omit, rename, flatten, unflatten, filter, sort, unique, head, tail, group-by, count, stats, join). Until now these could only print JSON, so getting CSV or YAML back meant a second to-* step in the pipe.

data-transform filter age ge 30 people.csv -t csv
data-transform flatten events.json -o events-flat.csv   # format from the extension
data-transform join id --with teams.csv users.json -t csv -o report.csv
  • Output format comes from --to, else the --output extension (.json, .yaml/.yml, .csv, .ndjson/.jsonl), else JSON. Unknown extensions and stdout stay JSON
  • --minify still controls JSON only; YAML/CSV/NDJSON ignore it
  • CSV for a non-list result (count, group-by, a scalar select) fails with exit code 1 and a hint to use --to json or --to yaml
  • YAML output keeps values like dates that JSON can't hold, so YAML → shape → YAML now works end to end
  • to-*, pretty, and minify are unchanged

Behaviour change: -o out.csv / -o out.yaml on a shaping command used to write JSON into that file whatever the name; it now writes the format the extension says. Called out in the changelog.

The 14 copies of the -o/-f/--minify option stack are folded into one shaping_options decorator, so cli.py ends up about 70 lines shorter even with the new option. Also adds CHANGELOG.md with the history back to 0.1.0, a README "Output formats" section, and bumps the version to 0.8.0.

Test plan

  • pytest: 109 → 136 tests (new tests/test_output_format.py: format resolution, every output format, extension inference and override, --minify handling, CSV round trip, CSV errors for non-list results, invalid --to, YAML dates, join)
  • README examples run by hand

Shaping commands (select, pick, omit, rename, flatten, unflatten, filter,
sort, unique, head, tail, group-by, count, stats, join) can now write
YAML, CSV, or NDJSON directly with -t/--to instead of piping into a
to-* command. Without --to, the format follows the --output extension
and falls back to JSON.

The repeated -o/-f/--minify option blocks are folded into one shared
decorator. Adds CHANGELOG.md and bumps the version to 0.8.0.
@rmkr-dev
rmkr-dev merged commit d49b731 into main Oct 14, 2026
2 checks passed
@rmkr-dev
rmkr-dev deleted the feat/output-format branch October 14, 2026 12:36
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