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

A more cross-platform way to specify raw string output #1617

Closed
mcandre opened this issue Mar 26, 2023 · 2 comments
Closed

A more cross-platform way to specify raw string output #1617

mcandre opened this issue Mar 26, 2023 · 2 comments

Comments

@mcandre
Copy link

mcandre commented Mar 26, 2023

Please describe your feature request.

The current way to obtain raw string output text involves specifying style="":

yq -o yaml ".target | keys | .[] | . style=\"\"" Cross.toml

or

yq -o yaml '.target | keys | .[] | . style=""' Cross.toml

The former breaks in user shells that do not respect C escape syntax conventions, such as Windows PowerShell.

The latter breaks in user shells that do not respect single quoted strings, like Windows Command Prompt.

While there are technically some sh interpreter shims available, such as WSL, I would prefer that my command line tools be able to operate well without assuming a particular user environment. Windows is just one example.

I have no idea how the commands would behave when run on FreeBSD, where the default shell isn't even a POSIX compliant one, but csh/tcsh. I have no idea how the commands would behave on still other shells like fish, ion, rc, legacy ksh, or the vintage Thompson sh.

Our immediate problem is the fact that style's value syntax requires double quotes, which are hard to wrap in the larger yq query CLI argument in a portable way.

Describe the solution you'd like

I would love for -r and --raw to behave like jq. But I'd settle for supporting style=blank, or failing that, style=''.

[target.aarch64-apple-darwin]
image = "freeznet/aarch64-apple-darwin-cross:11.3"

[target.x86_64-apple-darwin-cross]
image = "freeznet/x86_64-apple-darwin-cross:11.3"

And we run a command:

yq -r ".target | keys | .[]" Cross.toml

or

yq -o yaml ".target | keys | .[] style=blank" Cross.toml

or

yq -o yaml ".target | keys | .[] style=''" Cross.toml

it could output

aarch64-apple-darwin
x86_64-apple-darwin-cross
@mikefarah
Copy link
Owner

This will be fixed once I add a toml encoder, which I plan on working soon., What I couild do first is add a toml encoder that only encodes scalar values (like above).

Only caveat is that this first cut would error if its encoding a map or array until that functionality is added.

@mikefarah
Copy link
Owner

Fixed in 4.33.3

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

No branches or pull requests

2 participants