Handle authentication in quickstart

If the user is not logged in, make quickstart prompt for authentication
automatically.
This commit is contained in:
Juan Cruz Viotti 2016-01-12 10:12:04 -04:00
parent 8d709aea7d
commit 9b052c9aa5
3 changed files with 17 additions and 10 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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) ->