Add test command to CLI

Also, reorganize source files, so the lib directory contains two
children - api and cli.