UNPKG

964 BJavaScriptView Raw
1'use strict';
2
3// foreign modules
4
5const elegantSpinner = require('elegant-spinner');
6const logUpdate = require('log-update');
7
8// local modules
9
10const auth = require('../lib/auth');
11const asyncp = require('../lib/utils/asyncp');
12const whoami = require('../lib/whoami');
13
14// this module
15
16function 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
32module.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};