Feature: allow halting on a particular return code.

@sjagoe: something like this?

N.B. There's a lot of refactoring included in this PR.  I'll pull that out into a separate PR at some point when I have more time.