Skip to content

Commit

Permalink
counts
Browse files Browse the repository at this point in the history
  • Loading branch information
chandrareddyp committed May 1, 2024
1 parent 846e165 commit 333694a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
3 changes: 1 addition & 2 deletions pkg/command/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,7 @@ func syncContextPlugins(cmd *cobra.Command, contextType configtypes.ContextType,
if err == nil {
log.Success("Successfully installed all recommended plugins.")
}
pluginmanager.SetTotalPluginsToInstall(0)
pluginmanager.SetPluginsInstalledCount(0)
pluginmanager.ResetPluginInstallationCounts()
return err
}

Expand Down
29 changes: 15 additions & 14 deletions pkg/pluginmanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"

"github.com/Masterminds/semver"
Expand Down Expand Up @@ -65,11 +64,6 @@ var spinner component.OutputWriterSpinner
func init() {
// Initialize global spinner
spinner = component.NewOutputWriterSpinner(component.WithOutputStream(os.Stderr))
runtime.SetFinalizer(spinner, func(s component.OutputWriterSpinner) {
if s != nil {
s.StopSpinner()
}
})
}

func StopSpinner() {
Expand All @@ -78,6 +72,12 @@ func StopSpinner() {
}
}

// ResetPluginInstallationCounts resets the total number of plugins to install and the number of plugins installed
func ResetPluginInstallationCounts() {
SetTotalPluginsToInstall(0)
SetPluginsInstalledCount(0)
}

type DeletePluginOptions struct {
Target configtypes.Target
PluginName string
Expand Down Expand Up @@ -492,6 +492,7 @@ func InitializePlugin(plugin *cli.PluginInfo) error {

// InstallStandalonePlugin installs a plugin by name, version and target as a standalone plugin.
func InstallStandalonePlugin(pluginName, version string, target configtypes.Target) error {
defer StopSpinner()
return installPlugin(pluginName, version, target, "")
}

Expand All @@ -505,6 +506,11 @@ func SetPluginsInstalledCount(count int) {
pluginsInstalledCount = count
}

// GetPluginsInstalledCount returns the number of plugins installed
func GetPluginsInstalledCount() int {
return pluginsInstalledCount
}

// IncrementPluginsInstalledCount increments the number of plugins installed
func IncrementPluginsInstalledCount(count int) {
pluginsInstalledCount += count
Expand Down Expand Up @@ -635,7 +641,6 @@ func InstallPluginsFromGivenPluginGroup(pluginName, groupIDAndVersion string, pg
numErrors := 0
mandatoryPluginsExist := false
pluginExist := false
pluginsInstalledCount = 0

pluginsToInstall := make([]*plugininventory.PluginGroupPluginEntry, 0)
for _, plugin := range pg.Versions[pg.RecommendedVersion] {
Expand All @@ -649,11 +654,11 @@ func InstallPluginsFromGivenPluginGroup(pluginName, groupIDAndVersion string, pg
}
SetTotalPluginsToInstall(len(pluginsToInstall))
SetPluginsInstalledCount(0)
defer StopSpinner()
for _, plugin := range pluginsToInstall {
err := InstallStandalonePlugin(plugin.Name, plugin.Version, plugin.Target)
if err != nil {
numErrors++
log.Warningf("unable to install plugin '%s': %v", plugin.Name, err.Error())
} else {
IncrementPluginsInstalledCount(1)
}
Expand All @@ -674,12 +679,10 @@ func InstallPluginsFromGivenPluginGroup(pluginName, groupIDAndVersion string, pg
return groupIDAndVersion, fmt.Errorf("could not install %d plugin(s) from group '%s'", numErrors, groupIDAndVersion)
}

if pluginsInstalledCount == 0 {
if GetPluginsInstalledCount() == 0 {
return groupIDAndVersion, fmt.Errorf("plugin '%s' is not part of the group '%s'", pluginName, groupIDAndVersion)
}
SetTotalPluginsToInstall(0)
SetPluginsInstalledCount(0)
defer StopSpinner()
ResetPluginInstallationCounts()

return groupIDAndVersion, nil
}
Expand Down Expand Up @@ -1193,8 +1196,6 @@ func InstallPluginsFromLocalSource(pluginName, version string, target configtype
errList = append(errList, err)
}
}
SetTotalPluginsToInstall(0)
SetPluginsInstalledCount(0)
err = kerrors.NewAggregate(errList)
if err != nil {
return err
Expand Down

0 comments on commit 333694a

Please sign in to comment.