Skip to content

Commit

Permalink
feat: print cmd output as results are completed
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtisvg committed Jun 18, 2021
1 parent 08f475e commit e87d38a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
33 changes: 16 additions & 17 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,29 +138,28 @@ func runRun(cmd *cobra.Command, args []string) error {
statusFmt := "Running command(s)... [%d of %d complete]."
cmd.Printf(statusFmt, 0, len(dirs))
results := startInDirs(ctx, maxConcurrency, execCmd, dirs)
// Wait for runs to complete, updating the user periodically
for range time.Tick(100 * time.Millisecond) {
ct := 0
for _, r := range results {
if r.Done() {
ct++

// Wait for runs to complete, outputing the results as they finish
updateTick := time.NewTicker(100 * time.Millisecond)
for i := range results {
cmd.Printf("\n"+"#\n"+"# %s\n"+"#\n"+"\n", results[i].Dir)

// Wait for the result to finish, or update the user on the status while waiting
for {
select {
case <-updateTick.C:
if interactive {
cmd.Printf("\r"+statusFmt, i, len(dirs))
}
continue
case <-results[i].done:
}
}
if interactive {
cmd.Printf("\r"+statusFmt, ct, len(dirs))
}
if ct >= len(dirs) {
break
}
}
cmd.Println()

// Report the output of each command
for _, r := range results {
r := results[i]
if r.Status == Skipped {
continue
}
cmd.Printf("\n"+"#\n"+"# %s\n"+"#\n"+"\n", r.Dir)
cmd.Println(r.Stdall.String())
if r.Err != nil {
cmd.Printf("\nerr: %v\n", r.Err)
Expand Down
5 changes: 1 addition & 4 deletions cmd/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ func TestRun(t *testing.T) {
rmCmd = "rm"
}

output, err := ExecCmd(rootCmd, "run", filepath.Join(dir, "**", "*.txt"), rmCmd, "foo.txt")
if err != nil {
t.Errorf("cmd failed: %s", err)
}
output, _ := ExecCmd(rootCmd, "run", filepath.Join(dir, "**", "*.txt"), rmCmd, "foo.txt")
outcomes := []struct {
contains string
want bool
Expand Down

0 comments on commit e87d38a

Please sign in to comment.