16
16
package utils
17
17
18
18
import (
19
- "bytes"
20
- "io"
21
19
"os"
22
20
"strings"
23
21
"unicode"
24
22
25
- "github.com./arduino/arduino-cli/executils"
26
23
"github.com./arduino/arduino-cli/i18n"
27
24
f "github.com./arduino/arduino-cli/internal/algorithms"
28
25
"github.com./arduino/go-paths-helper"
@@ -201,14 +198,6 @@ func FindFilesInFolder(dir *paths.Path, recurse bool, extensions ...string) (pat
201
198
return dir .ReadDir (fileFilter )
202
199
}
203
200
204
- // nolint
205
- const (
206
- Ignore = 0 // Redirect to null
207
- Show = 1 // Show on stdout/stderr as normal
208
- ShowIfVerbose = 2 // Show if verbose is set, Ignore otherwise
209
- Capture = 3 // Capture into buffer
210
- )
211
-
212
201
func printableArgument (arg string ) string {
213
202
if strings .ContainsAny (arg , "\" \\ \t " ) {
214
203
arg = strings .ReplaceAll (arg , "\\ " , "\\ \\ " )
@@ -218,56 +207,14 @@ func printableArgument(arg string) string {
218
207
return arg
219
208
}
220
209
221
- // Convert a command and argument slice back to a printable string.
210
+ // PrintableCommand Convert a command and argument slice back to a printable string.
222
211
// This adds basic escaping which is sufficient for debug output, but
223
212
// probably not for shell interpretation. This essentially reverses
224
213
// ParseCommandLine.
225
- func printableCommand (parts []string ) string {
214
+ func PrintableCommand (parts []string ) string {
226
215
return strings .Join (f .Map (parts , printableArgument ), " " )
227
216
}
228
217
229
- // ExecCommand fixdoc
230
- func ExecCommand (
231
- verbose bool ,
232
- stdoutWriter , stderrWriter io.Writer ,
233
- command * executils.Process , stdout int , stderr int ,
234
- ) ([]byte , []byte , []byte , error ) {
235
- verboseInfoBuf := & bytes.Buffer {}
236
- if verbose {
237
- verboseInfoBuf .WriteString (printableCommand (command .GetArgs ()))
238
- }
239
-
240
- stdoutBuffer := & bytes.Buffer {}
241
- if stdout == Capture {
242
- command .RedirectStdoutTo (stdoutBuffer )
243
- } else if stdout == Show || (stdout == ShowIfVerbose && verbose ) {
244
- if stdoutWriter != nil {
245
- command .RedirectStdoutTo (stdoutWriter )
246
- } else {
247
- command .RedirectStdoutTo (os .Stdout )
248
- }
249
- }
250
-
251
- stderrBuffer := & bytes.Buffer {}
252
- if stderr == Capture {
253
- command .RedirectStderrTo (stderrBuffer )
254
- } else if stderr == Show || (stderr == ShowIfVerbose && verbose ) {
255
- if stderrWriter != nil {
256
- command .RedirectStderrTo (stderrWriter )
257
- } else {
258
- command .RedirectStderrTo (os .Stderr )
259
- }
260
- }
261
-
262
- err := command .Start ()
263
- if err != nil {
264
- return verboseInfoBuf .Bytes (), nil , nil , errors .WithStack (err )
265
- }
266
-
267
- err = command .Wait ()
268
- return verboseInfoBuf .Bytes (), stdoutBuffer .Bytes (), stderrBuffer .Bytes (), errors .WithStack (err )
269
- }
270
-
271
218
// DirContentIsOlderThan DirContentIsOlderThan returns true if the content of the given directory is
272
219
// older than target file. If extensions are given, only the files with these
273
220
// extensions are tested.
0 commit comments