Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ The OpenFeature CLI provides the following commands:
| Command | Description |
|---------|-------------|
| `init` | Initialize a new flag manifest |
| `manifest` | Manage flag manifest files (add, list) |
| `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 |
Expand All @@ -144,7 +144,7 @@ See [here](./docs/commands/openfeature_init.md) for all available options.

### `manifest`

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

```bash
# Add a new flag interactively
Expand All @@ -161,11 +161,15 @@ openfeature manifest add welcome-message \

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

Expand Down
1 change: 1 addition & 0 deletions docs/commands/openfeature_manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ openfeature manifest [flags]

* [openfeature](openfeature.md) - CLI for OpenFeature.
* [openfeature manifest add](openfeature_manifest_add.md) - Add a new flag to the manifest
* [openfeature manifest delete](openfeature_manifest_delete.md) - Delete a flag from the manifest
* [openfeature manifest list](openfeature_manifest_list.md) - List all flags in the manifest

39 changes: 39 additions & 0 deletions docs/commands/openfeature_manifest_delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!-- markdownlint-disable-file -->
<!-- WARNING: THIS DOC IS AUTO-GENERATED. DO NOT EDIT! -->
## openfeature manifest delete

Delete a flag from the manifest

### Synopsis

Delete a flag from the manifest file by its key.

Examples:
# Delete a flag named 'old-feature'
openfeature manifest delete old-feature

# Delete a flag from a specific manifest file
openfeature manifest delete old-feature --manifest path/to/flags.json

```
openfeature manifest delete <flag-name> [flags]
```

### Options

```
-h, --help help for delete
```

### Options inherited from parent commands

```
--debug Enable debug logging
-m, --manifest string Path to the flag manifest (default "flags.json")
--no-input Disable interactive prompts
```

### SEE ALSO

* [openfeature manifest](openfeature_manifest.md) - Manage flag manifest files

1 change: 1 addition & 0 deletions internal/cmd/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func GetManifestCmd() *cobra.Command {
// Add subcommands
manifestCmd.AddCommand(GetManifestAddCmd())
manifestCmd.AddCommand(GetManifestListCmd())
manifestCmd.AddCommand(GetManifestDeleteCmd())

addStabilityInfo(manifestCmd)

Expand Down
82 changes: 82 additions & 0 deletions internal/cmd/manifest_delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package cmd

import (
"fmt"
"slices"

"github.com/open-feature/cli/internal/config"
"github.com/open-feature/cli/internal/filesystem"
"github.com/open-feature/cli/internal/flagset"
"github.com/open-feature/cli/internal/logger"
"github.com/open-feature/cli/internal/manifest"
"github.com/pterm/pterm"
"github.com/spf13/afero"
"github.com/spf13/cobra"
)

func GetManifestDeleteCmd() *cobra.Command {
manifestDeleteCmd := &cobra.Command{
Use: "delete <flag-name>",
Short: "Delete a flag from the manifest",
Long: `Delete a flag from the manifest file by its key.

Examples:
# Delete a flag named 'old-feature'
openfeature manifest delete old-feature

# Delete a flag from a specific manifest file
openfeature manifest delete old-feature --manifest path/to/flags.json`,
Args: cobra.ExactArgs(1),
PreRunE: func(cmd *cobra.Command, args []string) error {
return initializeConfig(cmd, "manifest.delete")
},
RunE: func(cmd *cobra.Command, args []string) error {
flagName := args[0]
manifestPath := config.GetManifestPath(cmd)

// Check if manifest exists
exists, err := afero.Exists(filesystem.FileSystem(), manifestPath)
if err != nil {
return fmt.Errorf("failed to check manifest existence: %w", err)
}

if !exists {
return fmt.Errorf("manifest file does not exist: %s", manifestPath)
}

// Load existing manifest
fs, err := manifest.LoadFlagSet(manifestPath)
if err != nil {
return fmt.Errorf("failed to load manifest: %w", err)
}

// Remove the flag
originalLen := len(fs.Flags)
fs.Flags = slices.DeleteFunc(fs.Flags, func(flag flagset.Flag) bool {
return flag.Key == flagName
})

// Check if flag was found (length unchanged means nothing was deleted)
if len(fs.Flags) == originalLen {
return fmt.Errorf("flag '%s' not found in manifest", flagName)
}

// Write updated manifest
if err := manifest.Write(manifestPath, *fs); err != nil {
return fmt.Errorf("failed to write manifest: %w", err)
}

// Success message
pterm.Success.Printfln("Flag '%s' deleted successfully from %s", flagName, manifestPath)
logger.Default.Debug(fmt.Sprintf("Deleted flag: name=%s, manifestPath=%s", flagName, manifestPath))

return nil
},
}

// Add command-specific flags
config.AddManifestDeleteFlags(manifestDeleteCmd)
addStabilityInfo(manifestDeleteCmd)

return manifestDeleteCmd
}
Loading
Loading