interp: Add --value-output/-V option to do tovalue before output
Idea is to skip display so that JSON is outputted instead of showing tree and hexdump etc.
Not sure about this one yet, want something like it but is -V good? also should add documentation.
Demo:
$ fq '.headers[0].magic' format/mp3/testdata/test.mp3
│00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11│0123456789abcdef01│
0x0│49 44 33 │ID3 │.headers[0].magic: "ID3" (valid)
$ fq -V '.headers[0].magic' format/mp3/testdata/test.mp3
"ID3"
$ fq -Vr '.headers[0].magic' format/mp3/testdata/test.mp3
ID3
$ fq '.headers[0].flags' format/mp3/testdata/test.mp3
│00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11│0123456789abcdef01│.headers[0].flags{}:
0x0│ 00 │ . │ unsynchronisation: false
0x0│ 00 │ . │ extended_header: false
0x0│ 00 │ . │ experimental_indicator: false
0x0│ 00 │ . │ unused: 0
$ fq -V '.headers[0].flags' format/mp3/testdata/test.mp3
{
"experimental_indicator": false,
"extended_header": false,
"unsynchronisation": false,
"unused": 0
}
👍 would have found this useful as a new user.
Hey, yeap would be nice cli ergonomic to not have to do ... | tovalue. Any idea for something else than -V? also i see now that "description: "Output JSON value (don't display)" might not be very clear if you don't know that d etc is an alias for a display function.
I'll rebase the PR and fix the help description so you can try it if you want.
My original expectation was for -r to do something like this, which would have been the parallel to jq. But if it's not reasonable to change -r's output at this point, your existing choice of UX looks reasonable to me.
I was thinking of piggyback on -r but it would be confusing for strings i guess? then -r would both make a decode value string be outputted as JSON and be raw (not quoted)
I'm unsure what you mean by 'do both' other than that it is a conflict and there is a choice to be made. I presume you'd want to preserve backwards compatible behaviour.
For example:
$ fq '.path.to.a.string' file
<fancy hexdump/tree for string>
$ fq -V '.path.to.a.string' file
"some string"
$ fq -Vr '.path.to.a.string' file
some string
If we used -r for this then the -V case would not be possible for strings, would always be raw string and not JSON string.
I think I understand what you're saying and it makes sense to me in my limited experience of fq and reasonable level of experience of jq.
Updated the documentation a bit also. Maybe the -Vr combination should be mentioned somewhere
Added -Vr to documentation and don't think i can come up with anything better than -V.
@peterwaller-arm Looks good? and thanks for bumping this issue 👍 had forgot about it
Thanks for reviewing and sorry i modified some unrelated documentation, could not resist. The whole documentation probably needs an overhaul, parts have been written independently at different times so probably mixes styles etc.