whoami.js 804 B

12345678910111213141516171819202122232425262728293031
  1. const getIdentity = require('./utils/get-identity.js')
  2. const BaseCommand = require('./base-command.js')
  3. class Whoami extends BaseCommand {
  4. /* istanbul ignore next - see test/lib/load-all-commands.js */
  5. static get description () {
  6. return 'Display npm username'
  7. }
  8. /* istanbul ignore next - see test/lib/load-all-commands.js */
  9. static get name () {
  10. return 'whoami'
  11. }
  12. /* istanbul ignore next - see test/lib/load-all-commands.js */
  13. static get params () {
  14. return ['registry']
  15. }
  16. exec (args, cb) {
  17. this.whoami(args).then(() => cb()).catch(cb)
  18. }
  19. async whoami (args) {
  20. const username = await getIdentity(this.npm, this.npm.flatOptions)
  21. this.npm.output(
  22. this.npm.config.get('json') ? JSON.stringify(username) : username
  23. )
  24. }
  25. }
  26. module.exports = Whoami