yq icon indicating copy to clipboard operation
yq copied to clipboard

Option to avoid spaces in generated properties

Open aloifolia opened this issue 1 year ago • 4 comments

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'

aloifolia avatar Nov 15 '23 13:11 aloifolia

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..

mikefarah avatar Dec 12 '23 23:12 mikefarah

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 avatar Feb 01 '24 18:02 jakub-bochenski

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

jakub-bochenski avatar Feb 01 '24 18:02 jakub-bochenski

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 :(

jakub-bochenski avatar Feb 02 '24 17:02 jakub-bochenski

Fixed in 4.42.1

mikefarah avatar Feb 25 '24 22:02 mikefarah