File: command.go

package info (click to toggle)
amfora 1.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,272 kB
  • sloc: python: 71; sh: 42; makefile: 39
file content (22 lines) | stat: -rw-r--r-- 607 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
}