Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commit282f351

Browse files
authored
Fix rebuild output for non-terminals (#148)
1 parent70615c4 commit282f351

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

‎internal/cmd/rebuild.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"context"
55
"fmt"
6+
"os"
67
"strings"
78
"time"
89

@@ -12,6 +13,7 @@ import (
1213
"github.com/manifoldco/promptui"
1314
"github.com/spf13/cobra"
1415
"go.coder.com/flog"
16+
"golang.org/x/crypto/ssh/terminal"
1517
"golang.org/x/xerrors"
1618
)
1719

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

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

79+
// this tells us whether to show dynamic loaders when printing output
80+
isTerminal:=terminal.IsTerminal(int(os.Stdout.Fd()))
81+
7782
logs,err:=client.FollowEnvironmentBuildLog(ctx,envID)
7883
iferr!=nil {
7984
returnerr
@@ -88,23 +93,32 @@ func trailBuildLogs(ctx context.Context, client *coder.Client, envID string) err
8893
// the FE uses this to reset the UI
8994
// the CLI doesn't need to do anything here given that we only append to the trail
9095
casecoder.BuildLogTypeStage:
96+
msg:=fmt.Sprintf("%s %s",l.BuildLog.Time.Format(time.RFC3339),l.BuildLog.Msg)
97+
if!isTerminal {
98+
fmt.Println(msg)
99+
continue
100+
}
91101
ifs!=nil {
92102
s.Stop()
93103
fmt.Print("\n")
94104
}
95105
s=newSpinner()
96-
msg:=fmt.Sprintf("%s %s",l.BuildLog.Time.Format(time.RFC3339),l.BuildLog.Msg)
97106
s.Suffix=fmt.Sprintf(" -- %s",msg)
98107
s.FinalMSG=fmt.Sprintf("%s -- %s",check,msg)
99108
s.Start()
100109
casecoder.BuildLogTypeSubstage:
101110
// TODO(@cmoog) add verbose substage printing
102111
casecoder.BuildLogTypeError:
112+
errMsg:=color.RedString("\t%s",l.BuildLog.Msg)
113+
if!isTerminal {
114+
fmt.Println(errMsg)
115+
continue
116+
}
103117
ifs!=nil {
104118
s.FinalMSG=fmt.Sprintf("%s %s",failure,strings.TrimPrefix(s.Suffix," "))
105119
s.Stop()
106120
}
107-
fmt.Print(color.RedString("\t%s",l.BuildLog.Msg))
121+
fmt.Print(errMsg)
108122
s=newSpinner()
109123
casecoder.BuildLogTypeDone:
110124
ifs!=nil {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp