yay/pkg/settings/exe/passers.go

49 lines
1017 B
Go
Raw Normal View History

package exe
import (
"os"
"os/exec"
)
type CmdBuilder struct {
2020-08-22 01:24:52 +02:00
GitBin string
GitFlags []string
MakepkgFlags []string
MakepkgConfPath string
MakepkgBin string
}
func (c *CmdBuilder) BuildGitCmd(dir string, extraArgs ...string) *exec.Cmd {
args := make([]string, len(c.GitFlags), len(c.GitFlags)+len(extraArgs))
copy(args, c.GitFlags)
if dir != "" {
args = append(args, "-C", dir)
}
if len(extraArgs) > 0 {
args = append(args, extraArgs...)
}
cmd := exec.Command(c.GitBin, args...)
cmd.Env = append(os.Environ(), "GIT_TERMINAL_PROMPT=0")
return cmd
}
2020-08-22 01:24:52 +02:00
func (c *CmdBuilder) BuildMakepkgCmd(dir string, extraArgs ...string) *exec.Cmd {
args := make([]string, len(c.MakepkgFlags), len(c.MakepkgFlags)+len(extraArgs))
2020-08-22 01:24:52 +02:00
copy(args, c.MakepkgFlags)
if c.MakepkgConfPath != "" {
args = append(args, "--config", c.MakepkgConfPath)
}
if len(extraArgs) > 0 {
args = append(args, extraArgs...)
}
2020-08-22 01:24:52 +02:00
cmd := exec.Command(c.MakepkgBin, args...)
cmd.Dir = dir
return cmd
}