1616package utils
1717
1818import (
19- "bytes"
20- "io"
2119 "os"
2220 "strings"
2321 "unicode"
2422
25- "github.com/arduino/arduino-cli/executils"
2623 "github.com/arduino/arduino-cli/i18n"
2724 f "github.com/arduino/arduino-cli/internal/algorithms"
2825 "github.com/arduino/go-paths-helper"
@@ -201,14 +198,6 @@ func FindFilesInFolder(dir *paths.Path, recurse bool, extensions ...string) (pat
201198 return dir .ReadDir (fileFilter )
202199}
203200
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-
212201func printableArgument (arg string ) string {
213202 if strings .ContainsAny (arg , "\" \\ \t " ) {
214203 arg = strings .ReplaceAll (arg , "\\ " , "\\ \\ " )
@@ -218,56 +207,14 @@ func printableArgument(arg string) string {
218207 return arg
219208}
220209
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.
222211// This adds basic escaping which is sufficient for debug output, but
223212// probably not for shell interpretation. This essentially reverses
224213// ParseCommandLine.
225- func printableCommand (parts []string ) string {
214+ func PrintableCommand (parts []string ) string {
226215 return strings .Join (f .Map (parts , printableArgument ), " " )
227216}
228217
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-
271218// DirContentIsOlderThan DirContentIsOlderThan returns true if the content of the given directory is
272219// older than target file. If extensions are given, only the files with these
273220// extensions are tested.
0 commit comments