-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathargs.go
73 lines (60 loc) · 1.14 KB
/
args.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"strings"
)
type Args struct {
Self string
GamescopeArgs []string
GameAndArgs []string
ClientSocket string
ShowDummyWindow bool
}
func ParseArgs(args []string) Args {
var result Args
if len(args) < 2 {
return result
}
result.Self = args[0]
args = args[1:]
if len(args) >= 3 && args[0] == "--client" {
result.ClientSocket = args[1]
i := 2
loop:
for i < len(args) {
switch args[i] {
case "--dummy-window":
result.ShowDummyWindow = true
i++
default:
break loop
}
}
result.GameAndArgs = args[i:]
return result
}
if strings.HasPrefix(args[0], "-") {
result.GamescopeArgs = args
for i := range args {
if args[i] == "--" {
if i+1 < len(args) {
result.GamescopeArgs = args[:i]
result.GameAndArgs = args[i+1:]
}
break
}
}
} else {
result.GameAndArgs = args
}
for i := 0; i < len(result.GamescopeArgs); {
switch result.GamescopeArgs[i] {
case "--dummy-window":
result.ShowDummyWindow = true
default:
i++
continue
}
result.GamescopeArgs = append(result.GamescopeArgs[:i], result.GamescopeArgs[i+1:]...)
}
return result
}