Skip to content

Commit

Permalink
feat(ls): list current set user
Browse files Browse the repository at this point in the history
  • Loading branch information
trs committed Nov 23, 2017
1 parent ba8a3df commit a336951
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/commands/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,37 @@ const ls = {
_mapUserTokens
};

function _mapUserTokens(users) {
function _mapUserTokens(users, currentUser) {
return Object.keys(users).map(name => {
const user = users[name];
const token = user.token;
const censoredToken = token.length > 8 ? `...${token.substr(token.length - 8)}` : token;

return {
name,
token: censoredToken
token: censoredToken,
current: name === currentUser ? '\u2713' : ''
};
});
}

function handle() {
const users = storage.getUsers();
const currentUser = storage.getCurrentUser();

if (!Object.keys(users).length) {
console.log('No users added yet!');
return false;
}

const nameData = ls._mapUserTokens(users);
const columns = columnify(nameData);
const nameData = ls._mapUserTokens(users, currentUser);
const columns = columnify(nameData, {
config: {
current: {
align: 'center'
}
}
});
console.log(columns);
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/commands/use.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ function handle(name) {
return use._writeNpmrc(npmrcPath, updatedText);
})
.then(() => {
console.log(`Now using ${name}.`);
storage.setCurrentUser(name);
console.log(`NPM login user: ${name}.`);
return true;
})
.catch(errors.handle);
Expand Down

0 comments on commit a336951

Please sign in to comment.