fq icon indicating copy to clipboard operation
fq copied to clipboard

interp: Add --value-output/-V option to do tovalue before output

Open wader opened this issue 3 years ago • 1 comments

Idea is to skip display so that JSON is outputted instead of showing tree and hexdump etc.

wader avatar Aug 19 '22 15:08 wader

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
}

wader avatar Aug 19 '22 15:08 wader

👍 would have found this useful as a new user.

peterwaller-arm avatar Apr 12 '23 16:04 peterwaller-arm

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.

wader avatar Apr 12 '23 16:04 wader

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.

peterwaller-arm avatar Apr 12 '23 16:04 peterwaller-arm

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)

wader avatar Apr 12 '23 16:04 wader

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.

peterwaller-arm avatar Apr 12 '23 16:04 peterwaller-arm

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.

wader avatar Apr 12 '23 16:04 wader

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.

peterwaller-arm avatar Apr 12 '23 16:04 peterwaller-arm

Updated the documentation a bit also. Maybe the -Vr combination should be mentioned somewhere

wader avatar Apr 12 '23 17:04 wader

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

wader avatar Apr 12 '23 19:04 wader

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.

wader avatar Apr 13 '23 09:04 wader