-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathmain.go
More file actions
42 lines (34 loc) · 911 Bytes
/
main.go
File metadata and controls
42 lines (34 loc) · 911 Bytes
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
package main
import (
"embed"
"os"
"github.com/cronitorio/cronitor-cli/cmd"
)
//go:embed web/static
var WebAssets embed.FS
func main() {
// Ensure that flags on `exec` commands are not parsed by Cobra
// Inject a `--` param
commandIndex := 0
argsEscaped := false
for idx, arg := range os.Args {
if arg == "exec" && commandIndex == 0 {
// The first "exec" we come across is the one we care about.
// After we find it we continue looking at the rest of the args but we have our commandIndex set
commandIndex = idx + 2
}
if arg == "help" && commandIndex == 0 {
break
}
if commandIndex > 0 && arg == "--" {
argsEscaped = true
}
}
if commandIndex > 0 && !argsEscaped && len(os.Args) > commandIndex+1 {
os.Args = append(os.Args, "")
copy(os.Args[commandIndex+1:], os.Args[commandIndex:])
os.Args[commandIndex] = "--"
}
cmd.SetWebAssets(WebAssets)
cmd.Execute()
}