@@ -3,6 +3,7 @@ package cmd
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "os"
6
7
"strings"
7
8
"time"
8
9
@@ -12,6 +13,7 @@ import (
12
13
"github.com/manifoldco/promptui"
13
14
"github.com/spf13/cobra"
14
15
"go.coder.com/flog"
16
+ "golang.org/x/crypto/ssh/terminal"
15
17
"golang.org/x/xerrors"
16
18
)
17
19
@@ -74,6 +76,9 @@ func trailBuildLogs(ctx context.Context, client *coder.Client, envID string) err
74
76
75
77
newSpinner := func () * spinner.Spinner { return spinner .New (spinner .CharSets [11 ], 100 * time .Millisecond ) }
76
78
79
+ // this tells us whether to show dynamic loaders when printing output
80
+ isTerminal := terminal .IsTerminal (int (os .Stdout .Fd ()))
81
+
77
82
logs , err := client .FollowEnvironmentBuildLog (ctx , envID )
78
83
if err != nil {
79
84
return err
@@ -88,23 +93,32 @@ func trailBuildLogs(ctx context.Context, client *coder.Client, envID string) err
88
93
// the FE uses this to reset the UI
89
94
// the CLI doesn't need to do anything here given that we only append to the trail
90
95
case coder .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
+ }
91
101
if s != nil {
92
102
s .Stop ()
93
103
fmt .Print ("\n " )
94
104
}
95
105
s = newSpinner ()
96
- msg := fmt .Sprintf ("%s %s" , l .BuildLog .Time .Format (time .RFC3339 ), l .BuildLog .Msg )
97
106
s .Suffix = fmt .Sprintf (" -- %s" , msg )
98
107
s .FinalMSG = fmt .Sprintf ("%s -- %s" , check , msg )
99
108
s .Start ()
100
109
case coder .BuildLogTypeSubstage :
101
110
// TODO(@cmoog) add verbose substage printing
102
111
case coder .BuildLogTypeError :
112
+ errMsg := color .RedString ("\t %s" , l .BuildLog .Msg )
113
+ if ! isTerminal {
114
+ fmt .Println (errMsg )
115
+ continue
116
+ }
103
117
if s != nil {
104
118
s .FinalMSG = fmt .Sprintf ("%s %s" , failure , strings .TrimPrefix (s .Suffix , " " ))
105
119
s .Stop ()
106
120
}
107
- fmt .Print (color . RedString ( " \t %s" , l . BuildLog . Msg ) )
121
+ fmt .Print (errMsg )
108
122
s = newSpinner ()
109
123
case coder .BuildLogTypeDone :
110
124
if s != nil {
0 commit comments