use ui.writeError in lib/cli/cli.js

fixes GH-2254