Refactor and document the CLI parsing code.

Also update the `README.md` with usage instructions.