All files / src/commands/features features.enable.command.js

41.93% Statements 13/31
100% Branches 1/1
0% Functions 0/1
41.93% Lines 13/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  
import { EXPERIMENTAL_FEATURES, setFeature } from '../../config/features.js';
import { defineCommand } from '../../lib/define-command.js';
import { Logger } from '../../logger.js';
import { featuresArg } from './features.args.js';
 
export const featuresEnableCommand = defineCommand({
  description: 'Enable experimental features',
  since: '3.11.0',
  options: {},
  args: [featuresArg],
  async handler(_options, features) {
    const availableFeatures = Object.keys(EXPERIMENTAL_FEATURES);

    const unknownFeatures = features.filter((feature) => !availableFeatures.includes(feature));
    if (unknownFeatures.length > 0) {
      throw new Error(`Unavailable feature(s): ${unknownFeatures.join(', ')}`);
    }

    for (const featureName of features) {
      await setFeature(featureName, true);
      Logger.println(`Experimental feature '${featureName}' enabled`);
    }

    if (features.length === 1) {
      Logger.println(EXPERIMENTAL_FEATURES[features[0]].instructions);
    } else {
      Logger.println();
      Logger.println("To learn more about these experimental features, use 'clever features info FEATURE_NAME'");
    }
  },
});