@@ -11,7 +11,6 @@ import (
1111 "os"
1212 "os/exec"
1313 "path/filepath"
14- "runtime"
1514 "strings"
1615
1716 "github.com/Masterminds/semver"
@@ -65,11 +64,6 @@ var spinner component.OutputWriterSpinner
6564func init () {
6665 // Initialize global spinner
6766 spinner = component .NewOutputWriterSpinner (component .WithOutputStream (os .Stderr ))
68- runtime .SetFinalizer (spinner , func (s component.OutputWriterSpinner ) {
69- if s != nil {
70- s .StopSpinner ()
71- }
72- })
7367}
7468
7569func StopSpinner () {
@@ -78,6 +72,12 @@ func StopSpinner() {
7872 }
7973}
8074
75+ // ResetPluginInstallationCounts resets the total number of plugins to install and the number of plugins installed
76+ func ResetPluginInstallationCounts () {
77+ SetTotalPluginsToInstall (0 )
78+ SetPluginsInstalledCount (0 )
79+ }
80+
8181type DeletePluginOptions struct {
8282 Target configtypes.Target
8383 PluginName string
@@ -492,6 +492,7 @@ func InitializePlugin(plugin *cli.PluginInfo) error {
492492
493493// InstallStandalonePlugin installs a plugin by name, version and target as a standalone plugin.
494494func InstallStandalonePlugin (pluginName , version string , target configtypes.Target ) error {
495+ defer StopSpinner ()
495496 return installPlugin (pluginName , version , target , "" )
496497}
497498
@@ -505,6 +506,11 @@ func SetPluginsInstalledCount(count int) {
505506 pluginsInstalledCount = count
506507}
507508
509+ // GetPluginsInstalledCount returns the number of plugins installed
510+ func GetPluginsInstalledCount () int {
511+ return pluginsInstalledCount
512+ }
513+
508514// IncrementPluginsInstalledCount increments the number of plugins installed
509515func IncrementPluginsInstalledCount (count int ) {
510516 pluginsInstalledCount += count
@@ -635,7 +641,6 @@ func InstallPluginsFromGivenPluginGroup(pluginName, groupIDAndVersion string, pg
635641 numErrors := 0
636642 mandatoryPluginsExist := false
637643 pluginExist := false
638- pluginsInstalledCount = 0
639644
640645 pluginsToInstall := make ([]* plugininventory.PluginGroupPluginEntry , 0 )
641646 for _ , plugin := range pg .Versions [pg .RecommendedVersion ] {
@@ -649,11 +654,11 @@ func InstallPluginsFromGivenPluginGroup(pluginName, groupIDAndVersion string, pg
649654 }
650655 SetTotalPluginsToInstall (len (pluginsToInstall ))
651656 SetPluginsInstalledCount (0 )
657+ defer StopSpinner ()
652658 for _ , plugin := range pluginsToInstall {
653659 err := InstallStandalonePlugin (plugin .Name , plugin .Version , plugin .Target )
654660 if err != nil {
655661 numErrors ++
656- log .Warningf ("unable to install plugin '%s': %v" , plugin .Name , err .Error ())
657662 } else {
658663 IncrementPluginsInstalledCount (1 )
659664 }
@@ -674,12 +679,10 @@ func InstallPluginsFromGivenPluginGroup(pluginName, groupIDAndVersion string, pg
674679 return groupIDAndVersion , fmt .Errorf ("could not install %d plugin(s) from group '%s'" , numErrors , groupIDAndVersion )
675680 }
676681
677- if pluginsInstalledCount == 0 {
682+ if GetPluginsInstalledCount () == 0 {
678683 return groupIDAndVersion , fmt .Errorf ("plugin '%s' is not part of the group '%s'" , pluginName , groupIDAndVersion )
679684 }
680- SetTotalPluginsToInstall (0 )
681- SetPluginsInstalledCount (0 )
682- defer StopSpinner ()
685+ ResetPluginInstallationCounts ()
683686
684687 return groupIDAndVersion , nil
685688}
@@ -1193,8 +1196,6 @@ func InstallPluginsFromLocalSource(pluginName, version string, target configtype
11931196 errList = append (errList , err )
11941197 }
11951198 }
1196- SetTotalPluginsToInstall (0 )
1197- SetPluginsInstalledCount (0 )
11981199 err = kerrors .NewAggregate (errList )
11991200 if err != nil {
12001201 return err
0 commit comments