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
43 changes: 43 additions & 0 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/open-feature/cli/internal/generators"
"github.com/open-feature/cli/internal/generators/golang"
"github.com/open-feature/cli/internal/generators/nodejs"
"github.com/open-feature/cli/internal/generators/python"
"github.com/open-feature/cli/internal/generators/react"
"github.com/open-feature/cli/internal/logger"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -175,11 +176,53 @@ func GetGenerateGoCmd() *cobra.Command {
return goCmd
}

func getGeneratePythonCmd() *cobra.Command {
pythonCmd := &cobra.Command{
Use: "python",
Short: "Generate typesafe Python client.",
Long: `Generate typesafe Python client compatible with the OpenFeature Python SDK.`,
Annotations: map[string]string{
"stability": string(generators.Alpha),
},
RunE: func(cmd *cobra.Command, args []string) error {
manifestPath := config.GetManifestPath(cmd)
outputPath := config.GetOutputPath(cmd)

logger.Default.GenerationStarted("Python")

params := generators.Params[python.Params]{
OutputPath: outputPath,
Custom: python.Params{},
}
flagset, err := flagset.Load(manifestPath)
if err != nil {
return err
}

generator := python.NewGenerator(flagset)
logger.Default.Debug("Executing Python generator")
err = generator.Generate(&params)
if err != nil {
return err
}

logger.Default.GenerationComplete("Python")

return nil
},
}

addStabilityInfo(pythonCmd)

return pythonCmd
}

func init() {
// Register generators with the manager
generators.DefaultManager.Register(GetGenerateReactCmd)
generators.DefaultManager.Register(GetGenerateGoCmd)
generators.DefaultManager.Register(GetGenerateNodeJSCmd)
generators.DefaultManager.Register(getGeneratePythonCmd)
}

func GetGenerateCmd() *cobra.Command {
Expand Down
7 changes: 7 additions & 0 deletions cmd/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ func TestGenerate(t *testing.T) {
outputGolden: "testdata/success_nodejs.golden",
outputFile: "openfeature.ts",
},
{
name: "Python generation success",
command: "python",
manifestGolden: "testdata/success_manifest.golden",
outputGolden: "testdata/success_python.golden",
outputFile: "openfeature.py",
},
// Add more test cases here as needed
}

Expand Down
Loading