mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-19 13:47:52 +00:00
Make login command accept options instead of colon separated credentials
For consistency
This commit is contained in:
parent
4d49655ab2
commit
8275275a05
@ -3,28 +3,52 @@ url = require('url')
|
|||||||
async = require('async')
|
async = require('async')
|
||||||
resin = require('resin-sdk')
|
resin = require('resin-sdk')
|
||||||
visuals = require('resin-cli-visuals')
|
visuals = require('resin-cli-visuals')
|
||||||
helpers = require('../helpers/helpers')
|
|
||||||
|
|
||||||
exports.login =
|
exports.login =
|
||||||
signature: 'login [credentials]'
|
signature: 'login'
|
||||||
description: 'login to resin.io'
|
description: 'login to resin.io'
|
||||||
help: '''
|
help: '''
|
||||||
Use this command to login to your resin.io account.
|
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 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.
|
credentials, in which case the tool will present you with an interactive login form.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
$ resin login username:password
|
$ resin login --username <username> --password <password>
|
||||||
$ resin login
|
$ 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) ->
|
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 [
|
async.waterfall [
|
||||||
|
|
||||||
(callback) ->
|
(callback) ->
|
||||||
if params.credentials?
|
if hasOptionCredentials
|
||||||
return helpers.parseCredentials(params.credentials, callback)
|
return callback(null, options)
|
||||||
else
|
else
|
||||||
return visuals.widgets.login(callback)
|
return visuals.widgets.login(callback)
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ capitano.globalOption
|
|||||||
signature: 'project'
|
signature: 'project'
|
||||||
parameter: 'path'
|
parameter: 'path'
|
||||||
description: 'project path'
|
description: 'project path'
|
||||||
alias: 'p'
|
alias: 'j'
|
||||||
|
|
||||||
# We don't do anything in response to this options
|
# We don't do anything in response to this options
|
||||||
# explicitly. We use InquirerJS to provide CLI widgets,
|
# explicitly. We use InquirerJS to provide CLI widgets,
|
||||||
|
@ -1,17 +1,5 @@
|
|||||||
_ = require('lodash')
|
|
||||||
getStdin = require('get-stdin')
|
getStdin = require('get-stdin')
|
||||||
|
|
||||||
exports.readStdin = (callback) ->
|
exports.readStdin = (callback) ->
|
||||||
getStdin (result) ->
|
getStdin (result) ->
|
||||||
return callback(null, 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)
|
|
||||||
|
@ -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()
|
|
Loading…
Reference in New Issue
Block a user