Make run and throwable
Blackjacx opened this issue · 1 comments
I already mentioned this request in #92. I think it is a very common use case to make all run commands throwable.
What I would like to avoid is the extra check for the error and manually print the error like this:
let out = run("mint", args)
if let error = out.error {
print(out.stderror)
throw error
}
The following would be much cleaner imho and the failure reason could be part of the error or an underlying error maybe:
let successfulOut = try run("mint", args)
Originally posted by @stherold in #92 (comment)
You're right, it is a bit cumbersome the way it is now. The problem with your suggestion is that it makes it more cumbersome to get the result of a failing command. And it is a breaking change, so it would have to be in SwiftShell 6.0. But your use case is probably more common.
I've been wanting to improve the API for a long time now, but I just haven't been able to come up with a good solution that handles all aspects well, like error handling, synchronicity, shell interpreter, stdin, joined or separate stdout/stderror, printing output, piping output to another command, and probably even more that I haven't thought of yet.