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 into files uses .yml file ending #1165

Closed
Wikiwix opened this issue Apr 5, 2022 · 10 comments
Closed

Split into files uses .yml file ending #1165

Wikiwix opened this issue Apr 5, 2022 · 10 comments
Labels

Comments

@Wikiwix
Copy link

Wikiwix commented Apr 5, 2022

Describe the bug

Files created by --split-exp use the .yml file ending althoguh yaml is the recommended file ending

Version of yq: 4.24.2
Operating system: linux
Installed via: homebrew

Command

The command you ran:

echo '[1,2,3]' | yq '.[]' - --split-exp='"test-" + .'

Actual behavior

The files

  • file-1.yml,
  • file-2.yml and
  • file-3.yml

where created

Expected behavior

The files

  • file-1.yaml,
  • file-2.yaml and
  • file-3.yaml

are created

Additional context

If there are other cases where yq creates new files, I suspect the .yml ending might be in use as well

@mikefarah
Copy link
Owner

Ah I see - I should have done that from the start. I'm reluctant to do this now as users already have scripts that assume '.yml'.

Since this is seems to be only a preference of the standards and .yml is generally accepted I do not think it's worth adding a feature to toggle to '.yaml'.

@Wikiwix
Copy link
Author

Wikiwix commented Apr 8, 2022

Hmm, so a change for 5.0 then 🙈.

When I noticed .yml files are created, I somehow expected using a filename like "bla" + .a + ".yaml" would "deactivate" the autogenerated file ending.

So perhaps a flag to disable the addition of a file ending would be a worthwhile addition?

Besides allowing the proper .yaml ending, this enables the use of other file endings for special use cases as well.

@mikefarah
Copy link
Owner

Actually that's not a bad idea - if the resulting contains ".yaml" or ".yml" then I can skip over adding a ".yml"

@Wikiwix
Copy link
Author

Wikiwix commented Apr 9, 2022

Introducing that without a flag still might break some scripts though :/

Which is why I suggested a flag (which has the added benefit of allowing any file ending)

@joebowbeer
Copy link

I use the split feature to separate kustomize build and helm template output into separate files, but it would be even better for me and most k8s users if it would save with .yaml extension or allow me to choose this as an option.

@tschifftner
Copy link

@joebowbeer A workaround is to use kubectl-slice

kubectl slice -f source.yaml -t '{{.metadata.name | lower}}.yaml' -o ./source

@mikefarah
Copy link
Owner

Fixed in v4.25.3 - if you have an extension in the split-file-exp it will no longer add '.yml'

@bluebrown
Copy link

Fixed in v4.25.3 - if you have an extension in the split-file-exp it will no longer add '.yml'

so how do you use that? And how do you specify an output dir?

@Wikiwix
Copy link
Author

Wikiwix commented Jan 28, 2023

@bluebrown By defining a path as part of the filename given in --split-exp. Be aware that the directory must exist already:

$ mkdir dir/
$ echo '[1,2,3]' | yq '.[]' - --split-exp='"dir/test-" + . + ".yaml"'
$ ls dir/
test-1.yaml  test-2.yaml  test-3.yaml

@iosifnicolae2
Copy link

iosifnicolae2 commented Jul 12, 2023

@bluebrown By defining a path as part of the filename given in --split-exp. Be aware that the directory must exist already:

$ mkdir dir/
$ echo '[1,2,3]' | yq '.[]' - --split-exp='"dir/test-" + . + ".yaml"'
$ ls dir/
test-1.yaml  test-2.yaml  test-3.yaml

Any idea how to let yq also create the directories? (we're generating the directories dynamically)

Workaround

for name in $(yq eval '.metadata.name' manifests.yaml | grep -v '^---$' | awk '!seen[$0]++'); do mkdir -p "$name"; done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants