cli: Major refactoring.

Move alot of stuff out of main.py and abstract them
into classes instead where possible.