A really handy trick is to always return JSON from your CLI tools. This works very well when piping multiple commands. Every subsequent command augments the output from the previous command. Obviously you can add as many keys as you’d like. This means you can put in any logs and intermediate debugging information. After the very last command, you’ll have structured output, which is easy to parse and query. And this output will contain all of the information explaining how the result was formed. As it’s still text, it’s easily grep-pable.