2024-05-05 12:55:58 +00:00
|
|
|
package types
|
|
|
|
|
2024-05-05 14:29:17 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"golang.org/x/sys/execabs"
|
|
|
|
)
|
2024-05-05 12:55:58 +00:00
|
|
|
|
|
|
|
type Cmd struct {
|
|
|
|
*execabs.Cmd
|
|
|
|
Private bool
|
2024-05-05 14:29:17 +00:00
|
|
|
Trace *bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Cmd) Run() error {
|
|
|
|
if c.Trace == nil {
|
|
|
|
c.SetTrace(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Env == nil {
|
|
|
|
c.Env = os.Environ()
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Stdout == nil {
|
|
|
|
c.Stdout = os.Stdout
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Stderr == nil {
|
|
|
|
c.Stderr = os.Stderr
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Private {
|
|
|
|
c.Stdout = io.Discard
|
|
|
|
}
|
|
|
|
|
|
|
|
if *c.Trace {
|
|
|
|
fmt.Fprintf(os.Stdout, "+ %s\n", strings.Join(c.Args, " "))
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := c.Start(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Cmd) SetTrace(trace bool) {
|
|
|
|
c.Trace = &trace
|
2024-05-05 12:55:58 +00:00
|
|
|
}
|