Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Fix rebuild output for non-terminals #148

Merged
merged 1 commit into from
Oct 20, 2020
Merged
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
18 changes: 16 additions & 2 deletions internal/cmd/rebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"context"
"fmt"
"os"
"strings"
"time"

Expand All @@ -12,6 +13,7 @@ import (
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
"go.coder.com/flog"
"golang.org/x/crypto/ssh/terminal"
"golang.org/x/xerrors"
)

Expand Down Expand Up @@ -74,6 +76,9 @@ func trailBuildLogs(ctx context.Context, client *coder.Client, envID string) err

newSpinner := func() *spinner.Spinner { return spinner.New(spinner.CharSets[11], 100*time.Millisecond) }

// this tells us whether to show dynamic loaders when printing output
isTerminal := terminal.IsTerminal(int(os.Stdout.Fd()))

logs, err := client.FollowEnvironmentBuildLog(ctx, envID)
if err != nil {
return err
Expand All @@ -88,23 +93,32 @@ func trailBuildLogs(ctx context.Context, client *coder.Client, envID string) err
// the FE uses this to reset the UI
// the CLI doesn't need to do anything here given that we only append to the trail
case coder.BuildLogTypeStage:
msg := fmt.Sprintf("%s %s", l.BuildLog.Time.Format(time.RFC3339), l.BuildLog.Msg)
if !isTerminal {
fmt.Println(msg)
continue
}
if s != nil {
s.Stop()
fmt.Print("\n")
}
s = newSpinner()
msg := fmt.Sprintf("%s %s", l.BuildLog.Time.Format(time.RFC3339), l.BuildLog.Msg)
s.Suffix = fmt.Sprintf(" -- %s", msg)
s.FinalMSG = fmt.Sprintf("%s -- %s", check, msg)
s.Start()
case coder.BuildLogTypeSubstage:
// TODO(@cmoog) add verbose substage printing
case coder.BuildLogTypeError:
errMsg := color.RedString("\t%s", l.BuildLog.Msg)
if !isTerminal {
fmt.Println(errMsg)
continue
}
if s != nil {
s.FinalMSG = fmt.Sprintf("%s %s", failure, strings.TrimPrefix(s.Suffix, " "))
s.Stop()
}
fmt.Print(color.RedString("\t%s", l.BuildLog.Msg))
fmt.Print(errMsg)
s = newSpinner()
case coder.BuildLogTypeDone:
if s != nil {
Expand Down