All files / src/commands/domain domain.favourite.command.js

51.42% Statements 18/35
100% Branches 1/1
0% Functions 0/1
51.42% Lines 18/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 193x 193x                                   193x 193x  
import { defineCommand } from '../../lib/define-command.js';
import { Logger } from '../../logger.js';
import * as Application from '../../models/application.js';
import { getDomainObject, getFavouriteDomain } from '../../models/domain.js';
import { aliasOption, appIdOrNameOption, humanJsonOutputFormatOption } from '../global.options.js';
 
export const domainFavouriteCommand = defineCommand({
  description: 'Manage the favourite domain name for an application',
  since: '2.7.0',
  options: {
    alias: aliasOption,
    app: appIdOrNameOption,
    format: humanJsonOutputFormatOption,
  },
  args: [],
  async handler(options) {
    const { alias, app: appIdOrName, format } = options;
    const { ownerId, appId } = await Application.resolveId(appIdOrName, alias);

    const favouriteDomain = await getFavouriteDomain({ ownerId, appId });

    switch (format) {
      case 'json':
        const domain = getDomainObject(favouriteDomain, favouriteDomain);
        Logger.printJson(domain);
        break;
      default:
        if (favouriteDomain == null) {
          return Logger.println('No favourite domain set');
        }
        Logger.println(favouriteDomain);
        break;
    }
  },
});