From f3e193be0f62d8a917d51511bd1cc19c257ca9bc Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Mon, 11 May 2015 09:42:25 -0300 Subject: [PATCH] Make login command behave non interactively if a token is passed as an argument --- build/actions/auth.js | 12 +++++------- lib/actions/auth.coffee | 21 ++++++++++----------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/build/actions/auth.js b/build/actions/auth.js index 29d9b48a..c8cb2912 100644 --- a/build/actions/auth.js +++ b/build/actions/auth.js @@ -22,20 +22,18 @@ description: 'login to resin.io', help: "Use this command to login to your resin.io account.\n\nTo login, you need your token, which is accesible from the preferences page:\n\n " + TOKEN_URL + "\n\nExamples:\n\n $ resin login\n $ resin login \"eyJ0eXAiOiJKV1Qi...\"", action: function(params, options, done) { - console.info("To login to the Resin CLI, you need your unique token, which is accesible from\nthe preferences page at " + TOKEN_URL + "\n\nAttempting to open a browser at that location..."); return async.waterfall([ function(callback) { + if (params.token != null) { + return callback(null, params.token); + } + console.info("To login to the Resin CLI, you need your unique token, which is accesible from\nthe preferences page at " + TOKEN_URL + "\n\nAttempting to open a browser at that location..."); return open(TOKEN_URL, function(error) { if (error != null) { console.error("Unable to open a web browser in the current environment.\nPlease visit " + TOKEN_URL + " manually."); } - return callback(); + return visuals.widgets.ask('What\'s your token? (visible in the preferences page)', null, callback); }); - }, function(callback) { - if (params.token != null) { - return callback(null, params.token); - } - return visuals.widgets.ask('What\'s your token? (visible in the preferences page)', null, callback); }, function(token, callback) { return resin.auth.loginWithToken(token, done); } diff --git a/lib/actions/auth.coffee b/lib/actions/auth.coffee index d88219b2..454d654c 100644 --- a/lib/actions/auth.coffee +++ b/lib/actions/auth.coffee @@ -25,27 +25,26 @@ exports.login = """ action: (params, options, done) -> - console.info """ - To login to the Resin CLI, you need your unique token, which is accesible from - the preferences page at #{TOKEN_URL} - - Attempting to open a browser at that location... - """ - async.waterfall([ (callback) -> + return callback(null, params.token) if params.token? + + console.info """ + To login to the Resin CLI, you need your unique token, which is accesible from + the preferences page at #{TOKEN_URL} + + Attempting to open a browser at that location... + """ + open TOKEN_URL, (error) -> if error? console.error """ Unable to open a web browser in the current environment. Please visit #{TOKEN_URL} manually. """ - return callback() - (callback) -> - return callback(null, params.token) if params.token? - visuals.widgets.ask('What\'s your token? (visible in the preferences page)', null, callback) + visuals.widgets.ask('What\'s your token? (visible in the preferences page)', null, callback) (token, callback) -> resin.auth.loginWithToken(token, done)