Repository navigation
Add --to output format option to shaping commands (0.8.0) - #10
Merged
Merged
Conversation
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.
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.
Adds
-t, --to json|yaml|csv|ndjsonto 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 secondto-*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--to, else the--outputextension (.json,.yaml/.yml,.csv,.ndjson/.jsonl), else JSON. Unknown extensions and stdout stay JSON--minifystill controls JSON only; YAML/CSV/NDJSON ignore itcount,group-by, a scalarselect) fails with exit code 1 and a hint to use--to jsonor--to yamlto-*,pretty, andminifyare unchangedBehaviour change:
-o out.csv/-o out.yamlon 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/--minifyoption stack are folded into oneshaping_optionsdecorator, so cli.py ends up about 70 lines shorter even with the new option. Also addsCHANGELOG.mdwith 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 (newtests/test_output_format.py: format resolution, every output format, extension inference and override,--minifyhandling, CSV round trip, CSV errors for non-list results, invalid--to, YAML dates, join)