alphagov/vcloud-net_launcher — pull request #30 by mattbostock (2014-06-09 12:02:55+00:00)
Title: [#72169106] Replace methadone with optparse and add CLI tests

Replace methadone with optparse for passing CLI options and replace
Cucumber/Aruba tests with unit tests for the new Vcloud::NetLauncher::Cli
class.

`--version` no longer prints help. Just the version string.

I've chosen to rescue exceptions and print the exception error messages
so that the full backtrace doesn't show. I think the error messages are
mostly useful and showing just a message is much kinder to the end-user
than revealing a backtrace.

Heavily based on @dcarley's work in alphagov/vcloud-edge_gateway@0d8169c
and alphagov/vcloud-walker@527ccda. Part of his original commit message
follows below:

* * *

The primary purpose of this is to move the untested logic that's in the
executable file into a normal class and give it test coverage.

This happens to be a good reason to remove methadone, which collectively
we've not grown very fond of. Whilst it definitely results in less
boilerplate code than using OptionParser directly, it's a lot harder to
understand what's going on, e.g.

- Where does that options hash come from?
- Why don't `arg()` names match the block arguments on `main()`?

Whereas OptionParser makes it clear where we've defined those and that
usage strings don't necessarily match variable assignments for remaining
arguments.

The tipping point was figuring out how we'd test what it is or isn't
doing. Not the basic CLI interface, using cucumber - but what methods it
will call underneath.

I've stolen this pattern from rodjek/puppet-lint which was the
best/simplest example I could find. The binary just passes over `ARGV`
which is an array of CLI argument strings. We can then interface this
with rspec and stub out the parts underneath for testing.