@@ -477,17 +477,36 @@ def sync(ctx):
477477 if mc is None :
478478 return
479479 directory = os .getcwd ()
480- upload_job = None
480+ current_job = None
481+ current_bar = None
481482 try :
482-
483- def on_progress (increment , push_job ):
484- nonlocal upload_job
485- upload_job = push_job
486-
487- # run pull & push cycles until there are no local changes
488- mc .sync_project (directory , progress_callback = on_progress )
489-
490- click .secho ("Sync complete." , fg = "green" )
483+ # Iterate over the generator to get updates
484+ for size_change , job in mc .sync_project (directory , upload_progress = True ):
485+ # Check if this is a new job (a new push operation)
486+ if job and job != current_job :
487+ # If a previous bar exists, close it
488+ if current_bar :
489+ current_bar .finish ()
490+
491+ # A new push job has started. Initialize a new progress bar.
492+ click .echo (f"Starting upload" )
493+ current_job = job
494+
495+ # The length of the progress bar should be the total size of the job
496+ # You'll need to get this from your job object (e.g., job.total_size)
497+ total_size = job .total_size
498+ current_bar = click .progressbar (
499+ length = total_size ,
500+ label = f"Uploading project" ,
501+ )
502+
503+ # Update the current progress bar with the size increment
504+ current_bar .update (size_change )
505+
506+ # After the loop finishes, make sure to close the final progress bar
507+ if current_bar :
508+ current_bar .finish ()
509+ click .secho ("\n Project synced successfully" , fg = "green" )
491510
492511 except InvalidProject as e :
493512 click .secho ("Invalid project directory ({})" .format (str (e )), fg = "red" )
@@ -496,8 +515,8 @@ def on_progress(increment, push_job):
496515 return
497516 except KeyboardInterrupt :
498517 click .secho ("Cancelling..." )
499- if upload_job :
500- push_project_cancel (upload_job )
518+ if current_job :
519+ push_project_cancel (current_job )
501520 except Exception as e :
502521 _print_unhandled_exception ()
503522
0 commit comments