Refactor CLI and CLI testing