Fix cli options and make the cli better testable with require()

Nothing is directly written to stdout/stderr but is passed in an event
emitter, so when testing we can use that.

This way of testing the cli has the advantage that we don't need to exec
for all tests.
Add some extra CLI tests