qrz/vendor/github.com/gobuffalo/packr/v2/packr2/cmd/gocmd.go
Paul Lecuq 36c5d6f2ed
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is failing
large change on qrz
- web service with json support
- web page
- cron service to update database infos
2020-05-09 19:09:27 +02:00

68 lines
1.1 KiB
Go

package cmd
import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
"github.com/gobuffalo/packr/v2/plog"
)
func goCmd(name string, args ...string) error {
cargs := []string{name}
cargs = append(cargs, args...)
if len(args) > 0 {
err := func() error {
path := "."
pwd, err := os.Getwd()
if err != nil {
return err
}
if fi, err := os.Stat(filepath.Join(pwd, args[len(args)-1])); err == nil {
if fi.IsDir() {
return nil
}
path = fi.Name()
}
if filepath.Ext(path) != ".go" {
return nil
}
path, err = filepath.Abs(filepath.Dir(path))
if err != nil {
return err
}
files, err := ioutil.ReadDir(path)
if err != nil {
return err
}
for _, f := range files {
if strings.HasSuffix(f.Name(), "-packr.go") {
cargs = append(cargs, f.Name())
}
}
return nil
}()
if err != nil {
return err
}
}
goBin := os.Getenv("GO_BIN")
if goBin == "" {
goBin = "go"
}
cp := exec.Command(goBin, cargs...)
plog.Logger.Debug(strings.Join(cp.Args, " "))
cp.Stderr = os.Stderr
cp.Stdin = os.Stdin
cp.Stdout = os.Stdout
return cp.Run()
}