44package airgapped
55
66import (
7+ "fmt"
78 "os"
89 "path/filepath"
910
@@ -16,6 +17,7 @@ import (
1617 "github.com/vmware-tanzu/tanzu-cli/pkg/carvelhelpers"
1718 "github.com/vmware-tanzu/tanzu-cli/pkg/plugininventory"
1819 "github.com/vmware-tanzu/tanzu-cli/pkg/utils"
20+ "github.com/vmware-tanzu/tanzu-plugin-runtime/component"
1921 "github.com/vmware-tanzu/tanzu-plugin-runtime/log"
2022)
2123
@@ -55,18 +57,41 @@ func (o *UploadPluginBundleOptions) UploadPluginBundle() error {
5557 return errors .Wrap (err , "error while parsing plugin migration manifest" )
5658 }
5759
60+ totalImages := len (manifest .ImagesToCopy )
61+ imagesUploaded := 0
62+ uploadingMsg := "[%d/%d] uploading image %d"
63+ uploadedMsg := "[%d/%d] uploaded image %d"
64+ errorMsg := "error while uploading image %q"
5865 // Iterate through all the images and publish them to the remote repository
5966 for _ , ic := range manifest .ImagesToCopy {
6067 imageTar := filepath .Join (pluginBundleDir , ic .SourceTarFilePath )
6168 repoImagePath , err := utils .JoinURL (o .DestinationRepo , ic .RelativeImagePath )
6269 if err != nil {
6370 return errors .Wrap (err , "error while constructing the repo image path" )
6471 }
65- log .Infof ("---------------------------" )
66- log .Infof ("uploading image %q" , repoImagePath )
72+ errorMsg = fmt .Sprintf (errorMsg , repoImagePath )
73+ uploadingMsg = fmt .Sprintf (uploadingMsg , totalImages , imagesUploaded , imagesUploaded )
74+ uploadedMsg = fmt .Sprintf (uploadedMsg , totalImages , imagesUploaded , imagesUploaded )
75+ var spinner component.OutputWriterSpinner
76+ if ! component .IsTTYEnabled () {
77+ // Initialize the spinner
78+ spinner = component .NewOutputWriterSpinner (component .WithOutputStream (os .Stderr ),
79+ component .WithSpinnerText (uploadingMsg ),
80+ component .WithSpinnerStarted ())
81+ spinner .SetFinalText (errorMsg , log .LogTypeERROR )
82+ defer spinner .StopSpinner ()
83+ } else {
84+ log .Infof (uploadingMsg , totalImages , imagesUploaded , imagesUploaded )
85+ }
6786 err = o .ImageProcessor .CopyImageFromTar (imageTar , repoImagePath )
6887 if err != nil {
69- return errors .Wrap (err , "error while uploading image" )
88+ return errors .Wrap (err , errorMsg )
89+ }
90+ imagesUploaded = imagesUploaded + 1
91+ if spinner != nil {
92+ spinner .SetFinalText (uploadedMsg , log .LogTypeINFO )
93+ } else {
94+ log .Infof (uploadedMsg , totalImages , imagesUploaded , repoImagePath )
7095 }
7196 }
7297 log .Infof ("---------------------------" )
0 commit comments