Move makepkg handling to its own function

This commit is contained in:
morganamilo 2018-01-04 02:53:19 +00:00
parent 96f499ff44
commit 44f83e03ea
No known key found for this signature in database
GPG key ID: 6FE9E7996B0B082E
2 changed files with 19 additions and 14 deletions

18
cmd.go
View file

@ -521,7 +521,7 @@ func complete() error {
return err
}
// PassToPacman outsorces execution to pacman binary without modifications.
// passToPacman outsorces execution to pacman binary without modifications.
func passToPacman(parser *arguments) error {
var cmd *exec.Cmd
args := make([]string, 0)
@ -541,3 +541,19 @@ func passToPacman(parser *arguments) error {
err := cmd.Run()
return err
}
// passToMakepkg outsorces execution to makepkg binary without modifications.
func passToMakepkg(dir string, args ...string) (err error) {
cmd := exec.Command(config.MakepkgBin, args...)
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
cmd.Dir = dir
err = cmd.Run()
if err == nil {
_ = saveVCSInfo()
if config.CleanAfter {
fmt.Println("\x1b[1;32m==> CleanAfter enabled. Deleting source folder.\x1b[0m")
os.RemoveAll(dir)
}
}
return
}

View file

@ -162,18 +162,7 @@ func PkgInstall(a *rpc.Pkg, flags []string) (finalmdeps []string, err error) {
}
}
args := []string{"-sri"}
args = append(args, flags...)
makepkgcmd := exec.Command(config.MakepkgBin, args...)
makepkgcmd.Stdin, makepkgcmd.Stdout, makepkgcmd.Stderr = os.Stdin, os.Stdout, os.Stderr
makepkgcmd.Dir = dir
err = makepkgcmd.Run()
if err == nil {
_ = saveVCSInfo()
if config.CleanAfter {
fmt.Println("\x1b[1;32m==> CleanAfter enabled. Deleting source folder.\x1b[0m")
os.RemoveAll(dir)
}
}
flags = append(flags, "-sri")
err = passToMakepkg(dir, flags...)
return
}