UNPKG

growthbook

Version:

The GrowthBook command-line interface (CLI) for working with the GrowthBook A/B testing, feature flagging, and experimentation platform

59 lines (58 loc) 2.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@oclif/core"); const cli_1 = require("../../utils/cli"); const config_1 = require("../../utils/config"); const constants_1 = require("../../utils/constants"); const features_repository_1 = require("../../repositories/features.repository"); class FeaturesToggle extends core_1.Command { async run() { const { args: { featureKey, }, flags: { enabled, reason = '', environment, profile, apiBaseUrl, }, } = await this.parse(FeaturesToggle); const profileUsed = profile || constants_1.DEFAULT_GROWTHBOOK_PROFILE; const { apiKey, apiBaseUrl: configApiBaseUrl } = (0, config_1.getGrowthBookProfileConfigAndThrowForCommand)(profileUsed, this); const baseUrlUsed = apiBaseUrl || configApiBaseUrl || constants_1.DEFAULT_GROWTHBOOK_BASE_URL; const parsedEnabled = (0, cli_1.parseBooleanFromString)(enabled) || false; const featuresRepo = new features_repository_1.FeaturesRepository({ apiKey, apiBaseUrl: baseUrlUsed, }); const updatedFeature = await featuresRepo.toggleFeature({ enabled: parsedEnabled, environment, featureKey, reason, }); this.logJson(updatedFeature); this.log(`\n${cli_1.Icons.checkmark} The feature was updated!`); } } exports.default = FeaturesToggle; FeaturesToggle.description = 'Toggle a feature on or off for a specific environment'; FeaturesToggle.examples = [ '<%= config.bin %> <%= command.id %>', ]; FeaturesToggle.flags = { ...cli_1.baseGrowthBookCliFlags, environment: core_1.Flags.string({ char: 'e', description: 'Environment that you would like to toggle', required: true, }), enabled: core_1.Flags.string({ char: 'n', description: 'Enabled state of the feature', required: true, options: ['true', 'false', 'on', 'off', '1', '0'], }), reason: core_1.Flags.string({ char: 'r', description: 'The reason for toggling it on', required: false, }), }; FeaturesToggle.args = { featureKey: core_1.Args.string({ description: 'Feature key to toggle', required: true, }), };