puppetlabs/packaging — pull request #240 by haus (2013-12-10 21:54:02+00:00)
Title: Add `ex` method combining best of %x and sh

This commit adds a new utility method, `ex`, which combines the behavior of
`%x{cmd}` and rake's `sh "cmd"`. `%x{cmd}` has the benefit of returning the
standard out of an executed command, enabling us to query the file system, e.g.
`contents = %x{ls}`. The drawback to `%x{cmd}` is that on failure of a command
(something returned non-zero) the return of `%x{cmd}` is just an empty string.
As such, we can't know if we succeeded. Rake's `sh "cmd"`, on the other hand,
will raise a RuntimeError if a command does not return 0, but doesn't return
any of the stdout from the command - only true or false depending on its
success or failure. With `ex(cmd)` we purport to both return the results of the
command execution (ala `%x{cmd}`) while also raising an exception if a command
does not succeed (ala `sh "cmd"`).