parse stdin as JSON
on error:
parse stdin as a protocol
on error:
print the error
save stdin
parse the command-line args as a protocol
on error:
print the error
save the text
if both protocols were successfully parsed:
merge the protocols
print the merged protocols as (text if stdout is a TTY else JSON)
else:
concatenate the protocol strings
print the concatenated text as (text if stdout is a TTY else JSON)
The advantage of this is that it will provide a robust and extensible way to transfer metadata between stages of the pipeline, like:
The JSON format I'm thinking of will be something like this:
The main function would work something like this: