@@ -50,6 +50,8 @@ import (
50
50
// NOTE: If you do not want colorized output, set MINIKUBE_IN_STYLE=false in your environment.
51
51
52
52
var (
53
+ // silent will disable all output, if called from a script. Set using SetSilent()
54
+ silent bool
53
55
// outFile is where Out* functions send output to. Set using SetOutFile()
54
56
outFile fdWriter
55
57
// errFile is where Err* functions send output to. Set using SetErrFile()
@@ -122,6 +124,11 @@ func String(format string, a ...interface{}) {
122
124
// Flush log buffer so that output order makes sense
123
125
klog .Flush ()
124
126
127
+ if silent {
128
+ klog .Infof (format , a ... )
129
+ return
130
+ }
131
+
125
132
if outFile == nil {
126
133
klog .Warningf ("[unset outFile]: %s" , fmt .Sprintf (format , a ... ))
127
134
return
@@ -131,7 +138,13 @@ func String(format string, a ...interface{}) {
131
138
if spin .Active () {
132
139
spin .Stop ()
133
140
}
134
- _ , err := fmt .Fprintf (outFile , format , a ... )
141
+
142
+ Output (outFile , format , a ... )
143
+ }
144
+
145
+ // Output writes a basic formatted string
146
+ func Output (file fdWriter , format string , a ... interface {}) {
147
+ _ , err := fmt .Fprintf (file , format , a ... )
135
148
if err != nil {
136
149
klog .Errorf ("Fprintf failed: %v" , err )
137
150
}
@@ -152,10 +165,7 @@ func spinnerString(format string, a ...interface{}) {
152
165
if spin .Active () {
153
166
spin .Stop ()
154
167
}
155
- _ , err := fmt .Fprintf (outFile , format , a ... )
156
- if err != nil {
157
- klog .Errorf ("Fprintf failed: %v" , err )
158
- }
168
+ Output (outFile , format , a ... )
159
169
// Start spinning at the end of the printed line
160
170
spin .Start ()
161
171
}
@@ -194,10 +204,7 @@ func Err(format string, a ...interface{}) {
194
204
if spin .Active () {
195
205
spin .Stop ()
196
206
}
197
- _ , err := fmt .Fprintf (errFile , format , a ... )
198
- if err != nil {
199
- klog .Errorf ("Fprint failed: %v" , err )
200
- }
207
+ Output (errFile , format , a ... )
201
208
}
202
209
203
210
// ErrLn writes a basic formatted string with a newline to stderr
@@ -234,6 +241,20 @@ func FailureT(format string, a ...V) {
234
241
ErrT (style .Failure , format , a ... )
235
242
}
236
243
244
+ // IsTerminal returns whether we have a terminal or not
245
+ func IsTerminal (w fdWriter ) bool {
246
+ fd := w .Fd ()
247
+ isT := isatty .IsTerminal (fd )
248
+ klog .Infof ("isatty.IsTerminal(%d) = %v\n " , fd , isT )
249
+ return isT
250
+ }
251
+
252
+ // SetSilent configures whether output is disabled or not
253
+ func SetSilent (q bool ) {
254
+ klog .Infof ("Setting silent to %v" , q )
255
+ silent = q
256
+ }
257
+
237
258
// SetOutFile configures which writer standard output goes to.
238
259
func SetOutFile (w fdWriter ) {
239
260
klog .Infof ("Setting OutFile to fd %d ..." , w .Fd ())
0 commit comments