Skip to main content

OpenFeature CLI

work-in-progressSlack

The OpenFeature CLI is a command-line tool designed to improve the developer experience when working with feature flags. It helps developers manage feature flags consistently across different environments and programming languages by providing powerful utilities for code generation, flag validation, and more.

The CLI bridges the gap between feature flag management systems and your application code by generating strongly typed flag accessors from a flag manifest. This approach provides:

  • Type Safety: Generate strongly-typed flag accessors for your preferred language
  • Developer Experience: Reduce errors and improve IDE autocomplete support
  • Language Support: Generate code for TypeScript, JavaScript, React, Go, C#, and more

Installationโ€‹

via curlโ€‹

The OpenFeature CLI can be installed using a shell command. This method is suitable for most Unix-like operating systems.

curl -fsSL https://openfeature.dev/scripts/install_cli.sh | sh

via Dockerโ€‹

The OpenFeature CLI is available as a Docker image in the GitHub Container Registry.

You can run the CLI in a Docker container using the following command:

docker run -it -v $(pwd):/local -w /local ghcr.io/open-feature/cli:latest

via Goโ€‹

If you have Go >= 1.23 installed, you can install the CLI using the following command:

go install github.com/open-feature/cli/cmd/openfeature@latest

via pre-built binariesโ€‹

Download the appropriate pre-built binary from the releases page.

Quick Startโ€‹

  1. Create a flag manifest file in your project root:
cat > flags.json << EOL
{
"$schema": "https://raw.githubusercontent.com/open-feature/cli/refs/heads/main/schema/v0/flag-manifest.json",
"flags": {
"enableMagicButton": {
"flagType": "boolean",
"defaultValue": false,
"description": "Activates a special button that enhances user interaction with magical, intuitive functionalities."
}
}
}
EOL

Note

This is for demonstration purposes only. In a real-world scenario, you would typically want to fetch this file from a remote flag management service. See here, more details.

  1. Generate code for your preferred language:
openfeature generate react

See here for all available options.

  1. View the generated code:
cat openfeature.ts

Congratulations! You have successfully generated your first strongly typed flag accessors. You can now use the generated code in your application to access the feature flags. This is just scratching the surface of what the OpenFeature CLI can do. For more advanced usage, read on!

Commandsโ€‹

The OpenFeature CLI provides the following commands:

initโ€‹

Initialize a new flag manifest in your project.

openfeature init

This command creates a flags.json file in your current directory with the proper schema reference. You can customize the manifest path using configuration options.

See here for all available options.

generateโ€‹

Generate strongly typed flag accessors for your project.

# List available languages
openfeature generate

# Generate for a specific language
openfeature generate typescript

# With custom output directory
openfeature generate typescript --output ./src/flags

Supported Languages:

LanguageDescription
typescriptTypeScript flag accessors
javascriptJavaScript flag accessors
reactReact hooks for feature flags
goGo flag accessors
csharpC# flag accessors
javaJava flag accessors
pythonPython flag accessors
nestjsNestJS flag accessors
nodejsNode.js flag accessors

See here for all available options.

versionโ€‹

Print the version number of the OpenFeature CLI.

openfeature version

See here for all available options.

Flag Manifestโ€‹

The flag manifest is a JSON file that defines your feature flags and their properties. It serves as the source of truth for your feature flags and is used by the CLI to generate strongly typed accessors. The manifest file should be named flags.json and placed in the root of your project.

Flag Manifest Structureโ€‹

The flag manifest file should follow the JSON schema with the following properties:

  • $schema - The URL of the JSON schema for validation
  • flags - An object containing the feature flags
    • flagKey - A unique key for the flag
      • description - A description of what the flag does
      • type - The type of the flag (boolean, string, number, object)
      • defaultValue - The default value of the flag

Example Flag Manifestโ€‹

{
"$schema": "https://raw.githubusercontent.com/open-feature/cli/refs/heads/main/schema/v0/flag-manifest.json",
"flags": {
"uniqueFlagKey": {
"description": "Description of what this flag does",
"type": "boolean|string|number|object",
"defaultValue": "default-value",
}
}
}

Configurationโ€‹

The OpenFeature CLI uses an optional configuration file to override default settings and customize behavior. This file can be in JSON or YAML format and should be named either .openfeature.json or .openfeature.yaml.

Configuration File Structureโ€‹

# Example .openfeature.yaml
manifest: "flags/manifest.json" # Overrides the default manifest path
generate:
output: "src/flags" # Overrides the default output directory
# Any language-specific options can be specified here
# For example, for React:
react:
output: "src/flags/react" # Overrides the default React output directory
# For Go:
go:
package: "github.com/myorg/myrepo/flags" # Overrides the default Go package name
output: "src/flags/go" # Overrides the default Go output directory

Configuration Priorityโ€‹

The CLI uses a layered approach to configuration, allowing you to override settings at different levels. The configuration is applied in the following order: