import { SettingConfigurations } from '../configurations' ; import * as vscode from 'vscode' ; export interface IFeatureFlag { getName ( ) : string ; getDescription ( ) : string ; getContext ( ) : boolean ; } export class FeatureFlag implements IFeatureFlag { constructor ( private name , private description , private contextFlag ? ) { } getName ( ) { return this . name ; } getDescription ( ) { return this . description ; } getContext ( ) { return this . contextFlag ; } } export type FeatureFlags = Map < string , boolean > ; export class FeatureFlagManager { static readonly EXPORTAPPDATA : IFeatureFlag = new FeatureFlag ( 'exportAppData' , 'Export application data for the IBM Cloud Pak for Apps Blockchain Accelerator' , true ) ; static readonly ALL : IFeatureFlag [ ] = [ FeatureFlagManager . EXPORTAPPDATA ] ; static async enable ( featureFlag ) { const featureFlags = await this . get ( ) ; featureFlags [ featureFlag . getName ( ) ] = true ; await this . set ( featureFlags ) ; if ( featureFlag . getContext ( ) ) { await vscode . commands . executeCommand ( 'setContext' , featureFlag . getName ( ) , true ) ; } } static async disable ( featureFlag ) { const featureFlags = await this . get ( ) ; featureFlags [ featureFlag . getName ( ) ] = false ; await this . set ( featureFlags ) ; if ( featureFlag . getContext ( ) ) { await vscode . commands . executeCommand ( 'setContext' , featureFlag . getName ( ) , false ) ; } } static async enabled ( featureFlag ) { const featureFlags = await this . get ( ) ; return ! ! featureFlags [ featureFlag . getName ( ) ] ; } static async disabled ( featureFlag ) { const featureFlags = await this . get ( ) ; return ! featureFlags [ featureFlag . getName ( ) ] ; } static async get ( ) { const configuration = await vscode . workspace . getConfiguration ( ) ; const featureFlags = configuration . get ( SettingConfigurations . FEATURE_FLAGS ) ; return featureFlags ; } private static async set ( featureFlags ) { const configuration = await vscode . workspace . getConfiguration ( ) ; await configuration . update ( SettingConfigurations . FEATURE_FLAGS , featureFlags , vscode . ConfigurationTarget . Global ) ; } }