Add tests for command line arguments.  Refactor a bit.

OK, this one should be easier to diff.