MCPcopy Create free account
hub / github.com/ddev/ddev / CaptureUserOut

Function CaptureUserOut

pkg/util/capture.go:16–38  ·  view source on GitHub ↗

CaptureUserOut captures output written to UserOut to a string. Capturing starts when it is called. It returns an anonymous function that when called, will return a string containing the output during capture, and revert once again to the original value of UserOut.Out.

()

Source from the content-addressed store, hash-verified

14// when called, will return a string containing the output during capture, and
15// revert once again to the original value of UserOut.Out.
16func CaptureUserOut() func() string {
17 old := output.UserOut.Out // keep backup of the real stdout
18 r, w, _ := os.Pipe()
19 output.UserOut.Out = w
20
21 return func() string {
22 outC := make(chan string)
23 // copy the output in a separate goroutine so printing can't block indefinitely
24 go func() {
25 var buf bytes.Buffer
26 _, err := io.Copy(&buf, r)
27 CheckErr(err)
28 outC <- buf.String()
29 }()
30
31 // back to normal state
32 CheckClose(w)
33 output.UserOut.Out = old // restoring the real stdout
34
35 out := <-outC
36 return out
37 }
38}
39
40// CaptureUserErr captures output written to UserErr to a string.
41// Capturing starts when it is called. It returns an anonymous function that

Callers 15

TestConfigCommandFunction · 0.92
TestProcessHooksFunction · 0.92
TestDdevFullSiteSetupFunction · 0.92
StartMethod · 0.92
TestGetInputFunction · 0.92
TestGetQuotedInputFunction · 0.92
TestCaptureUserOutFunction · 0.92
isValidComposerOptionFunction · 0.92
TestTLSDiagnoseSmokeFunction · 0.92

Calls 2

CheckErrFunction · 0.85
CheckCloseFunction · 0.85

Tested by 15

TestConfigCommandFunction · 0.74
TestProcessHooksFunction · 0.74
TestDdevFullSiteSetupFunction · 0.74
TestGetInputFunction · 0.74
TestGetQuotedInputFunction · 0.74
TestCaptureUserOutFunction · 0.74
TestTLSDiagnoseSmokeFunction · 0.74