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

100% Statements 31/31
100% Branches 6/6
100% Functions 1/1
100% Lines 31/31

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 32193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 6x 6x 6x 6x 1x 1x 6x 5x 2x 3x 3x 3x 3x 193x 193x  
import { defineCommand } from '../../lib/define-command.js';
import { styleText } from '../../lib/style-text.js';
import { Logger } from '../../logger.js';
import * as Application from '../../models/application.js';
import { appIdOrNameArg } from '../global.args.js';
import { aliasCreationOption, orgaIdOrNameOption } from '../global.options.js';
 
export const linkCommand = defineCommand({
  description: 'Link this repo to an existing application',
  since: '0.2.0',
  options: {
    alias: aliasCreationOption,
    org: orgaIdOrNameOption,
  },
  args: [appIdOrNameArg],
  async handler(options, app) {
    const { org: orgaIdOrName, alias } = options;
 
    let appConfigEntry;
    if (app.app_id != null && orgaIdOrName != null) {
      Logger.warn("You've specified a unique application ID, organisation option will be ignored");
      appConfigEntry = await Application.linkRepo(app, null, alias);
    } else {
      appConfigEntry = await Application.linkRepo(app, orgaIdOrName, alias);
    }
 
    Logger.printSuccess(
      `Application ${styleText('green', appConfigEntry.app_id)} has been successfully linked to local alias ${styleText('green', appConfigEntry.alias)}!`,
    );
  },
});