cli.js refactoring