-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.go
58 lines (55 loc) · 990 Bytes
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package papipes
import (
"errors"
"os/exec"
"strings"
)
func getModulesList() ([]string, error) {
cmd := exec.Command("pactl", "list", "short", "modules")
out, err := cmd.CombinedOutput()
if err != nil {
return nil, errors.New(string(out))
}
return strings.Split(string(out), "\n"), nil
}
func parseArguments(s string, quote rune) map[string]string {
res := make(map[string]string)
var key, value string
var inKey, inValue, inQuoute bool
inKey = true
for _, r := range s {
switch r {
case '=':
if inQuoute {
value += string(r)
} else {
inValue = true
inKey = false
}
case quote:
if inQuoute {
inQuoute = false
} else {
inQuoute = true
}
case ' ':
if inQuoute {
value += string(r)
} else {
inValue = false
inKey = true
res[key] = value
key = ""
value = ""
}
default:
if inKey {
key += string(r)
} else if inValue {
value += string(r)
}
}
}
res[key] = value
return res
}