@@ -210,49 +210,50 @@ func StringToInterface() mapstructure.DecodeHookFunc {
210210 }
211211}
212212
213- func UploadCleanup (client * phrase.APIClient , confirm bool , ids []string , branch string , projectId string ) error {
214- if ! shared .BatchMode {
215- fmt .Println ("Keys not mentioned in the following uploads will be deleted:" )
216- fmt .Println (strings .Join (ids , "\n " ))
217- }
218- if ! confirm {
219- if shared .BatchMode {
220- return errors .New ("Can't ask for confirmation in batch mode. Aborting" )
221- }
222- confirmation := ""
223- err := prompt .WithDefault ("Are you sure you want to continue? (y/n)" , & confirmation , "n" )
224- if err != nil {
225- return err
213+ func CreateUploadBatch (client * phrase.APIClient , confirm bool , ids []string , branch string , projectId string , cleanup bool ) error {
214+ if cleanup {
215+ if ! shared .BatchMode {
216+ fmt .Println ("Keys not mentioned in the following uploads will be deleted:" )
217+ fmt .Println (strings .Join (ids , "\n " ))
226218 }
219+ if ! confirm {
220+ if shared .BatchMode {
221+ return errors .New ("Can't ask for confirmation in batch mode. Aborting" )
222+ }
223+ confirmation := ""
224+ err := prompt .WithDefault ("Are you sure you want to continue? (y/n)" , & confirmation , "n" )
225+ if err != nil {
226+ return err
227+ }
227228
228- if strings .ToLower (confirmation ) != "y" {
229- fmt .Println ("Clean up aborted" )
230- return nil
229+ if strings .ToLower (confirmation ) != "y" {
230+ fmt .Println ("Clean up aborted" )
231+ return nil
232+ }
231233 }
232234 }
233235
234- q := "unmentioned_in_upload:" + strings .Join (ids , "," )
235- optionalBranch := optional.String {}
236- if branch != "" {
237- optionalBranch = optional .NewString (branch )
238- }
239- keysDeletelocalVarOptionals := phrase.KeysDeleteCollectionOpts {
240- Q : optional .NewString (q ),
241- Branch : optionalBranch ,
236+ uploadBatchesCreateParameters := phrase.UploadBatchesCreateParameters {
237+ Branch : branch ,
238+ DeleteUnmentionedKeys : & cleanup ,
239+ UploadIds : ids ,
242240 }
243- affected , _ , err := client .KeysApi .KeysDeleteCollection (Auth , projectId , & keysDeletelocalVarOptionals )
244-
241+ uploadBatch , _ , err := client .UploadBatchesApi .UploadBatchesCreate (Auth , projectId , uploadBatchesCreateParameters , nil )
245242 if err != nil {
246243 return err
247244 }
245+ if ! cleanup {
246+ return nil
247+ }
248+
248249 if shared .BatchMode {
249- jsonBuf , jsonErr := json .MarshalIndent (affected , "" , " " )
250+ jsonBuf , jsonErr := json .MarshalIndent (uploadBatch , "" , " " )
250251 if jsonErr != nil {
251252 print .Error (jsonErr )
252253 }
253254 fmt .Printf ("%s\n " , string (jsonBuf ))
254255 } else {
255- print .Success ("%d key(s) successfully deleted. \n " , affected . RecordsAffected )
256+ print .Success ("Keys cleanup scheduled for an upload batch with %d uploads " , len ( ids ) )
256257 }
257258 return nil
258259}
0 commit comments