invopop / gobl.cli

The GOBL Command Line Interface
Apache License 2.0
3 stars 0 forks source link

keygen output #4

Open samlown opened 2 years ago

samlown commented 2 years ago

It might be a good idea to generate output for the gobl keygen command that indicates what files have been generated, and where.

Does it make sense to write message to STDERR incase STDOUT is being used to pipe a generated key (perhaps?) A -v tag for verbose output might be a good idea.

flimzy commented 2 years ago

I think this type of thing requires some thought, as there are several ways to do something like this.

For this particular feature, what probably makes sense to me is outputting helpful info to STDOUT except when STDOUT is being used as the output location of the key (in which case the helpful output isn't helpful anyway), or when quiet mode (i.e. --quiet?) is on (i.e for scripting purposes).

I expect there are output situations not covered by that, though.

samlown commented 2 years ago

I think for this application where STDOUT is likely to be used for data output its acceptable to use STDERR for all logging, as a rule. Sending to STDERR requires more effort, hence why it's not so common, but I don't think it's bad practice.

If a logging library is used, then it should be easy to add a --quiet option too.

flimzy commented 2 years ago

The problem with sending non-errors to STDERR is it makes error handling/detection in scripts very cumbersome.

samlown commented 2 years ago

It occurred to me that perhaps an alternate solution would be to always generate JSON output and make sure that the exit status code is non-zero. If you're worried about script handling, this would solve the problem and provide a universal interface with comparable results in both CLI and HTTP.

Argument errors, i.e. stuff caught by cobra, should be sent to STDERR as this clearly reflects invalid usage and you wouldn't want those to be scriptable.