if it succeeds, have it POST a http endpoint with:
{status: "success", log: "output generated during the compile"}
If it fails, have it POST a http endpoint with:
{status; "fail", log: "output generated during the compile"}
====
The XY problem here is that right now, cargo watch pipes output to a terminal, which means it's either taking up screen real estate (or hidden).
Instead, I'd like to turn cargo watch into a json-event-generator, where it gets sent to some other program, then I can control how to deal with the output.
(For example, a UI that collects events from multiple sources, only displays headlines for the status=fail ones, and expands the msg on click).
I assume when you say terminal you mean stdout/stderr. If so, you can just redirect the output with something like cargo watch -x [BASH_CMD] &> file.txt.
Well if you don't went the cargo output, what do you need cargo watch for? Sounds more like you need something like the watch functionality contained within. Something like epoll.
You can change the command that cargo watch runs -- that could be a script that runs cargo build, captures its output whole, and sends that in your http call.
Yes, cargo-watch is an external 3rd party tool that literally just runs a cargo build command when the source changes. You could replace it with any generic file watch service, but you don't need to and cargo-watch includes multiple special conveniences derived from the fact it knows it's watching a cargo project (like ignoring changes to VCS ignored files).
To ask cargo watch to run a custom command, do something like cargo watch -- my-cargo-wrapper build. my-cargo-wrapper is your simple wrapper which forwards arguments to an invocation of cargo and pushes the output to your endpoint.
There's possibly an approach using --message-format json and redirection to a Unix socket... but it sounds like the above approach is much simpler for what you want!