|
16 | 16 | package feedback
|
17 | 17 |
|
18 | 18 | import (
|
| 19 | + "errors" |
19 | 20 | "io"
|
20 | 21 | )
|
21 | 22 |
|
22 |
| -// OutputStreams returns the underlying io.Writer to directly stream to |
| 23 | +// DirectStreams returns the underlying io.Writer to directly stream to |
23 | 24 | // stdout and stderr.
|
24 |
| -// If the selected output format is not Text, the returned writers will |
25 |
| -// accumulate the output until command execution is completed. |
| 25 | +// If the selected output format is not Text, the function will error. |
| 26 | +// Using this function will allow usage of the PrintResult anymore. |
| 27 | +func DirectStreams() (io.Writer, io.Writer, error) { |
| 28 | + if !formatSelected { |
| 29 | + panic("output format not yet selected") |
| 30 | + } |
| 31 | + if format != Text { |
| 32 | + return nil, nil, errors.New(tr("available only in text format")) |
| 33 | + } |
| 34 | + return stdOut, stdErr, nil |
| 35 | +} |
| 36 | + |
| 37 | +// OutputStreams returns a pair of io.Writer to write the command output. |
| 38 | +// The returned writers will accumulate the output until the command |
| 39 | +// execution is completed, so they are not suitable for printing an unbounded |
| 40 | +// stream like a debug logger or an event watcher (use DirectStreams for |
| 41 | +// that purpose). |
| 42 | +// |
| 43 | +// If the output format is Text the output will be directly streamed to the |
| 44 | +// underlying stdio streams in real time. |
| 45 | +// |
26 | 46 | // This function returns also a callback that must be called when the
|
27 |
| -// command execution is completed, it will return a *OutputStreamsResult |
28 |
| -// object that can be used as a Result or to retrieve the output to embed |
29 |
| -// it in another object. |
| 47 | +// command execution is completed, it will return an *OutputStreamsResult |
| 48 | +// object that can be used as a Result or to retrieve the accumulated output |
| 49 | +// to embed it in another object. |
30 | 50 | func OutputStreams() (io.Writer, io.Writer, func() *OutputStreamsResult) {
|
31 | 51 | if !formatSelected {
|
32 | 52 | panic("output format not yet selected")
|
|
0 commit comments