Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split support #58

Merged
merged 7 commits into from
Jan 6, 2025
Merged

Split support #58

merged 7 commits into from
Jan 6, 2025

Conversation

clux
Copy link
Owner

@clux clux commented Jan 3, 2025

For #53

Usage;

cargo run -- '.' --split '"blah/" + (.metadata.name) + "_" + (.kind | ascii_downcase) + ".yaml"' ./test/deploy.yaml -y

which will use jq shellout with the split arg as the jq query (allowing you to use ANY jq function

and it produces the following files with each document in the blah subfolder:

controller_clusterrole.yaml         controller_deployment.yaml  controller_serviceaccount.yaml
controller_clusterrolebinding.yaml  controller_service.yaml

it does this by parsing into multidocs initially and running jq shellouts for each document so we can get both the key (for the filename) and the value in 2 jq calls (so 2*N shellouts currently), and at the end it would write the files.

it's not super efficient, 8 shellouts, but it only takes .1s with a release build with all serial IO, so if it gets annoying there's plenty of juice to squeeze out of it.

It's also a completely different mode that only happens when you pass --split, and need to fiddle with it some more, but the basic idea works well. Should work for all file formats, and is possibly a nicer step towards refactoring to smarter doc handling (as is it's a bit sprawling and duplicating fns).

@clux clux linked an issue Jan 3, 2025 that may be closed by this pull request
@clux clux marked this pull request as ready for review January 6, 2025 08:48
@clux clux merged commit c5f3947 into main Jan 6, 2025
14 checks passed
@clux clux deleted the split-support branch January 6, 2025 08:49
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.

allow splitting multidoc yaml into files by key
1 participant