@@ -57,34 +57,37 @@ func NewRepository(datas ...any) error {
57
57
err := os .Mkdir (repositoryPath , 0755 )
58
58
if err != nil {
59
59
if strings .Contains (err .Error (), "exists" ) {
60
- fmt .Println ("repository folder already exist, If you want to create new repository, click something else `y` or `Y`" )
60
+ fmt .Println ("repository folder already exist, If you want to create new repository click something else `y` or `Y`" )
61
61
var answer string
62
62
fmt .Scanln (& answer )
63
- if answer == "q" || answer == "Q " {
63
+ if strings . ToLower ( answer ) != "y " {
64
64
return nil
65
65
}
66
66
err := os .RemoveAll (repositoryPath )
67
+ os .Mkdir (repositoryPath , 0755 )
67
68
if err != nil {
69
+ fmt .Println (err .Error ())
68
70
return err
69
71
}
70
72
}
71
- } else {
72
- err := os . Mkdir ( repositoryPath + "/" + postgresPath , 0755 )
73
- if err != nil {
74
- if strings . Contains ( err . Error (), "exists" ) {
75
- fmt . Println ( "repository/postgres folder already exist, If you want to create new repository/postgres, click something else `y` or `Y`" )
76
- var answer string
77
- fmt . Scanln ( & answer )
78
- if answer == "q" || answer == "Q" {
79
- return nil
80
- }
81
- err := os . RemoveAll ( repositoryPath + "/" + postgresPath )
82
- if err != nil {
83
- return err
84
- }
73
+ }
74
+
75
+ err = os . Mkdir ( repositoryPath + "/" + postgresPath , 0755 )
76
+ if err != nil {
77
+ if strings . Contains ( err . Error (), "exists" ) {
78
+ fmt . Println ( "repository/postgres folder already exist, If you want to create new repository/postgres click something else `y` or `Y`" )
79
+ var answer string
80
+ fmt . Scanln ( & answer )
81
+ if strings . ToLower ( answer ) != "y" {
82
+ return nil
83
+ }
84
+ err := os . RemoveAll ( repositoryPath + "/" + postgresPath )
85
+ if err != nil {
86
+ return err
85
87
}
86
88
}
87
89
}
90
+
88
91
storage .WriteString (storageHeader ())
89
92
postgresUp .WriteString (postgresHeader ())
90
93
for _ , model := range datas {
@@ -100,12 +103,12 @@ func NewRepository(datas ...any) error {
100
103
log .Println ("Starting repository..." )
101
104
err = repositoryFiles (createRepository (upperNameOfModel , lowerNameOfModel , fieldsOfModel ), lowerNameOfModel )
102
105
if err != nil {
103
- return clear (err )
106
+ return clear ("repository" , err )
104
107
}
105
108
interfaceName , interfaceMethods := storageInterface (upperNameOfModel , lowerNameOfModel , fieldsOfModel )
106
109
storage .WriteString (interfaceName )
107
110
interfaces .WriteString (interfaceMethods )
108
- log . Println ( "Successful repository implemented" )
111
+
109
112
postgresUpString , postgresDownString := postgresInterface (upperNameOfModel , lowerNameOfModel )
110
113
111
114
postgresUp .WriteString (postgresUpString )
@@ -117,7 +120,7 @@ func NewRepository(datas ...any) error {
117
120
storage .WriteString (interfaces .String ())
118
121
storageFile (storage .String ())
119
122
postgresFile (postgresUp .String (), postgresDown .String ())
120
- log .Println ("Succesfull implemented... " )
123
+ log .Println ("Successful repository implemented" )
121
124
return nil
122
125
}
123
126
@@ -128,7 +131,7 @@ func NewMigration(datas ...any) error {
128
131
fmt .Println ("migration folder already exist, If you want to create new migration, click something else `y` or `Y`" )
129
132
var answer string
130
133
fmt .Scanln (& answer )
131
- if answer == "q" || answer == "Q " {
134
+ if strings . ToLower ( answer ) != "y " {
132
135
return nil
133
136
}
134
137
err := os .RemoveAll (migrationPath )
@@ -143,7 +146,7 @@ func NewMigration(datas ...any) error {
143
146
fmt .Println ("migration/postgres folder already exist, If you want to create new migration/postgres, click something else `y` or `Y`" )
144
147
var answer string
145
148
fmt .Scanln (& answer )
146
- if answer == "q" || answer == "Q " {
149
+ if strings . ToLower ( answer ) != "y " {
147
150
return nil
148
151
}
149
152
err := os .RemoveAll (migrationPath + "/" + postgresPath )
@@ -183,7 +186,7 @@ func NewTest(datas ...any) error {
183
186
fmt .Println ("test folder already exist, If you want to create new test, click something else `y` or `Y`" )
184
187
var answer string
185
188
fmt .Scanln (& answer )
186
- if answer == "q" || answer == "Q " {
189
+ if strings . ToLower ( answer ) != "y " {
187
190
return nil
188
191
}
189
192
err := os .RemoveAll (testPath )
@@ -198,7 +201,7 @@ func NewTest(datas ...any) error {
198
201
fmt .Println ("test/postgres folder already exist, If you want to create new test/postgres, click something else `y` or `Y`" )
199
202
var answer string
200
203
fmt .Scanln (& answer )
201
- if answer == "q" || answer == "Q " {
204
+ if strings . ToLower ( answer ) != "y " {
202
205
return nil
203
206
}
204
207
err := os .RemoveAll (testPath + "/" + postgresPath )
@@ -221,7 +224,7 @@ func NewTest(datas ...any) error {
221
224
log .Println ("Starting test..." )
222
225
err = testFiles (createTest (lowerNameOfModel , fieldsOfModel ), lowerNameOfModel )
223
226
if err != nil {
224
- return clear (err )
227
+ return clear ("test" , err )
225
228
}
226
229
227
230
log .Println ("Successful test implemented" )
@@ -230,32 +233,42 @@ func NewTest(datas ...any) error {
230
233
return nil
231
234
}
232
235
233
- func clear (response error ) error {
236
+ func clear (data string , response error ) error {
234
237
235
- if _ , err := os .Stat (migrationPath + "/" + postgresPath ); os .IsExist (err ) {
236
- err = os .RemoveAll (migrationPath + "/" + postgresPath )
237
- if err != nil {
238
- log .Printf ("Error: %v" , err )
238
+ switch data {
239
+ case "repository" :
240
+ {
241
+ if _ , err := os .Stat (repositoryPath + "/" + postgresPath ); os .IsExist (err ) {
242
+ err = os .RemoveAll (repositoryPath + "/" + postgresPath )
243
+ if err != nil {
244
+ log .Printf ("Error: %v" , err )
245
+ }
246
+ } else {
247
+ log .Printf ("Error: %v" , err )
248
+ }
239
249
}
240
- } else {
241
- log .Printf ("Error: %v" , err )
242
- }
243
- if _ , err := os .Stat (repositoryPath + "/" + postgresPath ); os .IsExist (err ) {
244
- err = os .RemoveAll (repositoryPath + "/" + postgresPath )
245
- if err != nil {
246
- log .Printf ("Error: %v" , err )
250
+ case "migration" :
251
+ {
252
+ if _ , err := os .Stat (migrationPath + "/" + postgresPath ); os .IsExist (err ) {
253
+ err = os .RemoveAll (migrationPath + "/" + postgresPath )
254
+ if err != nil {
255
+ log .Printf ("Error: %v" , err )
256
+ }
257
+ } else {
258
+ log .Printf ("Error: %v" , err )
259
+ }
247
260
}
248
- } else {
249
- log .Printf ("Error: %v" , err )
250
- }
251
-
252
- if _ , err := os .Stat (testPath + "/" + postgresPath ); os .IsExist (err ) {
253
- err = os .RemoveAll (testPath + "/" + postgresPath )
254
- if err != nil {
255
- log .Printf ("Error: %v" , err )
261
+ case "test" :
262
+ {
263
+ if _ , err := os .Stat (testPath + "/" + postgresPath ); os .IsExist (err ) {
264
+ err = os .RemoveAll (testPath + "/" + postgresPath )
265
+ if err != nil {
266
+ log .Printf ("Error: %v" , err )
267
+ }
268
+ } else {
269
+ log .Printf ("Error: %v" , err )
270
+ }
256
271
}
257
- } else {
258
- log .Printf ("Error: %v" , err )
259
272
}
260
273
261
274
return response
@@ -283,7 +296,7 @@ func NewModels(datas ...any) error {
283
296
fmt .Println ("migration/postgres folder already exist, If you want to create new migration/postgres, click something else `y` or `Y`" )
284
297
var answer string
285
298
fmt .Scanln (& answer )
286
- if answer == "q" || answer == "Q " {
299
+ if strings . ToLower ( answer ) != "y " {
287
300
return nil
288
301
}
289
302
err := os .RemoveAll (migrationPath + "/" + postgresPath )
0 commit comments