Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions internal/adapter/clientsideapply/client_side_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,11 @@ import (
"os"
"os/exec"
"testing"
"time"

"github.com/theckman/yacspin"

"github.com/smartcontractkit/crib-sdk/internal/core/domain"
"github.com/smartcontractkit/crib-sdk/internal/core/port"
)

var spinnerCfg = yacspin.Config{
Frequency: 100 * time.Millisecond,
Writer: os.Stderr,
CharSet: yacspin.CharSets[11],
Suffix: " ", // puts at least one space between the animating spinner and the Message
Message: "Executing configuration...",
SuffixAutoColon: true,
ColorAll: true,
Colors: []string{"fgYellow"},
StopCharacter: "✓",
StopColors: []string{"fgGreen"},
StopMessage: "Done!",
StopFailCharacter: "✗",
StopFailColors: []string{"fgRed"},
StopFailMessage: "failed",
}

type (
// EchoRunner is a client-side apply runner that writes arguments to a writer.
EchoRunner struct {
Expand Down
25 changes: 3 additions & 22 deletions internal/adapter/clientsideapply/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package clientsideapply

import (
"context"
"fmt"
"io"
Copy link

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The io import is added but consider if all spinner-related cleanup was properly handled. Verify that no orphaned references to spinner functionality remain in other parts of the codebase.

Copilot uses AI. Check for mistakes.
"os"
"os/exec"
"strings"
"sync"

"github.com/samber/lo"
"github.com/theckman/yacspin"

"github.com/smartcontractkit/crib-sdk/internal/adapter/mempools"
"github.com/smartcontractkit/crib-sdk/internal/core/common/dry"
Expand Down Expand Up @@ -44,19 +43,14 @@ func (c *CmdRunner) Execute(ctx context.Context, input *domain.ClientSideApplyMa
mu.Lock()
defer mu.Unlock()

spin, stop := showProgress()
spin.StopMessage(fmt.Sprintf("Executing %s", input.Spec.Action))

// Run the command, collecting the output of the command.
// Note: The output should have also been streamed to stdout/stderr.
// Possible gotcha here, we may need to inspect the output of the command
// to fully determine success or failure and not just the exit code.
res, err := combinedOutput(e)
if err != nil {
_ = spin.StopFail()
return nil, err
}
stop()

return &domain.RunnerResult{
Output: res,
Expand All @@ -69,22 +63,9 @@ func combinedOutput(cmd *exec.Cmd) ([]byte, error) {
buf, reset := mempools.BytesBuffer.Get()
defer reset()
// tee stdout to both os.Stdout and buf
cmd.Stdout = buf
cmd.Stdout = io.MultiWriter(os.Stdout, buf)
// tee stderr to both os.Stderr and buf
cmd.Stderr = buf
cmd.Stderr = io.MultiWriter(os.Stderr, buf)
err := cmd.Run()
return dry.Wrapf2(buf.Bytes(), err, "running command %q", strings.Join(cmd.Args, " "))
}

func showProgress() (spinner *yacspin.Spinner, stopFn func()) {
spinner, err := yacspin.New(spinnerCfg)
if err != nil {
return spinner, func() {}
}
if err := spinner.Start(); err != nil {
return spinner, func() {}
}
return spinner, func() {
_ = spinner.Stop()
}
}
Loading