1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-06-01 18:31:08 +00:00
amfora/command/command.go
2021-12-10 22:39:18 -05:00

23 lines
607 B
Go

package command
import (
"os/exec"
"strings"
)
// RunCommand runs `command`, replacing the string "${url}" with `url`.
func RunCommand(command string, url string) (string, error) {
cmdWithURL := strings.ReplaceAll(command, "${url}", url)
cmdSplit := strings.SplitN(cmdWithURL, " ", 2)
if len(cmdSplit) > 1 {
if err := exec.Command(cmdSplit[0], cmdSplit[1]).Start(); err != nil {
return "", err
}
return "Ran command " + cmdSplit[0] + " with args " + cmdSplit[1], nil
}
if err := exec.Command(cmdWithURL).Start(); err != nil {
return "", err
}
return "Ran command " + cmdWithURL, nil
}