@@ -3,19 +3,26 @@ package migrations
33import (
44 "flag"
55 "fmt"
6+ "time"
67)
78
8- func revisionCommandOptionsFromArgs (args []string ) (string , * configOptions , error ) {
9- fs := flag .NewFlagSet ("revision-command" , flag .ContinueOnError )
9+ const (
10+ defaultMigrationDirectory = "./migrations"
11+ defaultMigrationComment = "migration"
12+ defaultRevisionTimeout = 30 * time .Second
13+ )
14+
15+ func configOptionsFromArgs (args []string ) (string , * configOptions , error ) {
16+ fs := flag .NewFlagSet ("migrations-init" , flag .ContinueOnError )
1017
1118 var path string
1219 var options configOptions
1320
1421 fs .StringVar (
1522 & path ,
16- "path " ,
17- "" ,
18- "Path for generated cmd file" ,
23+ "dir " ,
24+ defaultMigrationDirectory ,
25+ "directory for generated qrafter config file" ,
1926 )
2027
2128 fs .StringVar (
@@ -72,3 +79,85 @@ func revisionCommandOptionsFromArgs(args []string) (string, *configOptions, erro
7279
7380 return path , & options , nil
7481}
82+
83+ type revisionOptions struct {
84+ WorkDir string
85+ MigrationDir string
86+ ConfigImportPath string
87+ Comment string
88+ GoBinary string
89+ Timeout time.Duration
90+ }
91+
92+ func revisionOptionsFromArgs (args []string ) (* revisionOptions , error ) {
93+ fs := flag .NewFlagSet ("migrations-revision" , flag .ContinueOnError )
94+
95+ options := revisionOptions {
96+ WorkDir : "." ,
97+ MigrationDir : defaultMigrationDirectory ,
98+ Comment : defaultMigrationComment ,
99+ GoBinary : "go" ,
100+ Timeout : defaultRevisionTimeout ,
101+ }
102+
103+ fs .StringVar (
104+ & options .WorkDir ,
105+ "workdir" ,
106+ options .WorkDir ,
107+ "project directory containing go.mod" ,
108+ )
109+
110+ fs .StringVar (
111+ & options .MigrationDir ,
112+ "dir" ,
113+ options .MigrationDir ,
114+ "directory containing qrafter_config.go and generated migrations" ,
115+ )
116+
117+ fs .StringVar (
118+ & options .ConfigImportPath ,
119+ "config-import" ,
120+ "" ,
121+ "Go import path for package containing MigrationConfig" ,
122+ )
123+
124+ fs .StringVar (
125+ & options .Comment ,
126+ "comment" ,
127+ options .Comment ,
128+ "migration comment" ,
129+ )
130+
131+ fs .StringVar (
132+ & options .GoBinary ,
133+ "go" ,
134+ options .GoBinary ,
135+ "go binary used for the temporary build" ,
136+ )
137+
138+ fs .DurationVar (
139+ & options .Timeout ,
140+ "timeout" ,
141+ options .Timeout ,
142+ "timeout for the temporary build and schema diff" ,
143+ )
144+
145+ if err := fs .Parse (args ); err != nil {
146+ return nil , err
147+ }
148+
149+ if options .WorkDir == "" {
150+ return nil , fmt .Errorf ("missing required flag: --workdir" )
151+ }
152+ if options .MigrationDir == "" {
153+ return nil , fmt .Errorf ("missing required flag: --dir" )
154+ }
155+ if options .GoBinary == "" {
156+ return nil , fmt .Errorf ("missing required flag: --go" )
157+ }
158+ if options .Timeout <= 0 {
159+ return nil , fmt .Errorf ("timeout must be positive" )
160+ }
161+
162+ return & options , nil
163+ }
0 commit comments