Refactor cmdline

Refactoring the command line logic into a few smaller classes to make it easier to understand.