66 "io"
77 "os"
88 "path/filepath"
9- "strings"
109
1110 "github.com/launchrctl/launchr"
1211)
@@ -16,35 +15,14 @@ type fileStreams interface {
1615}
1716
1817// webCli implements Streams interface.
19- // @todo Maybe refactor original streams.
2018type webCli struct {
21- in * launchr.In
22- out * launchr.Out
23- err io.Writer
19+ launchr.Streams
2420 files []* os.File
2521}
2622
27- // In returns the reader used for stdin
28- func (cli * webCli ) In () * launchr.In {
29- return cli .in
30- }
31-
32- // Out returns the writer used for stdout
33- func (cli * webCli ) Out () * launchr.Out {
34- return cli .out
35- }
36-
37- // Err returns the writer used for stderr
38- func (cli * webCli ) Err () io.Writer {
39- return cli .err
40- }
41-
4223// Close implements io.Closer.
4324func (cli * webCli ) Close () (err error ) {
44- for i := 0 ; i < len (cli .files ); i ++ {
45- _ = cli .files [i ].Close ()
46- }
47- return nil
25+ return cli .Streams .Close ()
4826}
4927
5028// GetStreamData implements fileStreams.
@@ -93,7 +71,14 @@ func (w *wrappedWriter) Write(p []byte) (int, error) {
9371 return w .w .Write (p )
9472}
9573
96- func createFileStreams (streamsDir , runId string ) (* webCli , error ) {
74+ func (w * wrappedWriter ) Close () error {
75+ if c , ok := w .w .(io.Closer ); ok {
76+ return c .Close ()
77+ }
78+ return nil
79+ }
80+
81+ func createFileStreams (streamsDir , runId string , app launchr.App ) (* webCli , error ) {
9782 outfile , err := os .Create (filepath .Join (streamsDir , runId + "-out.txt" ))
9883 if err != nil {
9984 return nil , fmt .Errorf ("error creating output file: %w" , err )
@@ -116,9 +101,7 @@ func createFileStreams(streamsDir, runId string) (*webCli, error) {
116101
117102 // Build and return webCli
118103 return & webCli {
119- files : []* os.File {outfile , errfile },
120- in : launchr .NewIn (io .NopCloser (strings .NewReader ("" ))),
121- out : launchr .NewOut (out ),
122- err : errWriter ,
104+ Streams : launchr .NewBasicStreams (nil , app .SensitiveWriter (out ), app .SensitiveWriter (errWriter )),
105+ files : []* os.File {outfile , errfile },
123106 }, nil
124107}
0 commit comments