Open Blackjacx opened 4 years ago
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.
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:
The following would be much cleaner imho and the failure reason could be part of the error or an underlying error maybe:
Originally posted by @stherold in https://github.com/kareman/SwiftShell/issues/92#issuecomment-698853537