All files / src/commands/emails emails.command.js

100% Statements 35/35
100% Branches 8/8
100% Functions 1/1
100% Lines 35/35

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 7x 7x 4x 4x 4x 2x 2x 2x 7x 7x 2x 2x 2x 1x 1x 1x 1x 2x 7x 193x 193x  
import { defineCommand } from '../../lib/define-command.js';
import { styleText } from '../../lib/style-text.js';
import { Logger } from '../../logger.js';
import { getUserEmailAddresses } from '../../models/emails.js';
import { humanJsonOutputFormatOption } from '../global.options.js';
 
export const emailsCommand = defineCommand({
  description: 'Manage email addresses of the current user',
  since: '3.13.0',
  options: {
    format: humanJsonOutputFormatOption,
  },
  args: [],
  async handler(options) {
    const { format } = options;
    const addresses = await getUserEmailAddresses();
 
    switch (format) {
      case 'json': {
        Logger.printJson(addresses);
        break;
      }
      case 'human':
      default: {
        Logger.println('✉️  Primary email address:');
        Logger.println(` • ${styleText('green', addresses.primary)}`);
        if (addresses.secondary.length > 0) {
          Logger.println();
          Logger.println(`✉️  ${addresses.secondary.length} secondary email address(es):`);
          addresses.secondary.forEach((address) => Logger.println(` • ${styleText('blue', address)}`));
        }
      }
    }
  },
});