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() b.mu.Lock()
defer b.mu.Unlock() defer b.mu.Unlock()
err := kustomize.CleanDirectory(b.resourcesPath, b.action) err := b.stopSpinner()
if err != nil { if err != nil {
return err 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 return nil
} }

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

Loading…
Cancel
Save