Merge pull request #4922 from bkreitch/stop-spinner-on-cancel

Stop spinner on cancel of flux diff kustomization
pull/4926/head
Stefan Prodan 5 months ago committed by GitHub
commit 52512a94a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -583,10 +583,44 @@ func (b *Builder) Cancel() error {
b.mu.Lock()
defer b.mu.Unlock()
err := kustomize.CleanDirectory(b.resourcesPath, b.action)
err := b.stopSpinner()
if err != nil {
return err
}
err = kustomize.CleanDirectory(b.resourcesPath, b.action)
if err != nil {
return err
}
return nil
}
func (b *Builder) startSpinner() error {
if b.spinner == nil {
return nil
}
err := b.spinner.Start()
if err != nil {
return fmt.Errorf("failed to start spinner: %w", err)
}
return nil
}
func (b *Builder) stopSpinner() error {
if b.spinner == nil {
return nil
}
status := b.spinner.Status()
if status == yacspin.SpinnerRunning || status == yacspin.SpinnerPaused {
err := b.spinner.Stop()
if err != nil {
return fmt.Errorf("failed to stop spinner: %w", err)
}
}
return nil
}

@ -77,11 +77,9 @@ func (b *Builder) Diff() (string, bool, error) {
ctx, cancel := context.WithTimeout(context.Background(), b.timeout)
defer cancel()
if b.spinner != nil {
err = b.spinner.Start()
err = b.startSpinner()
if err != nil {
return "", false, fmt.Errorf("failed to start spinner: %w", err)
}
return "", false, err
}
var diffErrs []error
@ -151,11 +149,9 @@ func (b *Builder) Diff() (string, bool, error) {
}
}
if b.spinner != nil {
err = b.spinner.Stop()
err = b.stopSpinner()
if err != nil {
return "", createdOrDrifted, fmt.Errorf("failed to stop spinner: %w", err)
}
return "", createdOrDrifted, err
}
return output.String(), createdOrDrifted, errors.Reduce(errors.Flatten(errors.NewAggregate(diffErrs)))

Loading…
Cancel
Save