diff --git a/cmd/lekko/init.go b/cmd/lekko/init.go index 7fe377e1..b756ea87 100644 --- a/cmd/lekko/init.go +++ b/cmd/lekko/init.go @@ -301,7 +301,6 @@ func initCmd() *cobra.Command { // Codegen spin.Suffix = " Running codegen..." spin.Start() - // TODO: make sure that `default` namespace exists repoPath := try.To1(repo.PrepareGithubRepo()) if err := gen.GenNative(cmd.Context(), nlProject, lekkoPath, repoPath, gen.GenOptions{}); err != nil { return errors.Wrap(err, "codegen for default namespace") diff --git a/pkg/gen/gen.go b/pkg/gen/gen.go index 0ac3df6b..60e2f3f8 100644 --- a/pkg/gen/gen.go +++ b/pkg/gen/gen.go @@ -27,6 +27,7 @@ import ( "github.com/lekkodev/cli/pkg/dotlekko" "github.com/lekkodev/cli/pkg/native" + "github.com/lekkodev/cli/pkg/repo" ) type GenOptions struct { @@ -50,9 +51,24 @@ func GenNative(ctx context.Context, project *native.Project, lekkoPath, repoPath if err != nil { return errors.Wrap(err, "create output dir") } + r, err := repo.NewLocal(repoPath, nil) + if err != nil { + return errors.Wrap(err, "read local repository") + } if len(opts.Namespaces) == 0 { + // Try to generate from only existing namespaces in code opts.Namespaces = try.To1(native.ListNamespaces(absLekkoPath, project.Language)) + // If no existing namespaces in code, generate from all namespaces in config repo + if len(opts.Namespaces) == 0 { + nsMDs, err := r.ListNamespaces(ctx) + if err != nil { + return errors.Wrap(err, "list namespaces") + } + for _, nsMD := range nsMDs { + opts.Namespaces = append(opts.Namespaces, nsMD.Name) + } + } } switch project.Language {