Refactor of cmdline parsing

Refactor to be more testing friendly. Add simple test for cmdline
parsing