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

70.83% Statements 17/24
100% Branches 1/1
0% Functions 0/1
70.83% Lines 17/24

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 25193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x               193x 193x  
import { defineCommand } from '../../lib/define-command.js';
import * as Application from '../../models/application.js';
import * as Domain from '../../models/domain.js';
import { openBrowser } from '../../models/utils.js';
import { aliasOption, appIdOrNameOption } from '../global.options.js';
 
export const openCommand = defineCommand({
  description: 'Open an application in the Console',
  since: '0.5.0',
  options: {
    alias: aliasOption,
    app: appIdOrNameOption,
  },
  args: [],
  async handler(options) {
    const { alias, app: appIdOrName } = options;
    const { ownerId, appId } = await Application.resolveId(appIdOrName, alias);

    const vhost = await Domain.getBest(appId, ownerId);
    const url = 'https://' + vhost.fqdn;

    await openBrowser(url, 'Opening the application in the browser…');
  },
});