diff --git a/lib/actions/auth.coffee b/lib/actions/auth.coffee index c1006776..055a4fb2 100644 --- a/lib/actions/auth.coffee +++ b/lib/actions/auth.coffee @@ -3,28 +3,52 @@ url = require('url') async = require('async') resin = require('resin-sdk') visuals = require('resin-cli-visuals') -helpers = require('../helpers/helpers') exports.login = - signature: 'login [credentials]' + signature: 'login' description: 'login to resin.io' help: ''' Use this command to login to your resin.io account. You need to login before you can use most of the commands this tool provides. - You can pass your credentials as a colon separated string, or you can omit the + You can pass your credentials as `--username` and `--password` options, or you can omit the credentials, in which case the tool will present you with an interactive login form. Examples: - $ resin login username:password + $ resin login --username --password $ resin login ''' + options: [ + { + signature: 'username' + parameter: 'username' + description: 'user name' + alias: 'u' + } + { + signature: 'password' + parameter: 'user password' + description: 'user password' + alias: 'p' + } + ] action: (params, options, done) -> + + hasOptionCredentials = not _.isEmpty(options) + + if hasOptionCredentials + + if not options.username + return done(new Error('Missing username')) + + if not options.password + return done(new Error('Missing password')) + async.waterfall [ (callback) -> - if params.credentials? - return helpers.parseCredentials(params.credentials, callback) + if hasOptionCredentials + return callback(null, options) else return visuals.widgets.login(callback) diff --git a/lib/app.coffee b/lib/app.coffee index d150d871..495bc0a8 100644 --- a/lib/app.coffee +++ b/lib/app.coffee @@ -28,7 +28,7 @@ capitano.globalOption signature: 'project' parameter: 'path' description: 'project path' - alias: 'p' + alias: 'j' # We don't do anything in response to this options # explicitly. We use InquirerJS to provide CLI widgets, diff --git a/lib/helpers/helpers.coffee b/lib/helpers/helpers.coffee index 658cf220..3b16d753 100644 --- a/lib/helpers/helpers.coffee +++ b/lib/helpers/helpers.coffee @@ -1,17 +1,5 @@ -_ = require('lodash') getStdin = require('get-stdin') exports.readStdin = (callback) -> getStdin (result) -> return callback(null, result) - -exports.parseCredentials = (credentials, callback) -> - result = credentials.split(':') - - if result.length isnt 2 - error = new Error('Invalid credentials') - return callback?(error) - - callback? null, - username: _.first(result) - password: _.last(result) diff --git a/lib/helpers/helpers.spec.coffee b/lib/helpers/helpers.spec.coffee deleted file mode 100644 index 0ea950aa..00000000 --- a/lib/helpers/helpers.spec.coffee +++ /dev/null @@ -1,37 +0,0 @@ -expect = require('chai').expect -sinon = require('sinon') -_ = require('lodash') -helpers = require('./helpers') -resin = require('resin-sdk') - -describe 'Helpers:', -> - - describe '#parseCredentials', -> - - describe 'given colon separated credentials', -> - - username = null - password = null - - beforeEach -> - username = 'johndoe' - password = 'mysecret' - - it 'should parse the credentials correctly', (done) -> - helpers.parseCredentials "#{username}:#{password}", (error, credentials) -> - expect(error).to.not.exist - expect(credentials.username).to.equal(username) - expect(credentials.password).to.equal(password) - done() - - it 'should throw an error if it has two or more colons', (done) -> - helpers.parseCredentials "#{username}:#{password}:#{username}", (error, credentials) -> - expect(error).to.be.an.instanceof(Error) - expect(credentials).to.not.exist - done() - - it 'should throw an error if only the username is passed', (done) -> - helpers.parseCredentials username, (error, credentials) -> - expect(error).to.be.an.instanceof(Error) - expect(credentials).to.not.exist - done()