All files / src/commands/k8s k8s.nodegroups.delete.command.js

55.88% Statements 19/34
100% Branches 1/1
0% Functions 0/1
55.88% Lines 19/34

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 35193x 193x 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 { k8sDeleteNodeGroup } from '../../lib/k8s.js';
import { ask } from '../../lib/prompts.js';
import { styleText } from '../../lib/style-text.js';
import { Logger } from '../../logger.js';
import { orgaIdOrNameOption, skipConfirmationOption } from '../global.options.js';
import { k8sIdOrNameArg, k8sNodeGroupIdOrNameArg } from './k8s.args.js';
 
export const k8sNodeGroupDeleteCommand = defineCommand({
  description: 'Delete a node group from a Kubernetes cluster',
  since: '4.9.0',
  options: {
    org: orgaIdOrNameOption,
    yes: skipConfirmationOption,
  },
  args: [k8sIdOrNameArg, k8sNodeGroupIdOrNameArg],
  async handler(options, clusterIdOrName, nodeGroupIdOrName) {
    const { org: orgIdOrName, yes } = options;

    if (!yes) {
      const proceed = await ask(
        `Are you sure you want to delete the node group ${styleText('blue', nodeGroupIdOrName)}?`,
        false,
      );
      if (!proceed) {
        Logger.println('Node group deletion cancelled');
        return;
      }
    }

    await k8sDeleteNodeGroup(orgIdOrName, clusterIdOrName, nodeGroupIdOrName);
    Logger.printSuccess(`Node group ${styleText('green', nodeGroupIdOrName)} successfully deleted`);
  },
});