bitfield/script

A pipe method for writing to Stdout and exit

ifraixedes opened this issue · 3 comments

Sometimes you're writing a script and you want to not continue if there is an error in some of the operations. I'm looking for a simple method that wraps the logic of having to check the Stdout() error, print it out, and exit.

In the README there is this example:

_, err := script.Do(req).Stdout()
if err != nil {
	log.Fatal(err)
}

I'm looking for having something like this

script.Do(req).StdoutAbortOnError()

that would be the same as above.

I don't like that much the name that I used in the example, it's explicit but a bit long and I don't know if the log.Fatal should be used rather than a fmt.Println(err) followed by os.Exit(1), or even to be able to configure them (printing and exit code).

Thank you in advance for your time!

Are you thinking along roughly the same lines as #140?

Yes, I missed that issue when I looked at the list.

I think that printing the error to stderr is better, but it would be nice to have available some methods that allow redirecting outputs, if it's not generic, at least to redirect stderr to stdout. I'm not looking for these redirections at this moment, but they blinked in my brain.

As commented above, perhaps may be useful for someone to be able to specify the exit code, rather than always returning 1.

Another thing that somebody may be interested in is adding a prefix to the error message, like "ERROR: ", but then there may be a way to implement something to modify anything before calling the sink, however Filter looks like that can do that despite that its name doesn't suggest it and it has another purpose.

Anyway, I stop overthinking 😅

I'm closing this issue because it duplicated #140

Thank you @bitfield

Sure, please add your comments to #140 instead. That'll be a big help, thank you.