Skip to content

Feature Flags

Jace Roell edited this page Apr 30, 2026 · 4 revisions

The Feature Flags system provides a way to manage feature toggles and configuration options in Zowe Explorer extensions.

Basic Usage

Import the Feature Flags from the Zowe Explorer API:

import { FeatureFlags, FeatureFlagsAccess, FlagAccessLevel } from "@zowe/zowe-explorer-api";

Setting and Getting Flags

// Set a flag (memory only)
await FeatureFlags.set("enableNewUI", true);

// Set a flag and save to disk
await FeatureFlags.set("maxRetries", 5, true);

// Get a flag value
const isEnabled = FeatureFlags.get("enableNewUI");
const maxRetries = FeatureFlags.get("maxRetries") || 3; // with default

Supported Data Types

// Boolean
await FeatureFlags.set("enableFeature", true);

// String
await FeatureFlags.set("apiEndpoint", "https://api.example.com");

// Number
await FeatureFlags.set("timeout", 30000);

// Object
await FeatureFlags.set("config", {
  retries: 3,
  timeout: 5000,
});

Removing Flags

FeatureFlags.remove("obsoleteFeature");

Access-Controlled Feature Flags

The FeatureFlagsAccess class provides permission-based access to flags.

Access Levels

enum FlagAccessLevel {
  None = 0,
  Read = 1 << 0,
  Write = 1 << 1,
}

Using Access Control

// Get with permission check
try {
  const value = FeatureFlagsAccess.get("fetchByDefault");
} catch (error) {
  console.error("Access denied:", error.message);
}

// Set with permission check
try {
  await FeatureFlagsAccess.set("fetchByDefault", false, true);
} catch (error) {
  console.error("Write access denied:", error.message);
}

// List available keys
const readableKeys = FeatureFlagsAccess.getReadableKeys();
const writableKeys = FeatureFlagsAccess.getWritableKeys();

File Persistence

Flags are stored in feature-flags.json:

{
  "enableNewUI": true,
  "maxRetries": 5,
  "apiEndpoint": "https://api.example.com"
}

Persistence options:

  • save: false (default) - Memory only
  • save: true - Immediate disk write, persistent across restarts

Example Uses

Extension Activation

export async function activate(context: vscode.ExtensionContext) {
  await FeatureFlags.init();

  const enableAdvanced = FeatureFlags.get("advancedMode") || false;
  if (enableAdvanced) {
    // Initialize advanced features
  }
}

Feature Toggles

class MyExtension {
  renderUI() {
    const useNewUI = FeatureFlags.get("enableNewUI") === true;
    return useNewUI ? this.renderNewUI() : this.renderLegacyUI();
  }
}

Configuration Management

class Config {
  static get() {
    return {
      maxRetries: FeatureFlags.get("maxRetries") ?? 3,
      timeout: FeatureFlags.get("timeout") ?? 30000,
      enableLogging: FeatureFlags.get("enableLogging") ?? false,
    };
  }
}

Clone this wiki locally