An open API service indexing awesome lists of open source software.

https://github.com/open-feature/cli

OpenFeature’s official command-line tool
https://github.com/open-feature/cli

Last synced: 5 months ago
JSON representation

OpenFeature’s official command-line tool

Awesome Lists containing this project

README

          




OpenFeature Logo

OpenFeature CLI



work-in-progress


Slack

> [!CAUTION]
> The OpenFeature CLI is experimental!
> Feel free to give it a shot and provide feedback, but expect breaking changes.

[OpenFeature](https://openfeature.dev) is an open specification that provides a vendor-agnostic, community-driven API for feature flagging that works with your favorite feature flag management tool or in-house solution.

## Overview

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.

```bash
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](https://github.com/open-feature/cli/pkgs/container/cli).

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

```bash
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:

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

### via pre-built binaries

Download the appropriate pre-built binary from the [releases page](https://github.com/open-feature/cli/releases).

## Quick Start

1. Create a flag manifest file in your project root:

```bash
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](https://github.com/open-feature/cli/issues/3), more details.

2. Generate code for your preferred language:

```bash
openfeature generate react
```

See [here](./docs/commands/openfeature_generate.md) for all available options.

3. View the generated code:

```bash
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:

| Command | Description |
|---------|-------------|
| `init` | Initialize a new flag manifest |
| `manifest` | Manage flag manifest files (add, list, delete) |
| `compare` | Compare two flag manifests |
| `generate` | Generate strongly typed flag accessors |
| `pull` | Fetch flags from remote sources |
| `push` | Push flags to remote services |
| `version` | Display CLI version |

### `init`

Initialize a new flag manifest in your project.

```bash
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](./docs/commands/openfeature_init.md) for all available options.

### `manifest`

Manage flag manifest files with subcommands for adding, listing, and deleting flags.

```bash
# Add a new flag interactively
openfeature manifest add

# Add a boolean flag
openfeature manifest add new-feature --default-value false

# Add a string flag with description
openfeature manifest add welcome-message \
--type string \
--default-value "Hello!" \
--description "Welcome message for users"

# List all flags in the manifest
openfeature manifest list

# Delete a flag from the manifest
openfeature manifest delete old-feature
```

The manifest command provides:
- **add**: Add new flags to your manifest file
- **list**: Display all flags with their configuration
- **delete**: Remove flags from your manifest file

See [here](./docs/commands/openfeature_manifest.md) for all available options.

### `compare`

Compare two feature flag manifests and display the differences.

```bash
# Compare your local manifest against another
openfeature compare --against production-flags.json

# Compare with different output formats
openfeature compare --against other.json --output json
openfeature compare --against other.json --output yaml
openfeature compare --against other.json --output flat
```

Output formats:
- **tree**: Hierarchical tree view (default)
- **flat**: Simple flat list
- **json**: JSON format
- **yaml**: YAML format

See [here](./docs/commands/openfeature_compare.md) for all available options.

### `generate`

Generate strongly typed flag accessors for your project.

```bash
# 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:**

| Language | Description |
|----------|-------------|
| `react` | React hooks for feature flags |
| `go` | Go flag accessors |
| `csharp` | C# flag accessors |
| `java` | Java flag accessors |
| `python` | Python flag accessors |
| `nestjs` | NestJS flag accessors |
| `nodejs` | Node.js flag accessors |
| `angular` | Angular flag accessors |

See [here](./docs/commands/openfeature_generate.md) for all available options.

> **_NOTE:_**
> Angular generated code requires `@openfeature/angular-sdk` version `1.1.0` or newer.

### `pull`

Fetch feature flag configurations from a remote source.

```bash
# Pull flags from a remote API
openfeature pull --flag-source-url https://api.example.com

# With authentication
openfeature pull --flag-source-url https://api.example.com --auth-token secret-token

# Pull from a JSON file URL
openfeature pull --flag-source-url https://example.com/flags.json
```

The pull command supports:
- HTTP/HTTPS endpoints implementing the OpenFeature Manifest Management API
- Direct JSON/YAML file URLs
- Authentication via bearer tokens

See [here](./docs/commands/openfeature_pull.md) for all available options.

### `push`

Push local flag configurations to a remote flag management service.

```bash
# Push flags to a remote API
openfeature push --flag-source-url https://api.example.com --auth-token secret-token

# Dry run to preview changes
openfeature push --flag-source-url https://api.example.com --dry-run
```

The push command intelligently:
- Fetches existing flags from the remote
- Compares local flags with remote flags
- Creates new flags that don't exist remotely
- Updates existing flags that have changed

See [here](./docs/commands/openfeature_push.md) for all available options.

### `version`

Print the version number of the OpenFeature CLI.

```bash
openfeature version
```

See [here](./docs/commands/openfeature_version.md) 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](https://raw.githubusercontent.com/open-feature/cli/refs/heads/main/schema/v0/flag-manifest.json) 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

```json
{
"$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",
}
}
}
```

## Remote Flag Management

The OpenFeature CLI supports synchronizing flags with remote flag management services through a standardized OpenAPI-based approach. This enables teams to:

- **Pull flags** from centralized flag management systems
- **Push flags** back to maintain consistency across environments
- **Integrate** with any service that implements the Manifest Management API

### OpenAPI Client Pattern

The CLI uses an OpenAPI-driven architecture for remote operations:

1. **Standardized API**: All remote operations conform to the [Manifest Management API](./api/v0/sync.yaml) OpenAPI specification
2. **Type-Safe Clients**: Generated clients provide compile-time safety and better IDE support
3. **Provider Agnostic**: Any service implementing the API specification can integrate with the CLI

For detailed information about implementing or extending the OpenAPI client pattern, see the [OpenAPI Client Pattern documentation](./docs/openapi-client-pattern.md).

### Implementing the Manifest Management API

If you're building a flag management service that needs to integrate with the OpenFeature CLI, implement the endpoints defined in the [sync.yaml](./api/v0/sync.yaml) specification:

- `GET /openfeature/v0/manifest` - Retrieve the project manifest
- `POST /openfeature/v0/manifest/flags` - Create new flags
- `PUT /openfeature/v0/manifest/flags/{key}` - Update existing flags
- `DELETE /openfeature/v0/manifest/flags/{key}` - Archive/delete flags

## 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

```yaml
# 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:

```mermaid
flowchart LR
default("Default Config")
config("Config File")
args("Command Line Args")
default --> config
config --> args
```

## Get Involved

- **GitHub Repository**: [open-feature/cli](https://github.com/open-feature/cli)
- **CNCF Slack**: Join the conversation in the [#openfeature](https://cloud-native.slack.com/archives/C0344AANLA1) and [#openfeature-cli](https://cloud-native.slack.com/archives/C07DY4TUDK6) channel
- **Regular Meetings**: Attend our [community calls](https://zoom-lfx.platform.linuxfoundation.org/meetings/openfeature)
- **GitHub Issues**: Report bugs or request features in our [issue tracker](https://github.com/open-feature/cli/issues)
- **Social Media**:
- Twitter: [@openfeature](https://twitter.com/openfeature)
- LinkedIn: [OpenFeature](https://www.linkedin.com/company/openfeature/)

For more information, visit our [community page](https://openfeature.dev/community/).

## Support the project

- Give this repo a ⭐️!
- Share your experience and contribute back to the project

## Thanks to everyone who has already contributed


Pictures of the folks who have contributed to the project

Made with [contrib.rocks](https://contrib.rocks).