Closed StarOfSlytherin closed 2 years ago
You can format command output, as proven by your echo example. So I do not think that this is a problem with Rich.
I don't have access to the _mosquittosub command, but I assume the problem is that it does not output a complete JSON document and close STDOUT. For example, tail -f
does not work either, because it produces continuous output and never closes the file, so this example hangs forever:
$ echo '{"test":"OK"}' | tee foo.json
{"test":"OK"}
$ tail -f foo.json | rich --json -
[No output]
As long as the command that you execute finishes, and closes the pipe, you can format the output with Rich. If it doesn't, you can't. And since JSON specifically will be invalid if you don't have the entire file, it's not really technically possible to try to do anything different.
(This is in contrast with JSON Lines, JSONL, which you could certainly stream one line at a time.)
Thanks, I did not think that streaming JSON would be different from a normal JSON.
(This is in contrast with JSON Lines, JSONL, which you could certainly stream one line at a time.)
Does Rich CLI support this?
As far as I can tell, rich-cli does not support JSONL. See also: #59
I don't believe it would be very difficult to add if there is enough interest. However, it's easy to convert JSONL to JSON with jq -s
so that's what I would recommend. 😊
Looks like I can use jq -s
. I'm getting some errors but I can fix that. Thanks for the help!
For example, the
mosquitto_sub
command can print data received through MQTT. It has a built-in formatting option using the-F
flag. But I would like to have a better looking output that would be possible with Rich CLI. What's the best way to use it?I did the following and it worked so I assumed mosquitto would work too:
I tried the following:
mosquitto_sub -h test.mosquitto.org -t "181818/json" | rich - --json
but did not get any output. Without| rich - --json
I got this:{"test":"OK"}