FeatureFlags.PowerShell 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package FeatureFlags.PowerShell --version 1.0.0
NuGet\Install-Package FeatureFlags.PowerShell -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FeatureFlags.PowerShell" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FeatureFlags.PowerShell --version 1.0.0
#r "nuget: FeatureFlags.PowerShell, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install FeatureFlags.PowerShell as a Cake Addin
#addin nuget:?package=FeatureFlags.PowerShell&version=1.0.0

// Install FeatureFlags.PowerShell as a Cake Tool
#tool nuget:?package=FeatureFlags.PowerShell&version=1.0.0

PowerShell Feature Flags

More documentation is available on the GitHub page of the project.

This package contains a simple, low-dependencies implementation of feature flags for PowerShell, which relies on a local configuration file to verify if a given feature should be enabled or not.

The configuration file contains two sections:

  • stages: a section where roll-out stages are defined;
  • features: a section where each feature can be associated to a roll-out stage.

A roll-out stage is defined by a name and an array of conditions that the predicate must match in the order they are presented for the feature associated to the given stage to be enabled.

Stage names and feature names must be non-empty and must consist of non-space characters.

A feature can be assigned an array of stages that it applies to. In addition, it can also accept an environment variable array, and can optionally output an environment configuration file.

For more general information about feature flags, please visit featureflags.io.

Installation

This module is available from the PowerShell Gallery. Therefore, to install it for all users on the machine type the following from an administrator PowerShell prompt:

PS > Install-Module FeatureFlags

To install as an unprivileged user, type the following from any PowerShell prompt:

PS > Install-Module FeatureFlags -Scope CurrentUser

Simple example

Imagine to have a feature flag configuration file called features.json:

{
  "stages": {
    "test": [
      {"whitelist": ["test.*", "dev.*"]}
    ],
    "canary": [
      {"whitelist": ["prod-canary"]}
    ],
    "prod": [
      {"whitelist": ["prod.*"]},
      {"blacklist": ["prod-canary"]}
    ]
  },
  "features": {
    "experimental-feature": {
      "stages": ["test"]
    },
    "well-tested-feature": {
      "stages": ["test", "canary", "prod"]
    }
  }
}

This file defines 3 stages: test, canary and prod, and 2 features: experimental-feature and well-tested-feature.

The intent of the configuration is to enable experimental-feature in test only (all predicates starting with test or dev), and to enable well-tested-feature in all stages.

Let's first read the configuration:

$cfg = Get-FeatureFlagConfigFromFile features.json

This step would fail if there is any I/O error (e.g., file doesn't exist), if the file is not valid JSON or if the file does not conform with the feature flags schema.

Let's now test a couple of predicates to verify that the configuration does what we expect:

PS > Test-FeatureFlag -config $cfg -Feature "well-tested-feature" -predicate "test1"
True 
PS > Test-FeatureFlag -config $cfg -Feature "well-tested-feature" -predicate "test2"
True 
PS > Test-FeatureFlag -config $cfg -Feature "well-tested-feature" -predicate "dev1" 
True                                                                                                                                
PS > Test-FeatureFlag -config $cfg -Feature "well-tested-feature" -predicate "prod-canary1"
True 
PS > Test-FeatureFlag -config $cfg -Feature "experimental-feature" -predicate "prod-canary1"
False 
PS > Test-FeatureFlag -config $cfg -Feature "experimental-feature" -predicate "test1"
True 
PS > Test-FeatureFlag -config $cfg -Feature "experimental-feature" -predicate "prod1"
False 

For more complex examples, please look at test cases. More examples will be added in the future (Issue #6).

Life of a feature flag

Feature flags are expected to be in use while a feature is rolled out to production, or in case there is a need to conditionally enable or disable features.

An example lifecycle of a feature flag might be the following:

  1. A new feature is checked in production after testing, in a disabled state;
  2. The feature is enabled for a particular customer;
  3. The feature is enabled for a small set of customers;
  4. The feature is gradually rolled out to increasingly large percentages of customers (e.g., 5%, 10%, 30%, 50%)
  5. The feature is rolled out to all customers (100%)
  6. The test for the feature flag is removed from the code, and the feature flag configuration is removed as well.

Here is how these example stages could be implemented:

  • Stage 1 can be implemented with a blacklist condition with value .*.
  • Stages 2 and 3 can be implemented with whitelist conditions.
  • Stages 4 and 5 can be implemented with probability conditions.
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.1 160 5/12/2023
2.0.0 535 6/13/2020
1.0.1 404 6/12/2020
1.0.0 569 8/8/2019

First release.