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

feat: adding an option to control style of strings #170

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

SGSSGene
Copy link

@SGSSGene SGSSGene commented Aug 1, 2023

Add options to control the styling of strings.

This capability is added by prepending a string with a specific control string (e.g. __yq_style_|__).
Because of this, this option is turned off by default and can be turned on by setting --yaml-style-strings.

@kislyuk
Copy link
Owner

kislyuk commented Aug 6, 2023

Thanks for your contribution! It's an interesting suggestion and I agree it would be nice to have a way to control the string style in an intuitive way.

The __yq__ control sequences were never meant to be exposed to the user through the API - up until now, they have only ever been used internally in the roundtrip process between yq and jq. So my main hesitation with this change is that it actually commits these control sequences into the API (and also uses special character literals for the styles, which may be a pain to escape).

I'll have to think more about the ergonomics of this change. One immediate change that comes to mind is to replace the special character literals with descriptions (__yq_style_single_quoted__, __yq_style_double_quoted__, __yq_style_block_literal__, __yq_style_block_folded__).

@SGSSGene
Copy link
Author

SGSSGene commented Aug 10, 2023

Yes, I completely agree.

Another thing I am very unhappy with, is that it is kind of hard to use these special strings. This is why I added the section into the README with the def style(s): function.
I would prefer if this function would be available when --yaml-style-strings is set.

If the filter is given on the command line, this is not such a big issue, we could just prepend the function definition to the filter (This is what I did originally). In the case the filter is given via a file, this doesn't work anymore. Any Ideas on how this could be done?

The advantage of having the functions automatically defined is, that then we could use even longer prefixes, avoiding practically any collisions: __yq_style_012323afafaf0123124_quoted__.

@SGSSGene
Copy link
Author

rebased to latest tag (v3.4.3)

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.

3 participants