Reuse messages

This commit is contained in:
Juan Cruz Viotti 2016-01-12 10:44:11 -04:00
parent 78ab2af8ba
commit c3a5998d5c
6 changed files with 36 additions and 31 deletions

View File

@ -50,7 +50,7 @@ limitations under the License.
], ],
primary: true, primary: true,
action: function(params, options, done) { action: function(params, options, done) {
var Promise, _, auth, events, form, login, patterns, resin; var Promise, _, auth, events, form, login, messages, patterns, resin;
_ = require('lodash'); _ = require('lodash');
Promise = require('bluebird'); Promise = require('bluebird');
resin = require('resin-sdk'); resin = require('resin-sdk');
@ -58,6 +58,7 @@ limitations under the License.
auth = require('resin-cli-auth'); auth = require('resin-cli-auth');
form = require('resin-cli-form'); form = require('resin-cli-form');
patterns = require('../utils/patterns'); patterns = require('../utils/patterns');
messages = require('../utils/messages');
login = function(options) { login = function(options) {
if (options.token != null) { if (options.token != null) {
return Promise["try"](function() { return Promise["try"](function() {
@ -82,13 +83,13 @@ limitations under the License.
}); });
}; };
return resin.settings.get('resinUrl').then(function(resinUrl) { 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); console.log("\nLogging in to " + resinUrl);
return login(options); return login(options);
}).then(resin.auth.whoami).tap(function(username) { }).then(resin.auth.whoami).tap(function(username) {
events.send('user.login'); events.send('user.login');
console.info("Successfully logged in as: " + username); 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); }).nodeify(done);
} }
}; };

View File

@ -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.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); }).call(this);

View File

@ -16,7 +16,7 @@ limitations under the License.
*/ */
(function() { (function() {
var Promise, _, chalk, form, resin, validation, visuals; var Promise, _, chalk, form, messages, resin, validation, visuals;
_ = require('lodash'); _ = require('lodash');
@ -32,6 +32,8 @@ limitations under the License.
validation = require('./validation'); validation = require('./validation');
messages = require('./messages');
exports.authenticate = function(options) { exports.authenticate = function(options) {
return form.run([ return form.run([
{ {
@ -185,7 +187,7 @@ limitations under the License.
exports.printErrorMessage = function(message) { exports.printErrorMessage = function(message) {
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')); return console.error(chalk.red("\n" + messages.getHelp + "\n"));
}; };
}).call(this); }).call(this);

View File

@ -78,6 +78,7 @@ exports.login =
auth = require('resin-cli-auth') auth = require('resin-cli-auth')
form = require('resin-cli-form') form = require('resin-cli-form')
patterns = require('../utils/patterns') patterns = require('../utils/patterns')
messages = require('../utils/messages')
login = (options) -> login = (options) ->
if options.token? if options.token?
@ -99,15 +100,7 @@ exports.login =
return login(options) return login(options)
resin.settings.get('resinUrl').then (resinUrl) -> resin.settings.get('resinUrl').then (resinUrl) ->
console.log ''' console.log(messages.resinAsciiArt)
______ _ _
| ___ \\ (_) (_)
| |_/ /___ ___ _ _ __ _ ___
| // _ \\/ __| | '_ \\ | |/ _ \\
| |\\ \\ __/\\__ \\ | | | |_| | (_) |
\\_| \\_\\___||___/_|_| |_(_)_|\\___/
'''
console.log("\nLogging in to #{resinUrl}") console.log("\nLogging in to #{resinUrl}")
return login(options) return login(options)
.then(resin.auth.whoami) .then(resin.auth.whoami)
@ -115,23 +108,18 @@ exports.login =
events.send('user.login') events.send('user.login')
console.info("Successfully logged in as: #{username}") console.info("Successfully logged in as: #{username}")
console.info ''' console.info """
Now what? Now what?
Run the following command to get a device started with Resin.io #{messages.gettingStarted}
$ resin quickstart
Find out about more super powers by running: Find out about more super powers by running:
$ resin help $ resin help
If you need help, or just want to say hi, don't hesitate in reaching out at: #{messages.reachingOut}
"""
GitHub: https://github.com/resin-io/resin-cli/issues/new
Gitter: https://gitter.im/resin-io/chat
'''
.nodeify(done) .nodeify(done)
exports.logout = exports.logout =

View File

@ -10,3 +10,19 @@ exports.reachingOut = '''
GitHub: https://github.com/resin-io/resin-cli/issues/new GitHub: https://github.com/resin-io/resin-cli/issues/new
Gitter: https://gitter.im/resin-io/chat 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 = '''
______ _ _
| ___ \\ (_) (_)
| |_/ /___ ___ _ _ __ _ ___
| // _ \\/ __| | '_ \\ | |/ _ \\
| |\\ \\ __/\\__ \\ | | | |_| | (_) |
\\_| \\_\\___||___/_|_| |_(_)_|\\___/
'''

View File

@ -21,6 +21,7 @@ visuals = require('resin-cli-visuals')
resin = require('resin-sdk') resin = require('resin-sdk')
chalk = require('chalk') chalk = require('chalk')
validation = require('./validation') validation = require('./validation')
messages = require('./messages')
exports.authenticate = (options) -> exports.authenticate = (options) ->
return form.run [ return form.run [
@ -146,11 +147,4 @@ exports.awaitDevice = (uuid) ->
exports.printErrorMessage = (message) -> exports.printErrorMessage = (message) ->
console.error(chalk.red(message)) console.error(chalk.red(message))
console.error chalk.red ''' console.error(chalk.red("\n#{messages.getHelp}\n"))
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
'''