@@ -26,6 +26,9 @@ import (
26
26
27
27
func init () {
28
28
uploadCmd .Flags ().BoolP ("dry-run" , "" , false , "dump upload request (default: false)" )
29
+ initCmd .Flags ().BoolP ("v1" , "" , false , "generate v1 config yaml file" )
30
+ initCmd .Flags ().BoolP ("v2" , "" , true , "generate v2 config yaml file" )
31
+ initCmd .MarkFlagsMutuallyExclusive ("v1" , "v2" )
29
32
}
30
33
31
34
// Do runs the command logic.
@@ -88,6 +91,17 @@ var initCmd = &cobra.Command{
88
91
Use : "init" ,
89
92
Short : "Create an empty sqlc.yaml settings file" ,
90
93
RunE : func (cmd * cobra.Command , args []string ) error {
94
+ useV1 , err := cmd .Flags ().GetBool ("v1" )
95
+ if err != nil {
96
+ return err
97
+ }
98
+ var yamlConfig interface {}
99
+ if useV1 {
100
+ yamlConfig = config.V1GenerateSettings {Version : "1" }
101
+ } else {
102
+ yamlConfig = config.Config {Version : "2" }
103
+ }
104
+
91
105
defer trace .StartRegion (cmd .Context (), "init" ).End ()
92
106
file := "sqlc.yaml"
93
107
if f := cmd .Flag ("file" ); f != nil && f .Changed {
@@ -97,13 +111,24 @@ var initCmd = &cobra.Command{
97
111
}
98
112
}
99
113
if _ , err := os .Stat (file ); ! os .IsNotExist (err ) {
114
+ fmt .Printf ("%s is already created\n " , file )
100
115
return nil
101
116
}
102
- blob , err := yaml .Marshal (config. V1GenerateSettings { Version : "1" } )
117
+ blob , err := yaml .Marshal (yamlConfig )
103
118
if err != nil {
104
119
return err
105
120
}
106
- return os .WriteFile (file , blob , 0644 )
121
+ err = os .WriteFile (file , blob , 0644 )
122
+ if err != nil {
123
+ return err
124
+ }
125
+ configDoc := "https://docs.sqlc.dev/en/stable/reference/config.html"
126
+ fmt .Printf (
127
+ "%s is added. Please visit %s to learn more about configuration\n " ,
128
+ file ,
129
+ configDoc ,
130
+ )
131
+ return nil
107
132
},
108
133
}
109
134
0 commit comments