Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Beemer <[email protected]>
  • Loading branch information
beeme1mr committed Feb 20, 2025
1 parent e430a8d commit 9f84f0d
Show file tree
Hide file tree
Showing 10 changed files with 433 additions and 29 deletions.
53 changes: 53 additions & 0 deletions cmd/manifest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package cmd

import (
"encoding/json"
"os"

"github.com/open-feature/cli/internal/manifest"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
)

var manifestCmd = &cobra.Command{
Use: "manifest",
Short: "Manage OpenFeature manifests",
Long: `Manage OpenFeature manifests with subcommands to init, validate, and compare manifests`,
}

type InitManifest struct {
Schema string `json:"$schema,omitempty"`
manifest.Manifest
}

var initCmd = &cobra.Command{
Use: "init",
Short: "Initialize a new manifest",
RunE: func(cmd *cobra.Command, args []string) error {
if _, err := os.Stat(ManifestPath); err == nil {
overwrite, _ := cmd.Flags().GetBool("overwrite")
if !overwrite {
pterm.Warning.Printf("%s already exists. Use --overwrite to overwrite", ManifestPath)
return nil
}
}

m := &InitManifest{
Schema: "https://raw.githubusercontent.com/open-feature/cli/refs/heads/main/schema/v0/flag_manifest.json",
Manifest: manifest.Manifest{
Flags: map[string]any{},
},
}
formattedInitManifest, err := json.MarshalIndent(m, "", " ")
if err != nil {
return err
}
err = os.WriteFile(ManifestPath, formattedInitManifest, 0644)
if err != nil {
pterm.Error.Println("error creating manifest:", err)
return nil
}
pterm.Success.Printf("%s created successfully\n", ManifestPath)
return nil
},
}
15 changes: 15 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,26 @@ import (
"github.com/open-feature/cli/cmd/generate"

"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var (
Version = "dev"
Commit string
Date string

ManifestPath = "flags.json"
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "openfeature",
Short: "CLI for OpenFeature.",
Long: `CLI for OpenFeature related functionalities.`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
ManifestPath = viper.GetString("manifest-path")
return nil
},
DisableAutoGenTag: true,
}

Expand All @@ -36,6 +43,14 @@ func Execute(version string, commit string, date string) {
}

func init() {
rootCmd.PersistentFlags().StringVarP(&ManifestPath, "manifest-path", "m", ManifestPath, "Specify the path and name for the manifest file")

viper.BindPFlag("manifest-path", rootCmd.PersistentFlags().Lookup("manifest-path"))

viper.SetConfigName(".openfeature")
viper.AddConfigPath(".")
viper.ReadInConfig()

rootCmd.AddCommand(generate.Root)
rootCmd.AddCommand(versionCmd)
}
23 changes: 21 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,43 @@ require (
)

require (
atomicgo.dev/cursor v0.2.0 // indirect
atomicgo.dev/keyboard v0.2.9 // indirect
atomicgo.dev/schedule v0.1.0 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gookit/color v1.5.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/invopop/jsonschema v0.13.0 // indirect
github.com/lithammer/fuzzysearch v1.1.8 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pterm/pterm v0.12.80 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/term v0.26.0 // indirect
golang.org/x/text v0.20.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Expand Down
Loading

0 comments on commit 9f84f0d

Please sign in to comment.