Skip to content

Commit

Permalink
Merge pull request #4922 from bkreitch/stop-spinner-on-cancel
Browse files Browse the repository at this point in the history
Stop spinner on cancel of flux diff kustomization
  • Loading branch information
stefanprodan authored Aug 9, 2024
2 parents b8bf44e + 170e4f6 commit 52512a9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
36 changes: 35 additions & 1 deletion internal/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
16 changes: 6 additions & 10 deletions internal/build/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))
Expand Down

0 comments on commit 52512a9

Please sign in to comment.