Have you ever wanted to call exit() with an error condition, but weren’t sure what exit status to use? No? Maybe it’s just me, then.
Anyway, I was reading manpages late one evening before retiring to bed in my palatial estate in rural Oregon, and I stumbled across sysexits(3). Much to my chagrin, I couldn’t find a ‘sysexits’ for Ruby! Well, for the other 2 people that actually care about style(9) as it applies to Ruby code, now there is one!
Sysexits is a completely awesome collection of human-readable constants for the standard (BSDish) exit codes, used as arguments to `Kernel.exit` to indicate a specific error condition to the parent process.
It’s so fantastically fabulous that you’ll want to fork it right away to avoid being thought of as that guy that’s still using Webrick for his blog. I mean, `exit(1)` is so passé! This is like the 14-point font of Systems Programming.
Like the C header file from which this was derived (I mean forked, naturally), error numbers begin at `Sysexits::EX__BASE` (which is way more cool than plain old ‘64’) to reduce the possibility of clashing with other exit statuses that other programs may already return.
The codes are available in two forms: as constants which can be imported into your own namespace via
include Sysexits, or as
Sysexits::STATUS_CODES, a Hash keyed by Symbols derived from the constant names.
Allow me to demonstrate. First, the old way:
exit( 69 ) <
clude Sysexits exit EX_UNAVAILABLE <?e
ude Sysexits exit :unavailable <?end
You can clone the source with Mercurial, submit bug reports, suggestions, etc., via the project page.
Or if you prefer Git, you can clone the source via its Github mirror.
After checking out the source, run:
ke newb <?end
This task will install any missing dependencies, run the specs, and generate the API documentation.