1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 | const elegantSpinner = require('elegant-spinner');
|
6 | const logUpdate = require('log-update');
|
7 |
|
8 |
|
9 |
|
10 | const auth = require('../lib/auth');
|
11 | const asyncp = require('../lib/utils/asyncp');
|
12 | const whoami = require('../lib/whoami');
|
13 |
|
14 |
|
15 |
|
16 | function logAuthLookup (options) {
|
17 | const frame = elegantSpinner();
|
18 | let timer = setInterval(() => {
|
19 | logUpdate(`${options.origin}: ${frame()}`);
|
20 | }, 100);
|
21 | return whoami.lookupUser()
|
22 | .then((result) => {
|
23 | logUpdate(`${options.origin}: ${result.name} <${result.email}>`);
|
24 | clearTimeout(timer);
|
25 | })
|
26 | .catch((err) => {
|
27 | clearTimeout(timer);
|
28 | return Promise.reject(err);
|
29 | });
|
30 | }
|
31 |
|
32 | module.exports = function (input, flags, options) {
|
33 | auth.readAll()
|
34 | .then((auths) => {
|
35 | if (auths.length) {
|
36 | return asyncp.eachSeries(auths, asyncp.asyncify(logAuthLookup));
|
37 | }
|
38 | console.log('no authentication data found');
|
39 | });
|
40 | };
|