Stop spinner on cancel

Signed-off-by: Boris Kreitchman <bkreitch@gmail.com>
pull/4922/head
Boris Kreitchman 5 months ago
parent b8bf44e0ae
commit 170e4f6f57

@ -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()
if err != nil {
return "", false, fmt.Errorf("failed to start spinner: %w", err)
}
err = b.startSpinner()
if err != nil {
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()
if err != nil {
return "", createdOrDrifted, fmt.Errorf("failed to stop spinner: %w", err)
}
err = b.stopSpinner()
if err != nil {
return "", createdOrDrifted, err
}
return output.String(), createdOrDrifted, errors.Reduce(errors.Flatten(errors.NewAggregate(diffErrs)))

Loading…
Cancel
Save