Skip to content

Commit c166820

Browse files
committed
progress indicator
Signed-off-by: Harper, Jason M <[email protected]>
1 parent d476221 commit c166820

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

cmd/config/restore.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import (
88
"bufio"
99
"bytes"
1010
"fmt"
11-
"io"
1211
"log/slog"
1312
"os"
1413
"os/exec"
1514
"perfspect/internal/common"
15+
"perfspect/internal/progress"
1616
"regexp"
1717
"slices"
1818
"strconv"
@@ -149,7 +149,7 @@ func runRestoreCmd(cmd *cobra.Command, args []string) error {
149149
cmdArgs := []string{"config"}
150150

151151
// copy target flags from restore command first
152-
targetFlags := []string{"target", "targets", "user", "key", "keystring", "port", "password"}
152+
targetFlags := []string{"target", "targets", "user", "key", "port"}
153153
for _, flagName := range targetFlags {
154154
if flag := cmd.Flags().Lookup(flagName); flag != nil && flag.Changed {
155155
cmdArgs = append(cmdArgs, fmt.Sprintf("--%s", flagName), flag.Value.String())
@@ -203,21 +203,28 @@ func runRestoreCmd(cmd *cobra.Command, args []string) error {
203203

204204
// execute the command
205205
slog.Info("executing perfspect config", slog.String("command", executable), slog.String("args", strings.Join(cmdArgs, " ")))
206-
fmt.Println() // blank line before config output
207206

208207
execCmd := exec.Command(executable, cmdArgs...)
209208
execCmd.Stdout = os.Stdout
210209
execCmd.Stdin = os.Stdin
211210

212-
// capture stderr for parsing
211+
// capture stderr for parsing (don't display it in real-time to keep output clean)
213212
var stderrBuf bytes.Buffer
214-
stderrWriter := io.MultiWriter(os.Stderr, &stderrBuf)
215-
execCmd.Stderr = stderrWriter
213+
execCmd.Stderr = &stderrBuf
214+
215+
// show progress while command is running
216+
multiSpinner := progress.NewMultiSpinner()
217+
err = multiSpinner.AddSpinner("config")
218+
if err != nil {
219+
return fmt.Errorf("failed to add spinner: %v", err)
220+
}
221+
multiSpinner.Start()
222+
_ = multiSpinner.Status("config", "applying configuration changes")
216223

217224
err = execCmd.Run()
218225

219-
// parse stderr output and present results in flag order
220-
parseAndPresentResults(stderrBuf.String(), flagValues)
226+
_ = multiSpinner.Status("config", "configuration changes complete")
227+
multiSpinner.Finish()
221228

222229
if err != nil {
223230
if exitErr, ok := err.(*exec.ExitError); ok {
@@ -234,6 +241,9 @@ func runRestoreCmd(cmd *cobra.Command, args []string) error {
234241
return err
235242
}
236243

244+
// parse stderr output and present results in flag order
245+
parseAndPresentResults(stderrBuf.String(), flagValues)
246+
237247
return nil
238248
}
239249

0 commit comments

Comments
 (0)