You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-taskrem/run.go

43 lines
1001 B

2 years ago
package main
2 years ago
import (
"fmt"
"os"
"os/exec"
"github.com/gen2brain/beeep"
)
2 years ago
// Run will take the config file and for each task, run a go routine
func TaskRun(c Config) {
2 years ago
for i := range c.Tasks {
title := c.Tasks[i].TaskName
desc := c.Tasks[i].TaskDesc
err := beeep.Notify(title, desc, "")
if err != nil {
fmt.Fprintf(os.Stderr, "ERROR: could not display \"%s\":\n\t%s\n", title, err)
}
2 years ago
}
}
2 years ago
// TaskCMD will take the config struct and run all the "CMD" fields with "bash -c [command]" and return the output
func TaskCMD(c Config) (output string) {
for i := range c.Tasks {
command := c.Tasks[i].CMD
if command == " " {
fmt.Printf("INFO: Task %s has the cmd section empty. Will just return...\n", c.Tasks[i].TaskName)
return
}
out, err := exec.Command("bash", "-c", command).Output()
if err != nil {
fmt.Fprintf(os.Stderr, "ERROR: could not run command \"%s\":\n\t%s\n", command, err)
}
//fmt.Printf("Output:\n%s\n", out)
return string(out)
}
return
}