All files / src/commands/ng ng.unlink.command.js

72% Statements 18/25
100% Branches 1/1
0% Functions 0/1
72% Lines 18/25

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 26193x 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 { styleText } from '../../lib/style-text.js';
import { Logger } from '../../logger.js';
import * as networkGroupResources from '../../models/ng-resources.js';
import { orgaIdOrNameOption } from '../global.options.js';
import { ngIdOrLabelArg, ngResourceIdArg } from './ng.args.js';
 
export const ngUnlinkCommand = defineCommand({
  description:
    'Unlink a resource by its ID (app_xxx, external_xxx, mysql_xxx, postgresql_xxx, redis_xxx, etc.) from a Network Group',
  since: '3.12.0',
  options: {
    org: orgaIdOrNameOption,
  },
  args: [ngResourceIdArg, ngIdOrLabelArg],
  async handler(options, resourceId, ngIdOrLabel) {
    const { org } = options;

    await networkGroupResources.unlinkMember(ngIdOrLabel, resourceId.memberId, org);
    const ngText = ngIdOrLabel.ngResourceLabel ?? ngIdOrLabel.ngId;
    Logger.printSuccess(
      `Member ${styleText('green', resourceId.memberId)} successfully unlinked from Network Group ${styleText('green', ngText)}`,
    );
  },
});