Restructure cli and add tests.