christianspecht / scm-backup

Makes offline backups of your cloud hosted source code repositories
https://scm-backup.org/
GNU General Public License v3.0
61 stars 20 forks source link

Set process exit code to non-zero on error #53

Closed nzbart closed 4 years ago

nzbart commented 4 years ago

For use in scripts, it would be handy to have the process exit with zero on success and nonzero on failure.

I had a quick stab at this, but it wasn't immediately clear how it would best be done. My initial approach was to alter IScmBackup.Run to return bool, which would be true on success and false on failure. However, this approach isn't perfect due to the use of the decorator pattern where - for example - LogMailingScmBackup wraps ScmBackup. Currently, errors are bubbled through the layers of decorators by throwing exceptions, and it's a little clunky to also return a true/false value.

Is this something that you'd be interested in me submitting a pull request for, and if so, how would you recommend I implement it?

christianspecht commented 4 years ago

Is this something that you'd be interested in me submitting a pull request for...

Definitely! :+1:

...and if so, how would you recommend I implement it?

That's a good question. I was thinking about the same approach a few days ago, because of #47.
This is a similar problem and it affects exactly the LogMailingScmBackup you mentioned - this class would need the true/false value in order to send different mail texts depending on the result.

I agree, the bool return value looks clunky somehow, but right now, I don't have a better idea. But I don't have that much experience with designs like this, though - that's one reason why I'm making open source projects like this one.

Do you have a different idea?

christianspecht commented 4 years ago

Fixed by #54