@@ -18,6 +18,7 @@ import (
18
18
"context"
19
19
"fmt"
20
20
"io"
21
+ "log"
21
22
"os"
22
23
"path"
23
24
"path/filepath"
@@ -27,7 +28,6 @@ import (
27
28
featurev1beta1 "buf.build/gen/go/lekkodev/cli/protocolbuffers/go/lekko/feature/v1beta1"
28
29
"golang.org/x/mod/modfile"
29
30
30
- "github.com/AlecAivazis/survey/v2"
31
31
"github.com/lekkodev/cli/pkg/dotlekko"
32
32
"github.com/lekkodev/cli/pkg/feature"
33
33
"github.com/lekkodev/cli/pkg/gen"
@@ -81,26 +81,40 @@ func genGoCmd() *cobra.Command {
81
81
return err
82
82
}
83
83
}
84
+ var namespaces []string
84
85
if len (ns ) == 0 {
85
- if err := survey .AskOne (& survey.Input {
86
- Message : "Namespace:" ,
87
- Help : "Lekko namespace to generate code for, determines Go package name" ,
88
- }, & ns ); err != nil {
89
- return errors .Wrap (err , "namespace prompt" )
86
+ files , err := os .ReadDir (outputPath )
87
+ if err != nil {
88
+ log .Fatal (err )
90
89
}
90
+ for _ , f := range files {
91
+ if f .IsDir () && f .Name () != "proto" {
92
+ namespaces = append (namespaces , f .Name ())
93
+ }
94
+ }
95
+ } else {
96
+ namespaces = []string {ns }
91
97
}
92
- // TODO: Change this to a survey validator so it can keep re-asking
93
- if ! regexp .MustCompile ("[a-z]+" ).MatchString (ns ) {
94
- return errors .New ("namespace must be a lowercase alphanumeric string" )
95
- }
96
- generator , err := gen .NewGoGenerator (mf .Module .Mod .Path , outputPath , outputPath , repoPath , ns )
97
- if err != nil {
98
- return errors .Wrap (err , "initialize code generator" )
99
- }
100
- if initMode {
101
- return generator .Init (cmd .Context ())
98
+ for _ , n := range namespaces {
99
+ if ! regexp .MustCompile ("[a-z]+" ).MatchString (n ) {
100
+ return errors .New ("namespace must be a lowercase alphanumeric string" )
101
+ }
102
+ generator , err := gen .NewGoGenerator (mf .Module .Mod .Path , outputPath , outputPath , repoPath , n )
103
+ if err != nil {
104
+ return errors .Wrap (err , "initialize code generator" )
105
+ }
106
+ if initMode {
107
+ err = generator .Init (cmd .Context ())
108
+ if err != nil {
109
+ return err
110
+ }
111
+ }
112
+ err = generator .Gen (cmd .Context ())
113
+ if err != nil {
114
+ return err
115
+ }
102
116
}
103
- return generator . Gen ( cmd . Context ())
117
+ return nil
104
118
},
105
119
}
106
120
cmd .Flags ().StringVarP (& ns , "namespace" , "n" , "" , "namespace to generate code from" )
0 commit comments