From 70ea8dd1a32e7de51554b9a496e2381150895554 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Tue, 12 Jan 2016 08:31:40 -0400 Subject: [PATCH 1/7] Redirect users to GitHub and Gitter in case of errors Users will ge a better experience by knowing exactly where to go for help if things go wrong. --- build/utils/patterns.js | 3 ++- lib/utils/patterns.coffee | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/build/utils/patterns.js b/build/utils/patterns.js index 18a182d2..16a3293a 100644 --- a/build/utils/patterns.js +++ b/build/utils/patterns.js @@ -134,7 +134,8 @@ limitations under the License. }; exports.printErrorMessage = function(message) { - return console.error(chalk.red(message)); + console.error(chalk.red(message)); + return console.error(chalk.red('\nIf you need help, don\'t hesitate in contacting us at:\n\n GitHub: https://github.com/resin-io/resin-cli/issues/new\n Gitter: https://gitter.im/resin-io/chat\n')); }; }).call(this); diff --git a/lib/utils/patterns.coffee b/lib/utils/patterns.coffee index 3ac65bf7..b4dd9e65 100644 --- a/lib/utils/patterns.coffee +++ b/lib/utils/patterns.coffee @@ -105,3 +105,11 @@ exports.awaitDevice = (uuid) -> exports.printErrorMessage = (message) -> console.error(chalk.red(message)) + console.error chalk.red ''' + + If you need help, don't hesitate in contacting us at: + + GitHub: https://github.com/resin-io/resin-cli/issues/new + Gitter: https://gitter.im/resin-io/chat + + ''' From 8d709aea7da26102d7260bdf226c9ee930d1860e Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Tue, 12 Jan 2016 09:07:15 -0400 Subject: [PATCH 2/7] Implement purely interactive login command The new login command interactively asks the user if he wants to login using web/credentials/token. --- build/actions/auth.js | 63 ++++++++++++++++----------------- build/utils/patterns.js | 50 ++++++++++++++++++++++++++ doc/cli.markdown | 17 +++++---- lib/actions/auth.coffee | 74 ++++++++++++++++++--------------------- lib/utils/patterns.coffee | 41 ++++++++++++++++++++++ 5 files changed, 166 insertions(+), 79 deletions(-) diff --git a/build/actions/auth.js b/build/actions/auth.js index 5c0dcf36..a4a57a93 100644 --- a/build/actions/auth.js +++ b/build/actions/auth.js @@ -19,13 +19,18 @@ limitations under the License. exports.login = { signature: 'login', description: 'login to resin.io', - help: 'Use this command to login to your resin.io account.\n\nThis command will open your web browser and prompt you to authorize the CLI\nfrom the dashboard.\n\nIf you don\'t have access to a web browser (e.g: running in a headless server),\nyou can fetch your authentication token from the preferences page and pass\nthe token option.\n\nAlternatively, you can pass the `--credentials` boolean option to perform\na credential-based authentication, with optional `--email` and `--password`\noptions to avoid interactive behaviour (unless you have 2FA enabled).\n\nExamples:\n\n $ resin login\n $ resin login --token "..."\n $ resin login --credentials\n $ resin login --credentials --email johndoe@gmail.com --password secret', + help: 'Use this command to login to your resin.io account.\n\nThis command will prompt you to login using the following login types:\n\n- Web authorization: open your web browser and prompt you to authorize the CLI\nfrom the dashboard.\n\n- Credentials: using email/password and 2FA.\n\n- Token: using the authentication token from the preferences page.\n\nExamples:\n\n $ resin login\n $ resin login --web\n $ resin login --token "..."\n $ resin login --credentials\n $ resin login --credentials --email johndoe@gmail.com --password secret', options: [ { signature: 'token', description: 'auth token', parameter: 'token', alias: 't' + }, { + signature: 'web', + description: 'web-based login', + boolean: true, + alias: 'w' }, { signature: 'credentials', description: 'credential-based login', @@ -45,48 +50,40 @@ limitations under the License. ], primary: true, action: function(params, options, done) { - var Promise, auth, events, form, resin, validation; + var Promise, _, auth, events, form, login, patterns, resin; + _ = require('lodash'); Promise = require('bluebird'); resin = require('resin-sdk'); events = require('resin-cli-events'); - form = require('resin-cli-form'); auth = require('resin-cli-auth'); - validation = require('../utils/validation'); - return resin.settings.get('resinUrl').then(function(resinUrl) { - console.log("Logging in to " + resinUrl); + form = require('resin-cli-form'); + patterns = require('../utils/patterns'); + login = function(options) { if (options.token != null) { - return resin.auth.loginWithToken(options.token); - } else if (options.credentials) { - return form.run([ - { - message: 'Email:', - name: 'email', - type: 'input', - validate: validation.validateEmail - }, { - message: 'Password:', - name: 'password', - type: 'password' - } - ], { - override: options - }).then(resin.auth.login).then(resin.auth.twoFactor.isPassed).then(function(isTwoFactorAuthPassed) { - if (isTwoFactorAuthPassed) { - return; + return Promise["try"](function() { + if (_.isString(options.token)) { + return options.token; } return form.ask({ - message: 'Two factor auth challenge:', - name: 'code', + message: 'Token (from the preferences page)', + name: 'token', type: 'input' - }).then(resin.auth.twoFactor.challenge)["catch"](function() { - return resin.auth.logout().then(function() { - throw new Error('Invalid two factor authentication code'); - }); }); - }); + }).then(resin.auth.loginWithToken); + } else if (options.credentials) { + return patterns.authenticate(options); + } else if (options.web) { + console.info('Connecting to the web dashboard'); + return auth.login(); } - console.info('Connecting to the web dashboard'); - return auth.login(); + return patterns.askLoginType().then(function(loginType) { + options[loginType] = true; + return login(options); + }); + }; + return resin.settings.get('resinUrl').then(function(resinUrl) { + console.log("Logging in to " + resinUrl); + return login(options); }).then(resin.auth.whoami).tap(function(username) { console.info("Successfully logged in as: " + username); return events.send('user.login'); diff --git a/build/utils/patterns.js b/build/utils/patterns.js index 16a3293a..12acf2b1 100644 --- a/build/utils/patterns.js +++ b/build/utils/patterns.js @@ -32,6 +32,56 @@ limitations under the License. validation = require('./validation'); + exports.authenticate = function(options) { + return form.run([ + { + message: 'Email:', + name: 'email', + type: 'input', + validate: validation.validateEmail + }, { + message: 'Password:', + name: 'password', + type: 'password' + } + ], { + override: options + }).then(resin.auth.login).then(resin.auth.twoFactor.isPassed).then(function(isTwoFactorAuthPassed) { + if (isTwoFactorAuthPassed) { + return; + } + return form.ask({ + message: 'Two factor auth challenge:', + name: 'code', + type: 'input' + }).then(resin.auth.twoFactor.challenge)["catch"](function() { + return resin.auth.logout().then(function() { + throw new Error('Invalid two factor authentication code'); + }); + }); + }); + }; + + exports.askLoginType = function() { + return form.ask({ + message: 'How would you like to login?', + name: 'loginType', + type: 'list', + choices: [ + { + name: 'Web authorization (recommended)', + value: 'web' + }, { + name: 'Credentials', + value: 'credentials' + }, { + name: 'Authentication token', + value: 'token' + } + ] + }); + }; + exports.selectDeviceType = function() { return resin.models.device.getSupportedDeviceTypes().then(function(deviceTypes) { return form.ask({ diff --git a/doc/cli.markdown b/doc/cli.markdown index 821d918c..55c8d8d4 100644 --- a/doc/cli.markdown +++ b/doc/cli.markdown @@ -165,20 +165,19 @@ confirm non interactively Use this command to login to your resin.io account. -This command will open your web browser and prompt you to authorize the CLI +This command will prompt you to login using the following login types: + +- Web authorization: open your web browser and prompt you to authorize the CLI from the dashboard. -If you don't have access to a web browser (e.g: running in a headless server), -you can fetch your authentication token from the preferences page and pass -the token option. +- Credentials: using email/password and 2FA. -Alternatively, you can pass the `--credentials` boolean option to perform -a credential-based authentication, with optional `--email` and `--password` -options to avoid interactive behaviour (unless you have 2FA enabled). +- Token: using the authentication token from the preferences page. Examples: $ resin login + $ resin login --web $ resin login --token "..." $ resin login --credentials $ resin login --credentials --email johndoe@gmail.com --password secret @@ -189,6 +188,10 @@ Examples: auth token +#### --web, -w + +web-based login + #### --credentials, -c credential-based login diff --git a/lib/actions/auth.coffee b/lib/actions/auth.coffee index b962039a..ec08b029 100644 --- a/lib/actions/auth.coffee +++ b/lib/actions/auth.coffee @@ -20,20 +20,19 @@ exports.login = help: ''' Use this command to login to your resin.io account. - This command will open your web browser and prompt you to authorize the CLI + This command will prompt you to login using the following login types: + + - Web authorization: open your web browser and prompt you to authorize the CLI from the dashboard. - If you don't have access to a web browser (e.g: running in a headless server), - you can fetch your authentication token from the preferences page and pass - the token option. + - Credentials: using email/password and 2FA. - Alternatively, you can pass the `--credentials` boolean option to perform - a credential-based authentication, with optional `--email` and `--password` - options to avoid interactive behaviour (unless you have 2FA enabled). + - Token: using the authentication token from the preferences page. Examples: $ resin login + $ resin login --web $ resin login --token "..." $ resin login --credentials $ resin login --credentials --email johndoe@gmail.com --password secret @@ -45,6 +44,12 @@ exports.login = parameter: 'token' alias: 't' } + { + signature: 'web' + description: 'web-based login' + boolean: true + alias: 'w' + } { signature: 'credentials' description: 'credential-based login' @@ -66,45 +71,36 @@ exports.login = ] primary: true action: (params, options, done) -> + _ = require('lodash') Promise = require('bluebird') resin = require('resin-sdk') events = require('resin-cli-events') - form = require('resin-cli-form') auth = require('resin-cli-auth') - validation = require('../utils/validation') + form = require('resin-cli-form') + patterns = require('../utils/patterns') + + login = (options) -> + if options.token? + return Promise.try -> + return options.token if _.isString(options.token) + return form.ask + message: 'Token (from the preferences page)' + name: 'token' + type: 'input' + .then(resin.auth.loginWithToken) + else if options.credentials + return patterns.authenticate(options) + else if options.web + console.info('Connecting to the web dashboard') + return auth.login() + + return patterns.askLoginType().then (loginType) -> + options[loginType] = true + return login(options) resin.settings.get('resinUrl').then (resinUrl) -> console.log("Logging in to #{resinUrl}") - - if options.token? - return resin.auth.loginWithToken(options.token) - else if options.credentials - return form.run [ - message: 'Email:' - name: 'email' - type: 'input' - validate: validation.validateEmail - , - message: 'Password:' - name: 'password' - type: 'password' - ], - override: options - .then(resin.auth.login) - .then(resin.auth.twoFactor.isPassed) - .then (isTwoFactorAuthPassed) -> - return if isTwoFactorAuthPassed - return form.ask - message: 'Two factor auth challenge:' - name: 'code' - type: 'input' - .then(resin.auth.twoFactor.challenge) - .catch -> - resin.auth.logout().then -> - throw new Error('Invalid two factor authentication code') - - console.info('Connecting to the web dashboard') - return auth.login() + return login(options) .then(resin.auth.whoami) .tap (username) -> console.info("Successfully logged in as: #{username}") diff --git a/lib/utils/patterns.coffee b/lib/utils/patterns.coffee index b4dd9e65..ce32e833 100644 --- a/lib/utils/patterns.coffee +++ b/lib/utils/patterns.coffee @@ -22,6 +22,47 @@ resin = require('resin-sdk') chalk = require('chalk') validation = require('./validation') +exports.authenticate = (options) -> + return form.run [ + message: 'Email:' + name: 'email' + type: 'input' + validate: validation.validateEmail + , + message: 'Password:' + name: 'password' + type: 'password' + ], + override: options + .then(resin.auth.login) + .then(resin.auth.twoFactor.isPassed) + .then (isTwoFactorAuthPassed) -> + return if isTwoFactorAuthPassed + return form.ask + message: 'Two factor auth challenge:' + name: 'code' + type: 'input' + .then(resin.auth.twoFactor.challenge) + .catch -> + resin.auth.logout().then -> + throw new Error('Invalid two factor authentication code') + +exports.askLoginType = -> + return form.ask + message: 'How would you like to login?' + name: 'loginType' + type: 'list' + choices: [ + name: 'Web authorization (recommended)' + value: 'web' + , + name: 'Credentials' + value: 'credentials' + , + name: 'Authentication token' + value: 'token' + ] + exports.selectDeviceType = -> resin.models.device.getSupportedDeviceTypes().then (deviceTypes) -> return form.ask From 9b052c9aa51515264023e469fdcbca8a042194c0 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Tue, 12 Jan 2016 10:12:04 -0400 Subject: [PATCH 3/7] Handle authentication in quickstart If the user is not logged in, make quickstart prompt for authentication automatically. --- README.md | 6 ------ build/actions/wizard.js | 12 ++++++++++-- lib/actions/wizard.coffee | 9 +++++++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 4823e519..53ae9c53 100644 --- a/README.md +++ b/README.md @@ -27,12 +27,6 @@ This might require elevated privileges in some environments. $ npm install --global --production resin-cli ``` -### Login - -```sh -$ resin login -``` - ### List available commands ```sh diff --git a/build/actions/wizard.js b/build/actions/wizard.js index 8fbf4ed7..09448d74 100644 --- a/build/actions/wizard.js +++ b/build/actions/wizard.js @@ -20,7 +20,6 @@ limitations under the License. signature: 'quickstart [name]', description: 'getting started with resin.io', help: 'Use this command to run a friendly wizard to get started with resin.io.\n\nThe wizard will guide you through:\n\n - Create an application.\n - Initialise an SDCard with the resin.io operating system.\n - Associate an existing project directory with your resin.io application.\n - Push your project to your devices.\n\nExamples:\n\n $ resin quickstart\n $ resin quickstart MyApp', - permission: 'user', primary: true, action: function(params, options, done) { var Promise, capitano, patterns, resin; @@ -28,7 +27,16 @@ limitations under the License. capitano = Promise.promisifyAll(require('capitano')); resin = require('resin-sdk'); patterns = require('../utils/patterns'); - return Promise["try"](function() { + return resin.auth.isLoggedIn().then(function(isLoggedIn) { + if (isLoggedIn) { + return; + } + console.info('Looks like you\'re not logged in yet!'); + console.info('Lets go through a quick wizard to get you started.\n'); + return capitano.runAsync('login').then(function() { + return require('fs').readdirSync('/Users/jviotti/.resin'); + }); + }).then(function() { if (params.name != null) { return; } diff --git a/lib/actions/wizard.coffee b/lib/actions/wizard.coffee index f91bfeeb..fc4fe433 100644 --- a/lib/actions/wizard.coffee +++ b/lib/actions/wizard.coffee @@ -32,7 +32,6 @@ exports.wizard = $ resin quickstart $ resin quickstart MyApp ''' - permission: 'user' primary: true action: (params, options, done) -> Promise = require('bluebird') @@ -40,7 +39,13 @@ exports.wizard = resin = require('resin-sdk') patterns = require('../utils/patterns') - Promise.try -> + resin.auth.isLoggedIn().then (isLoggedIn) -> + return if isLoggedIn + console.info('Looks like you\'re not logged in yet!') + console.info('Lets go through a quick wizard to get you started.\n') + return capitano.runAsync('login').then -> + require('fs').readdirSync('/Users/jviotti/.resin') + .then -> return if params.name? patterns.selectOrCreateApplication().tap (applicationName) -> resin.models.application.has(applicationName).then (hasApplication) -> From 86cac606e4e058c13b179592224689d03ecea890 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Tue, 12 Jan 2016 10:23:46 -0400 Subject: [PATCH 4/7] Add Resin.io ASCII art in login --- build/actions/auth.js | 3 ++- lib/actions/auth.coffee | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/build/actions/auth.js b/build/actions/auth.js index a4a57a93..96451848 100644 --- a/build/actions/auth.js +++ b/build/actions/auth.js @@ -82,7 +82,8 @@ limitations under the License. }); }; return resin.settings.get('resinUrl').then(function(resinUrl) { - console.log("Logging in to " + resinUrl); + console.log('______ _ _\n| ___ \\ (_) (_)\n| |_/ /___ ___ _ _ __ _ ___\n| // _ \\/ __| | \'_ \\ | |/ _ \\\n| |\\ \\ __/\\__ \\ | | | |_| | (_) |\n\\_| \\_\\___||___/_|_| |_(_)_|\\___/'); + console.log("\nLogging in to " + resinUrl); return login(options); }).then(resin.auth.whoami).tap(function(username) { console.info("Successfully logged in as: " + username); diff --git a/lib/actions/auth.coffee b/lib/actions/auth.coffee index ec08b029..5e5ef0e0 100644 --- a/lib/actions/auth.coffee +++ b/lib/actions/auth.coffee @@ -99,7 +99,16 @@ exports.login = return login(options) resin.settings.get('resinUrl').then (resinUrl) -> - console.log("Logging in to #{resinUrl}") + console.log ''' + ______ _ _ + | ___ \\ (_) (_) + | |_/ /___ ___ _ _ __ _ ___ + | // _ \\/ __| | '_ \\ | |/ _ \\ + | |\\ \\ __/\\__ \\ | | | |_| | (_) | + \\_| \\_\\___||___/_|_| |_(_)_|\\___/ + ''' + + console.log("\nLogging in to #{resinUrl}") return login(options) .then(resin.auth.whoami) .tap (username) -> From 11354de5967aaa4f98f7318e51aa3dfd21413b31 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Tue, 12 Jan 2016 10:30:56 -0400 Subject: [PATCH 5/7] Print an informative message after successful login --- build/actions/auth.js | 3 ++- lib/actions/auth.coffee | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/build/actions/auth.js b/build/actions/auth.js index 96451848..88719055 100644 --- a/build/actions/auth.js +++ b/build/actions/auth.js @@ -86,8 +86,9 @@ limitations under the License. console.log("\nLogging in to " + resinUrl); return login(options); }).then(resin.auth.whoami).tap(function(username) { + events.send('user.login'); console.info("Successfully logged in as: " + username); - return events.send('user.login'); + return console.info('\nNow what?\n\nRun the following command to get a device started with Resin.io\n\n $ resin quickstart\n\nFind out about more super powers by running:\n\n $ resin help\n\nIf you need help, or just want to say hi, don\'t hesitate in reaching out at:\n\n GitHub: https://github.com/resin-io/resin-cli/issues/new\n Gitter: https://gitter.im/resin-io/chat'); }).nodeify(done); } }; diff --git a/lib/actions/auth.coffee b/lib/actions/auth.coffee index 5e5ef0e0..cc0a5e34 100644 --- a/lib/actions/auth.coffee +++ b/lib/actions/auth.coffee @@ -112,8 +112,26 @@ exports.login = return login(options) .then(resin.auth.whoami) .tap (username) -> - console.info("Successfully logged in as: #{username}") events.send('user.login') + + console.info("Successfully logged in as: #{username}") + console.info ''' + + Now what? + + Run the following command to get a device started with Resin.io + + $ resin quickstart + + Find out about more super powers by running: + + $ resin help + + If you need help, or just want to say hi, don't hesitate in reaching out at: + + GitHub: https://github.com/resin-io/resin-cli/issues/new + Gitter: https://gitter.im/resin-io/chat + ''' .nodeify(done) exports.logout = From 78ab2af8baefd7a5aa659b4b652876ead9ce71fb Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Tue, 12 Jan 2016 10:39:29 -0400 Subject: [PATCH 6/7] Print verbose help in resin help command --- build/actions/help.js | 8 ++++++-- build/utils/messages.js | 6 ++++++ lib/actions/help.coffee | 5 ++++- lib/utils/messages.coffee | 12 ++++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 build/utils/messages.js create mode 100644 lib/utils/messages.coffee diff --git a/build/actions/help.js b/build/actions/help.js index 7a05bb10..88b2b12f 100644 --- a/build/actions/help.js +++ b/build/actions/help.js @@ -16,7 +16,7 @@ limitations under the License. */ (function() { - var _, capitano, columnify, command, general, indent, parse, print; + var _, capitano, columnify, command, general, indent, messages, parse, print; _ = require('lodash'); @@ -26,6 +26,8 @@ limitations under the License. columnify = require('columnify'); + messages = require('../utils/messages'); + parse = function(object) { return _.object(_.map(object, function(item) { var signature; @@ -55,7 +57,9 @@ limitations under the License. general = function(params, options, done) { var commands, groupedCommands; console.log('Usage: resin [COMMAND] [OPTIONS]\n'); - console.log('Primary commands:\n'); + console.log(messages.gettingStarted + "\n"); + console.log(messages.reachingOut); + console.log('\nPrimary commands:\n'); commands = _.reject(capitano.state.commands, function(command) { return command.isWildcard(); }); diff --git a/build/utils/messages.js b/build/utils/messages.js new file mode 100644 index 00000000..bf6d5736 --- /dev/null +++ b/build/utils/messages.js @@ -0,0 +1,6 @@ +(function() { + exports.gettingStarted = 'Run the following command to get a device started with Resin.io\n\n $ resin quickstart'; + + exports.reachingOut = 'If you need help, or just want to say hi, don\'t hesitate in reaching out at:\n\n GitHub: https://github.com/resin-io/resin-cli/issues/new\n Gitter: https://gitter.im/resin-io/chat'; + +}).call(this); diff --git a/lib/actions/help.coffee b/lib/actions/help.coffee index 3e629a3f..0c3f7430 100644 --- a/lib/actions/help.coffee +++ b/lib/actions/help.coffee @@ -18,6 +18,7 @@ _ = require('lodash') _.str = require('underscore.string') capitano = require('capitano') columnify = require('columnify') +messages = require('../utils/messages') parse = (object) -> return _.object _.map object, (item) -> @@ -46,7 +47,9 @@ print = (data) -> general = (params, options, done) -> console.log('Usage: resin [COMMAND] [OPTIONS]\n') - console.log('Primary commands:\n') + console.log("#{messages.gettingStarted}\n") + console.log(messages.reachingOut) + console.log('\nPrimary commands:\n') # We do not want the wildcard command # to be printed in the help screen. diff --git a/lib/utils/messages.coffee b/lib/utils/messages.coffee new file mode 100644 index 00000000..04a8bf16 --- /dev/null +++ b/lib/utils/messages.coffee @@ -0,0 +1,12 @@ +exports.gettingStarted = ''' + Run the following command to get a device started with Resin.io + + $ resin quickstart +''' + +exports.reachingOut = ''' + If you need help, or just want to say hi, don't hesitate in reaching out at: + + GitHub: https://github.com/resin-io/resin-cli/issues/new + Gitter: https://gitter.im/resin-io/chat +''' From c3a5998d5c31b66ce55cf00105649003dfa009a0 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Tue, 12 Jan 2016 10:44:11 -0400 Subject: [PATCH 7/7] Reuse messages --- build/actions/auth.js | 7 ++++--- build/utils/messages.js | 4 ++++ build/utils/patterns.js | 6 ++++-- lib/actions/auth.coffee | 24 ++++++------------------ lib/utils/messages.coffee | 16 ++++++++++++++++ lib/utils/patterns.coffee | 10 ++-------- 6 files changed, 36 insertions(+), 31 deletions(-) diff --git a/build/actions/auth.js b/build/actions/auth.js index 88719055..c1c9ac49 100644 --- a/build/actions/auth.js +++ b/build/actions/auth.js @@ -50,7 +50,7 @@ limitations under the License. ], primary: true, action: function(params, options, done) { - var Promise, _, auth, events, form, login, patterns, resin; + var Promise, _, auth, events, form, login, messages, patterns, resin; _ = require('lodash'); Promise = require('bluebird'); resin = require('resin-sdk'); @@ -58,6 +58,7 @@ limitations under the License. auth = require('resin-cli-auth'); form = require('resin-cli-form'); patterns = require('../utils/patterns'); + messages = require('../utils/messages'); login = function(options) { if (options.token != null) { return Promise["try"](function() { @@ -82,13 +83,13 @@ limitations under the License. }); }; return resin.settings.get('resinUrl').then(function(resinUrl) { - console.log('______ _ _\n| ___ \\ (_) (_)\n| |_/ /___ ___ _ _ __ _ ___\n| // _ \\/ __| | \'_ \\ | |/ _ \\\n| |\\ \\ __/\\__ \\ | | | |_| | (_) |\n\\_| \\_\\___||___/_|_| |_(_)_|\\___/'); + console.log(messages.resinAsciiArt); console.log("\nLogging in to " + resinUrl); return login(options); }).then(resin.auth.whoami).tap(function(username) { events.send('user.login'); console.info("Successfully logged in as: " + username); - return console.info('\nNow what?\n\nRun the following command to get a device started with Resin.io\n\n $ resin quickstart\n\nFind out about more super powers by running:\n\n $ resin help\n\nIf you need help, or just want to say hi, don\'t hesitate in reaching out at:\n\n GitHub: https://github.com/resin-io/resin-cli/issues/new\n Gitter: https://gitter.im/resin-io/chat'); + return console.info("\nNow what?\n\n" + messages.gettingStarted + "\n\nFind out about more super powers by running:\n\n $ resin help\n\n" + messages.reachingOut); }).nodeify(done); } }; diff --git a/build/utils/messages.js b/build/utils/messages.js index bf6d5736..c1907805 100644 --- a/build/utils/messages.js +++ b/build/utils/messages.js @@ -3,4 +3,8 @@ exports.reachingOut = 'If you need help, or just want to say hi, don\'t hesitate in reaching out at:\n\n GitHub: https://github.com/resin-io/resin-cli/issues/new\n Gitter: https://gitter.im/resin-io/chat'; + exports.getHelp = 'If you need help, don\'t hesitate in contacting us at:\n\n GitHub: https://github.com/resin-io/resin-cli/issues/new\n Gitter: https://gitter.im/resin-io/chat'; + + exports.resinAsciiArt = '______ _ _\n| ___ \\ (_) (_)\n| |_/ /___ ___ _ _ __ _ ___\n| // _ \\/ __| | \'_ \\ | |/ _ \\\n| |\\ \\ __/\\__ \\ | | | |_| | (_) |\n\\_| \\_\\___||___/_|_| |_(_)_|\\___/'; + }).call(this); diff --git a/build/utils/patterns.js b/build/utils/patterns.js index 12acf2b1..719e3539 100644 --- a/build/utils/patterns.js +++ b/build/utils/patterns.js @@ -16,7 +16,7 @@ limitations under the License. */ (function() { - var Promise, _, chalk, form, resin, validation, visuals; + var Promise, _, chalk, form, messages, resin, validation, visuals; _ = require('lodash'); @@ -32,6 +32,8 @@ limitations under the License. validation = require('./validation'); + messages = require('./messages'); + exports.authenticate = function(options) { return form.run([ { @@ -185,7 +187,7 @@ limitations under the License. exports.printErrorMessage = function(message) { console.error(chalk.red(message)); - return console.error(chalk.red('\nIf you need help, don\'t hesitate in contacting us at:\n\n GitHub: https://github.com/resin-io/resin-cli/issues/new\n Gitter: https://gitter.im/resin-io/chat\n')); + return console.error(chalk.red("\n" + messages.getHelp + "\n")); }; }).call(this); diff --git a/lib/actions/auth.coffee b/lib/actions/auth.coffee index cc0a5e34..1c15c443 100644 --- a/lib/actions/auth.coffee +++ b/lib/actions/auth.coffee @@ -78,6 +78,7 @@ exports.login = auth = require('resin-cli-auth') form = require('resin-cli-form') patterns = require('../utils/patterns') + messages = require('../utils/messages') login = (options) -> if options.token? @@ -99,15 +100,7 @@ exports.login = return login(options) resin.settings.get('resinUrl').then (resinUrl) -> - console.log ''' - ______ _ _ - | ___ \\ (_) (_) - | |_/ /___ ___ _ _ __ _ ___ - | // _ \\/ __| | '_ \\ | |/ _ \\ - | |\\ \\ __/\\__ \\ | | | |_| | (_) | - \\_| \\_\\___||___/_|_| |_(_)_|\\___/ - ''' - + console.log(messages.resinAsciiArt) console.log("\nLogging in to #{resinUrl}") return login(options) .then(resin.auth.whoami) @@ -115,23 +108,18 @@ exports.login = events.send('user.login') console.info("Successfully logged in as: #{username}") - console.info ''' + console.info """ Now what? - Run the following command to get a device started with Resin.io - - $ resin quickstart + #{messages.gettingStarted} Find out about more super powers by running: $ resin help - If you need help, or just want to say hi, don't hesitate in reaching out at: - - GitHub: https://github.com/resin-io/resin-cli/issues/new - Gitter: https://gitter.im/resin-io/chat - ''' + #{messages.reachingOut} + """ .nodeify(done) exports.logout = diff --git a/lib/utils/messages.coffee b/lib/utils/messages.coffee index 04a8bf16..55ec692e 100644 --- a/lib/utils/messages.coffee +++ b/lib/utils/messages.coffee @@ -10,3 +10,19 @@ exports.reachingOut = ''' GitHub: https://github.com/resin-io/resin-cli/issues/new Gitter: https://gitter.im/resin-io/chat ''' + +exports.getHelp = ''' + If you need help, don't hesitate in contacting us at: + + GitHub: https://github.com/resin-io/resin-cli/issues/new + Gitter: https://gitter.im/resin-io/chat +''' + +exports.resinAsciiArt = ''' + ______ _ _ + | ___ \\ (_) (_) + | |_/ /___ ___ _ _ __ _ ___ + | // _ \\/ __| | '_ \\ | |/ _ \\ + | |\\ \\ __/\\__ \\ | | | |_| | (_) | + \\_| \\_\\___||___/_|_| |_(_)_|\\___/ +''' diff --git a/lib/utils/patterns.coffee b/lib/utils/patterns.coffee index ce32e833..fcaec301 100644 --- a/lib/utils/patterns.coffee +++ b/lib/utils/patterns.coffee @@ -21,6 +21,7 @@ visuals = require('resin-cli-visuals') resin = require('resin-sdk') chalk = require('chalk') validation = require('./validation') +messages = require('./messages') exports.authenticate = (options) -> return form.run [ @@ -146,11 +147,4 @@ exports.awaitDevice = (uuid) -> exports.printErrorMessage = (message) -> console.error(chalk.red(message)) - console.error chalk.red ''' - - If you need help, don't hesitate in contacting us at: - - GitHub: https://github.com/resin-io/resin-cli/issues/new - Gitter: https://gitter.im/resin-io/chat - - ''' + console.error(chalk.red("\n#{messages.getHelp}\n"))