@@ -81,6 +81,7 @@ func root(args []string) error {
81
81
flagsParse (fs , args [1 :])
82
82
83
83
s .CheckUpdates (ctx )
84
+
84
85
case "update" :
85
86
if len (args ) < 2 {
86
87
return fmt .Errorf ("language argument is missing" )
@@ -91,11 +92,15 @@ func root(args []string) error {
91
92
flagsParse (fs , args [2 :])
92
93
93
94
s .Update (ctx , args [1 ], * force )
95
+ s .writeGrammarsFile (ctx )
96
+
94
97
case "update-all" :
95
98
fs := flag .NewFlagSet ("update-all" , flag .ExitOnError )
96
99
flagsParse (fs , args [1 :])
97
100
98
- s .UpdateAll (ctx )
101
+ s .UpdateAll (ctx , true )
102
+ s .writeGrammarsFile (ctx )
103
+
99
104
default :
100
105
return fmt .Errorf ("unknown sub-command" )
101
106
}
@@ -194,33 +199,20 @@ func (s *UpdateService) Update(ctx context.Context, language string, force bool)
194
199
}
195
200
196
201
s .downloadGrammar (ctx , grammar )
197
- s .writeGrammarsFile (ctx )
198
202
}
199
203
200
- func (s * UpdateService ) UpdateAll (ctx context.Context ) {
201
- newVersions := s .fetchNewVersions ()
202
-
204
+ func (s * UpdateService ) UpdateAll (ctx context.Context , force bool ) {
203
205
wg := sync.WaitGroup {}
204
- for i , g := range s .grammars {
205
- v := newVersions [i ]
206
- if v == nil {
207
- continue
208
- }
209
-
206
+ for _ , g := range s .grammars {
210
207
wg .Add (1 )
211
- g .Reference = v .Reference
212
- g .Revision = v .Revision
213
208
214
209
go func (g * Grammar ) {
215
210
defer wg .Done ()
216
211
217
- s .downloadGrammar (ctx , g )
212
+ s .Update (ctx , g . Language , force )
218
213
}(g )
219
214
}
220
-
221
215
wg .Wait ()
222
-
223
- s .writeGrammarsFile (ctx )
224
216
}
225
217
226
218
func (s * UpdateService ) downloadGrammar (ctx context.Context , g * Grammar ) {
@@ -310,7 +302,7 @@ func (s *UpdateService) fetchFile(ctx context.Context, url string) []byte {
310
302
defer resp .Body .Close ()
311
303
312
304
if resp .StatusCode != 200 {
313
- logAndExit ( logger , "incorrect response status code" , "statusCode" , resp .StatusCode )
305
+ logger . Error ( "incorrect response status code" , "statusCode" , resp .StatusCode )
314
306
}
315
307
316
308
b , err := io .ReadAll (resp .Body )
0 commit comments