From 3220ede04d8bd5a3e38cffe5e5238f0715b878fb Mon Sep 17 00:00:00 2001 From: Charlie Moog Date: Tue, 20 Oct 2020 17:20:56 -0500 Subject: [PATCH] Fix rebuild output for non-terminals --- internal/cmd/rebuild.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/internal/cmd/rebuild.go b/internal/cmd/rebuild.go index 71d2599a..a5d42a50 100644 --- a/internal/cmd/rebuild.go +++ b/internal/cmd/rebuild.go @@ -3,6 +3,7 @@ package cmd import ( "context" "fmt" + "os" "strings" "time" @@ -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" ) @@ -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 @@ -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 { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy