44package airgapped
55
66import (
7+ "fmt"
78 "os"
9+ "os/signal"
810 "path/filepath"
911
1012 "github.com/pkg/errors"
@@ -16,6 +18,7 @@ import (
1618 "github.com/vmware-tanzu/tanzu-cli/pkg/carvelhelpers"
1719 "github.com/vmware-tanzu/tanzu-cli/pkg/plugininventory"
1820 "github.com/vmware-tanzu/tanzu-cli/pkg/utils"
21+ "github.com/vmware-tanzu/tanzu-plugin-runtime/component"
1922 "github.com/vmware-tanzu/tanzu-plugin-runtime/log"
2023)
2124
@@ -55,19 +58,43 @@ func (o *UploadPluginBundleOptions) UploadPluginBundle() error {
5558 return errors .Wrap (err , "error while parsing plugin migration manifest" )
5659 }
5760
61+ totalNumberOfImages := len (manifest .ImagesToCopy )
62+ imagesCompletedUpload := 0
63+
64+ var uploadingMessage , uploadedMessage , errMessage string
65+ var spinner component.OutputWriterSpinner
66+
5867 // Iterate through all the images and publish them to the remote repository
5968 for _ , ic := range manifest .ImagesToCopy {
6069 imageTar := filepath .Join (pluginBundleDir , ic .SourceTarFilePath )
6170 repoImagePath , err := utils .JoinURL (o .DestinationRepo , ic .RelativeImagePath )
6271 if err != nil {
6372 return errors .Wrap (err , "error while constructing the repo image path" )
6473 }
65- log .Infof ("---------------------------" )
66- log .Infof ("uploading image %q" , repoImagePath )
74+ uploadingMessage = fmt .Sprintf ("[%v/%v] uploading image %s" , imagesCompletedUpload , totalNumberOfImages , repoImagePath )
75+ errMessage = fmt .Sprintf ("[%v/%v] failed to upload image %s" , imagesCompletedUpload , totalNumberOfImages , repoImagePath )
76+ uploadedMessage = fmt .Sprintf ("[%v/%v] uploaded image %s" , imagesCompletedUpload + 1 , totalNumberOfImages , repoImagePath )
77+ spinner = component .NewOutputWriterSpinner (component .WithOutputStream (os .Stderr ),
78+ component .WithSpinnerText (uploadingMessage ),
79+ component .WithSpinnerStarted (), component .WithSpinnerFinalText (uploadedMessage , log .LogTypeINFO ))
80+
81+ signalChannel := make (chan os.Signal , 1 )
82+ defer func () {
83+ signal .Stop (signalChannel )
84+ close (signalChannel )
85+ spinner .StopSpinner ()
86+ component .StopAllSpinners ()
87+ }()
88+ // Initialize the signal catcher
89+ go utils .SignalCatcherInitialization (signalChannel , spinner , errMessage , log .LogTypeERROR , "" )
90+
91+ //log.Infof("---------------------------")
92+ //log.Infof("uploading image %q", repoImagePath)
6793 err = o .ImageProcessor .CopyImageFromTar (imageTar , repoImagePath )
6894 if err != nil {
6995 return errors .Wrap (err , "error while uploading image" )
7096 }
97+ imagesCompletedUpload ++
7198 }
7299 log .Infof ("---------------------------" )
73100 log .Infof ("---------------------------" )
0 commit comments