jzelinskie / faq

Format Agnostic jQ -- process various formats with libjq
Apache License 2.0
434 stars 14 forks source link

"raw output" fails to encode #77

Closed vbatts closed 4 years ago

vbatts commented 4 years ago
vbatts@infra1:~$ curl -s https://api.github.com/repos/flatcar-linux/manifest/releases | faq -f json '.[0].tag_name'
"v2492.0.0"
vbatts@infra1:~$ curl -s https://api.github.com/repos/flatcar-linux/manifest/releases | faq -f json -r '.[0].tag_name'
Error: failed to encode as pretty: invalid character 'v' looking for beginning of value
Usage:
  faq [flags] [filter string] [files...]
[...]
vbatts@infra1:~$ curl -s https://api.github.com/repos/flatcar-linux/manifest/releases | jq -r '.[0].tag_name'
v2492.0.0

faq seems to be expected raw values to act a certain way?

jzelinskie commented 4 years ago

This is on faq v0.0.6?

vbatts commented 4 years ago
vbatts@infra1:~$ faq --version
0.0.6
chancez commented 4 years ago

Try -ojson when using -r and maybe -c. I think it's broken with non-JSON output.

vbatts commented 4 years ago

@chancez it already defaulted to json output. Adding that flag did not change anything.

vbatts@infra1:~$ curl -s https://api.github.com/repos/flatcar-linux/manifest/releases | faq -f json -o json -r '.[0].tag_name'
Error: failed to encode as pretty: invalid character 'v' looking for beginning of value
Usage:
  faq [flags] [filter string] [files...]
[...]

p.s. despite erroring out, the return code is from this is still 0

chancez commented 4 years ago

Try -c. It's trying to pretty the raw output, which cannot be done.

jzelinskie commented 4 years ago

@chancez maybe we should just add

if rawOutput {
  outputConf.Color = false
  outputConf.Pretty = false
}

above https://github.com/jzelinskie/faq/blob/ecc24aed5346a65c8bbc37a64ba58aad8c5175b1/pkg/faq/faq.go#L87-L92

The original jq (and early faq) handled this at flag-parsing time, but it honestly seems more sane to do it at the call site.

chancez commented 4 years ago

I'd agree with that.