mirror of
https://github.com/Jguer/yay.git
synced 2024-11-07 17:47:21 +01:00
34 lines
606 B
Go
34 lines
606 B
Go
package exe
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
type CmdBuilder struct {
|
|
GitBin string
|
|
GitFlags []string
|
|
}
|
|
|
|
func NewCmdBuilder(gitBin, gitFlags string) *CmdBuilder {
|
|
c := &CmdBuilder{GitBin: gitBin, GitFlags: strings.Fields(gitFlags)}
|
|
|
|
return c
|
|
}
|
|
|
|
func (c *CmdBuilder) BuildGitCmd(dir string, extraArgs ...string) *exec.Cmd {
|
|
args := make([]string, 0, len(c.GitFlags))
|
|
copy(args, c.GitFlags)
|
|
|
|
if dir != "" {
|
|
args = append(args, "-C", dir)
|
|
}
|
|
|
|
args = append(args, extraArgs...)
|
|
|
|
cmd := exec.Command(c.GitBin, args...)
|
|
cmd.Env = append(os.Environ(), "GIT_TERMINAL_PROMPT=0")
|
|
return cmd
|
|
}
|