Move cli.js over to refactored code