-
Notifications
You must be signed in to change notification settings - Fork 1
/
firefox.go
45 lines (42 loc) · 1.09 KB
/
firefox.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
package main
import (
"log"
"os"
"strings"
flag "github.com/spf13/pflag"
)
func CleanupArgs() (args []string, trailers []string) {
// get a list of all possible flags from the flag package
args = []string{os.Args[0]}
for i, arg := range os.Args[1:] {
log.Printf("arg %d: %s", i, arg)
trailer := true
trimmed := strings.Split(strings.TrimLeft(arg, "-"), "=")[0]
flag.VisitAll(func(f *flag.Flag) {
//log.Printf("testing f.Name: %s against %s", f.Name, trimmed)
if f.Name == trimmed {
log.Printf("found known flag: %s", f.Name)
// if the next arg is not a flag(does not start with '-'), add it to the end of arg before
// appending arg to args
if i+1 < len(os.Args) && os.Args[i+1][0] != '-' {
args = append(args, arg+"="+os.Args[i+1])
i++
trailer = false
} else {
args = append(args, arg)
trailer = false
}
return
}
})
if trailer {
if arg != "--profile" && arg != "-P" && arg != "-profile" {
log.Printf("found possible firefox flag: %s", trimmed)
trailers = append(trailers, arg)
} else {
i++
}
}
}
return
}