From f91037fec969683ea48b7f54f6eded8e3ce4b2bd Mon Sep 17 00:00:00 2001 From: nightwing Date: Wed, 9 Mar 2016 17:38:44 +0400 Subject: [PATCH] make cli login prompt bearable --- plugins/c9.cli/auth.bootstrap.js | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/plugins/c9.cli/auth.bootstrap.js b/plugins/c9.cli/auth.bootstrap.js index 684225f1..b0afc78e 100644 --- a/plugins/c9.cli/auth.bootstrap.js +++ b/plugins/c9.cli/auth.bootstrap.js @@ -8,7 +8,7 @@ define(function(require, exports, module) { var http = imports.http; var fs = require("fs"); - var read = require("read"); + var _read = require("read"); /***** Initialization *****/ @@ -21,15 +21,35 @@ define(function(require, exports, module) { /***** Methods *****/ + function read(options, cb) { + _read(options, function(err, result) { + if (err && err.message == 'canceled') { + console.log("\n"); + if (options.retry) + return process.exit(1); + else { + options.retry = 1; + console.log("(^C again to quit)"); + return read(options, cb); + } + } + cb(err, result); + }); + } + function readCredentials(callback){ read({ prompt: "Cloud9 Username:" }, function(error, username) { if (error) return callback(error); - + if (!username) { + console.error("username is required"); + return process.exit(1); + } read({ prompt: "Password:", - silent: true + silent: true, + replace: "*" }, function(error, password) { if (error) return callback(error); @@ -64,7 +84,11 @@ define(function(require, exports, module) { client_id: "cli" } }, function(err, token) { - if (err) return callback(err); + if (err) { + var message = /id="error_header">([^<]*)