Extracts the main logic in its own function.

The main benefit is to be able to run it from the REPL
without needing to take care of terminal-specific stuff,
like the exit code.