@@ -16,10 +16,14 @@ type CommandDescriptor struct {
1616 Environment map [string ]string `json:"env"`
1717 AdditionalEnvironment map [string ]string `json:"additionalEnv"`
1818 WorkingDirectory string `json:"workingDir"`
19- DisableStdOut bool `json:"disableStdOut"`
20- DisableStdErr bool `json:"disableStdErr"`
21- FirstNBytes int `json:"firstNBytes"`
22- LastNBytes int `json:"lastNBytes"`
19+ Output * OutputSettings `json:"output,omitempty"`
20+ }
21+
22+ type OutputSettings struct {
23+ DisableStdOut bool `json:"disableStdOut"`
24+ DisableStdErr bool `json:"disableStdErr"`
25+ FirstNBytes int `json:"firstNBytes"`
26+ LastNBytes int `json:"lastNBytes"`
2327}
2428
2529func (c CommandDescriptor ) Run (ctx context.Context ) ([]byte , error ) {
@@ -45,10 +49,10 @@ func (c CommandDescriptor) Run(ctx context.Context) ([]byte, error) {
4549 }()
4650
4751 cmd := cmdBuild .WithErrorChecker (cmdchain .IgnoreExitErrors ()).Finalize ()
48- if ! c .DisableStdOut {
52+ if c . Output == nil || ! c . Output .DisableStdOut {
4953 cmd = cmd .WithOutput (oFile )
5054 }
51- if ! c .DisableStdErr {
55+ if c . Output == nil || ! c . Output .DisableStdErr {
5256 cmd = cmd .WithError (oFile )
5357 }
5458
@@ -57,7 +61,11 @@ func (c CommandDescriptor) Run(ctx context.Context) ([]byte, error) {
5761}
5862
5963func (c CommandDescriptor ) getOutput (f * os.File ) []byte {
60- if c .FirstNBytes < 0 || c .LastNBytes < 0 {
64+ if c .Output == nil {
65+ return readFile (f )
66+ }
67+ cfg := c .Output
68+ if cfg .FirstNBytes < 0 || cfg .LastNBytes < 0 {
6169 return readFile (f )
6270 }
6371
@@ -69,7 +77,7 @@ func (c CommandDescriptor) getOutput(f *os.File) []byte {
6977 )
7078 return nil
7179 }
72- if c .FirstNBytes + c .LastNBytes > int (fs .Size ()) {
80+ if cfg .FirstNBytes + cfg .LastNBytes > int (fs .Size ()) {
7381 return readFile (f )
7482 }
7583
@@ -83,34 +91,34 @@ func (c CommandDescriptor) getOutput(f *os.File) []byte {
8391 return nil
8492 }
8593
86- if c .FirstNBytes > 0 {
87- _ , err = io .CopyN (buf , f , int64 (c .FirstNBytes ))
94+ if cfg .FirstNBytes > 0 {
95+ _ , err = io .CopyN (buf , f , int64 (cfg .FirstNBytes ))
8896 if err != nil && err != io .EOF {
8997 slog .Error ("Could not read first bytes from command output file." ,
90- "bytes" , c .FirstNBytes ,
98+ "bytes" , cfg .FirstNBytes ,
9199 "path" , f .Name (),
92100 "error" , err ,
93101 )
94102 return nil
95103 }
96104 } else {
97105 // Indicate that there were bytes skipped
98- buf .WriteString (skippedBytesIndicator (fs .Size () - int64 (c .LastNBytes )))
106+ buf .WriteString (skippedBytesIndicator (fs .Size () - int64 (cfg .LastNBytes )))
99107 buf .WriteRune ('\n' )
100108 }
101109
102- if c .FirstNBytes > 0 && c .LastNBytes > 0 {
110+ if cfg .FirstNBytes > 0 && cfg .LastNBytes > 0 {
103111 // Indicate that there were bytes skipped
104112 buf .WriteRune ('\n' )
105- buf .WriteString (skippedBytesIndicator (fs .Size () - int64 (c .FirstNBytes + c .LastNBytes )))
113+ buf .WriteString (skippedBytesIndicator (fs .Size () - int64 (cfg .FirstNBytes + cfg .LastNBytes )))
106114 buf .WriteRune ('\n' )
107115 }
108116
109- if c .LastNBytes > 0 {
110- _ , err = f .Seek (- int64 (c .LastNBytes ), io .SeekEnd ) // Seek to the last N bytes
117+ if cfg .LastNBytes > 0 {
118+ _ , err = f .Seek (- int64 (cfg .LastNBytes ), io .SeekEnd ) // Seek to the last N bytes
111119 if err != nil {
112120 slog .Error ("Could not seek to the last bytes of command output file." ,
113- "bytes" , c .LastNBytes ,
121+ "bytes" , cfg .LastNBytes ,
114122 "path" , f .Name (),
115123 "error" , err ,
116124 )
@@ -119,7 +127,7 @@ func (c CommandDescriptor) getOutput(f *os.File) []byte {
119127 _ , err = io .Copy (buf , f )
120128 if err != nil && err != io .EOF {
121129 slog .Error ("Could not read last bytes from command output file." ,
122- "bytes" , c .LastNBytes ,
130+ "bytes" , cfg .LastNBytes ,
123131 "path" , f .Name (),
124132 "error" , err ,
125133 )
@@ -128,7 +136,7 @@ func (c CommandDescriptor) getOutput(f *os.File) []byte {
128136 } else {
129137 // Indicate that there were bytes skipped
130138 buf .WriteRune ('\n' )
131- buf .WriteString (skippedBytesIndicator (fs .Size () - int64 (c .FirstNBytes )))
139+ buf .WriteString (skippedBytesIndicator (fs .Size () - int64 (cfg .FirstNBytes )))
132140 }
133141
134142 return buf .Bytes ()
0 commit comments