Skip to content

Commit

Permalink
Update spinner to use updated NewSpinner API from plugin runtime (vmw…
Browse files Browse the repository at this point in the history
  • Loading branch information
anujc25 authored Feb 6, 2024
1 parent bdbdbd1 commit 672312f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
30 changes: 11 additions & 19 deletions pkg/pluginmanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 672312f

Please sign in to comment.