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

Option to avoid spaces in generated properties #1864

Closed
aloifolia opened this issue Nov 15, 2023 · 5 comments · Fixed by #1951
Closed

Option to avoid spaces in generated properties #1864

aloifolia opened this issue Nov 15, 2023 · 5 comments · Fixed by #1951

Comments

@aloifolia
Copy link

Please describe your feature request.
Currently, when the output is formatted as properties, the equality signs are separated by a single space from both keys and values. Kustomize supports properties files. However, it is not able to process them if they have such whitespace around the equality characters.

I'd like to be able to instruct yq to generate a more compact properties format that is compatible with Kustomize.
A clear and concise description of what the request is and what it would solve.

Describe the solution you'd like
Given a file application.properties:

foo=bar

And we run a command:

yq --no-spaces '.baz="nix"' application.properties 

it could output

foo=bar
baz=nix

Describe alternatives you've considered
At the moment, I use sed to remove the whitespace:

yq '.baz="nix"' application.properties | sed 's/\([^ ]*\) = /\1=/g'
@mikefarah
Copy link
Owner

yq uses https://github.com/magiconair/properties to decode/encode property files and it currently does not expose an interface to let me control the whitespace.

For now, you could do a custom format, I've just added a new recipe to show how: https://mikefarah.gitbook.io/yq/recipes#export-as-environment-variables-script-or-any-custom-format.

That said, you're sed expression is simpler (though it could have issues if you had a quoted " = " as a value somewhere..

@jakub-bochenski
Copy link

It's not apparent from the recipe how to handle lists to output them like the -o=props does. Would be nice to add it.

Besides the recipe doesn't work as described in #1932

@jakub-bochenski
Copy link

Also I don't think this recipe approach will ever be able to handle comments

@jakub-bochenski
Copy link

Also I don't think this recipe approach will ever be able to handle comments

I guess it could after all, but the recipe gets really complex :(

learnitall added a commit to learnitall/yq that referenced this issue Feb 19, 2024
This commit adds the --properties-separator option, which lets users
specify the separator used between keys and values in the properties
output format. This is done by adjusting the value of
github.com/magiconair/properties#Properties.WriteSeparator at encode
time.

Some refactoring of the properties encoder unit tests was done to make
it easier to write unit tests that include different separator values.

Fixes: mikefarah#1864

Signed-off-by: Ryan Drew <ryan.drew@isovalent.com>
learnitall added a commit to learnitall/yq that referenced this issue Feb 19, 2024
This commit adds the --properties-separator option, which lets users
specify the separator used between keys and values in the properties
output format. This is done by adjusting the value of
github.com/magiconair/properties#Properties.WriteSeparator at encode
time.

Some refactoring of the properties encoder unit tests was done to make
it easier to write unit tests that include different separator values.

Fixes: mikefarah#1864

Signed-off-by: Ryan Drew <ryan.drew@isovalent.com>
mikefarah pushed a commit that referenced this issue Feb 19, 2024
This commit adds the --properties-separator option, which lets users
specify the separator used between keys and values in the properties
output format. This is done by adjusting the value of
github.com/magiconair/properties#Properties.WriteSeparator at encode
time.

Some refactoring of the properties encoder unit tests was done to make
it easier to write unit tests that include different separator values.

Fixes: #1864

Signed-off-by: Ryan Drew <ryan.drew@isovalent.com>
@mikefarah
Copy link
Owner

Fixed in 4.42.1

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

Successfully merging a pull request may close this issue.

3 participants