Move sudoloop code to exec.go

This commit is contained in:
morganamilo 2018-07-19 18:56:40 +01:00
parent 474cc56f8d
commit 257653047b
No known key found for this signature in database
GPG Key ID: 6FE9E7996B0B082E
2 changed files with 24 additions and 27 deletions

27
cmd.go
View File

@ -4,9 +4,7 @@ import (
"bufio"
"fmt"
"os"
"os/exec"
"strconv"
"time"
)
var cmdArgs = makeArguments()
@ -118,31 +116,6 @@ If no arguments are provided 'yay -Syu' will be performed
If no operation is provided -Y will be assumed`)
}
func sudoLoopBackground() {
updateSudo()
go sudoLoop()
}
func sudoLoop() {
for {
updateSudo()
time.Sleep(298 * time.Second)
}
}
func updateSudo() {
for {
cmd := exec.Command("sudo", "-v")
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
err := cmd.Run()
if err != nil {
fmt.Println(err)
} else {
break
}
}
}
func handleCmd() (err error) {
for option, value := range cmdArgs.options {
if handleConfig(option, value) {

24
exec.go
View File

@ -6,6 +6,7 @@ import (
"os"
"os/exec"
"strings"
"time"
)
func show(cmd *exec.Cmd) error {
@ -29,6 +30,29 @@ func capture(cmd *exec.Cmd) (string, string, error) {
return stdout, stderr, err
}
func sudoLoopBackground() {
updateSudo()
go sudoLoop()
}
func sudoLoop() {
for {
updateSudo()
time.Sleep(298 * time.Second)
}
}
func updateSudo() {
for {
err := show(exec.Command("sudo", "-v"))
if err != nil {
fmt.Println(err)
} else {
break
}
}
}
func passToPacman(args *arguments) *exec.Cmd {
argArr := make([]string, 0)