From 672312f0afaad113c30ee66c9b21296ce721c574 Mon Sep 17 00:00:00 2001 From: Anuj Chaudhari Date: Tue, 6 Feb 2024 11:57:33 -0800 Subject: [PATCH] Update spinner to use updated NewSpinner API from plugin runtime (#669) --- go.mod | 2 +- go.sum | 4 ++-- pkg/pluginmanager/manager.go | 30 +++++++++++------------------- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/go.mod b/go.mod index a0167165b..ec6d83a32 100644 --- a/go.mod +++ b/go.mod @@ -42,7 +42,7 @@ require ( github.com/vmware-tanzu/carvel-ytt v0.40.0 github.com/vmware-tanzu/tanzu-cli/test/e2e/framework v0.0.0-00010101000000-000000000000 github.com/vmware-tanzu/tanzu-framework/capabilities/client v0.0.0-20230523145612-1c6fbba34686 - github.com/vmware-tanzu/tanzu-plugin-runtime v1.2.0-dev.0.20240122215628-021d60b78abe + github.com/vmware-tanzu/tanzu-plugin-runtime v1.2.0-dev.0.20240206192120-055fd83cf63d go.pinniped.dev v0.20.0 golang.org/x/mod v0.12.0 golang.org/x/oauth2 v0.8.0 diff --git a/go.sum b/go.sum index 795de3a18..5e7b06c06 100644 --- a/go.sum +++ b/go.sum @@ -738,8 +738,8 @@ github.com/vmware-tanzu/tanzu-framework/apis/run v0.0.0-20230419030809-7081502eb github.com/vmware-tanzu/tanzu-framework/apis/run v0.0.0-20230419030809-7081502ebf68/go.mod h1:e1Uef+Ux5BIHpYwqbeP2ZZmOzehBcez2vUEWXHe+xHE= github.com/vmware-tanzu/tanzu-framework/capabilities/client v0.0.0-20230523145612-1c6fbba34686 h1:VcuXqUXFxm5WDqWkzAlU/6cJXua0ozELnqD59fy7J6E= github.com/vmware-tanzu/tanzu-framework/capabilities/client v0.0.0-20230523145612-1c6fbba34686/go.mod h1:AFGOXZD4tH+KhpmtV0VjWjllXhr8y57MvOsIxTtywc4= -github.com/vmware-tanzu/tanzu-plugin-runtime v1.2.0-dev.0.20240122215628-021d60b78abe h1:jlR24NEVKyBiTGlEtqWBSGULBqZe0LJd40VzybAStY0= -github.com/vmware-tanzu/tanzu-plugin-runtime v1.2.0-dev.0.20240122215628-021d60b78abe/go.mod h1:M7WVZoItdyQp53tEprQIa6PZmhbrLe3CzuyQphWuRyI= +github.com/vmware-tanzu/tanzu-plugin-runtime v1.2.0-dev.0.20240206192120-055fd83cf63d h1:I2eep1os5VH2jdFMFC1ObjzUcOrNFARWubZbpDkTEGk= +github.com/vmware-tanzu/tanzu-plugin-runtime v1.2.0-dev.0.20240206192120-055fd83cf63d/go.mod h1:M7WVZoItdyQp53tEprQIa6PZmhbrLe3CzuyQphWuRyI= github.com/xanzy/go-gitlab v0.83.0 h1:37p0MpTPNbsTMKX/JnmJtY8Ch1sFiJzVF342+RvZEGw= github.com/xanzy/go-gitlab v0.83.0/go.mod h1:5ryv+MnpZStBH8I/77HuQBsMbBGANtVpLWC15qOjWAw= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= diff --git a/pkg/pluginmanager/manager.go b/pkg/pluginmanager/manager.go index 56f8b0a69..183d42c8f 100644 --- a/pkg/pluginmanager/manager.go +++ b/pkg/pluginmanager/manager.go @@ -746,17 +746,10 @@ func installOrUpgradePlugin(p *discovery.Discovered, version string, installTest // Log message based on different installation conditions installingMsg, installedMsg, errMsg := getPluginInstallationMessage(p, version, plugin != nil, isPluginAlreadyInstalled) - var spinnerErr error - var sow component.OutputWriterSpinner + var spinner component.OutputWriterSpinner // Initialize the spinner if the spinner is allowed if component.IsTTYEnabled() { - spinnerOptions := component.OutputWriterSpinnerOptions{ - SpinnerOptions: []component.OutputWriterSpinnerOption{ - component.WithSpinnerFinalText(installedMsg, log.LogTypeINFO), - }, - } - // Create a channel to receive OS signals signalChannel := make(chan os.Signal, 1) // Register the channel to receive interrupt signals (e.g., Ctrl+C) @@ -767,14 +760,13 @@ func installOrUpgradePlugin(p *discovery.Discovered, version string, installTest }() // Initialize the spinner - sow, spinnerErr = component.NewOutputWriterSpinnerWithSpinnerOptions(os.Stderr, component.TableOutputType, installingMsg, true, spinnerOptions) - if spinnerErr != nil { - log.V(6).Infof("Unable to initialize spinner: %v", spinnerErr.Error()) - log.Info(installingMsg) - } - if sow != nil { - defer sow.StopSpinner() - } + spinner = component.NewOutputWriterSpinner(component.WithOutputStream(os.Stderr), + component.WithSpinnerText(installingMsg), + component.WithSpinnerStarted(), + component.WithSpinnerFinalText(installedMsg, log.LogTypeINFO)) + + defer spinner.StopSpinner() + // Start a goroutine that listens for interrupt signals go func(s component.OutputWriterSpinner) { sig := <-signalChannel @@ -785,15 +777,15 @@ func installOrUpgradePlugin(p *discovery.Discovered, version string, installTest } os.Exit(128 + int(sig.(syscall.Signal))) } - }(sow) + }(spinner) } else { log.Info(installingMsg) } pluginErr := verifyInstallAndInitializePlugin(plugin, p, version, installTestPlugin) if pluginErr != nil { - if sow != nil { - sow.SetFinalText(errMsg, log.LogTypeERROR) + if spinner != nil { + spinner.SetFinalText(errMsg, log.LogTypeERROR) } } return pluginErr