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" "bufio"
"fmt" "fmt"
"os" "os"
"os/exec"
"strconv" "strconv"
"time"
) )
var cmdArgs = makeArguments() 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`) 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) { func handleCmd() (err error) {
for option, value := range cmdArgs.options { for option, value := range cmdArgs.options {
if handleConfig(option, value) { if handleConfig(option, value) {

24
exec.go
View file

@ -6,6 +6,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"strings" "strings"
"time"
) )
func show(cmd *exec.Cmd) error { func show(cmd *exec.Cmd) error {
@ -29,6 +30,29 @@ func capture(cmd *exec.Cmd) (string, string, error) {
return stdout, stderr, err 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 { func passToPacman(args *arguments) *exec.Cmd {
argArr := make([]string, 0) argArr := make([]string, 0)