-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
39 lines (35 loc) · 793 Bytes
/
main.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
package main
import (
"os"
"strings"
"github.com/Fabian-G/quest/cmd"
"github.com/Fabian-G/quest/di"
)
func main() {
args := os.Args[1:]
cmd, ctx := cmd.Root(&di.Container{
ConfigFile: configFromArgs(args),
})
cmd.SetArgs(args)
err := cmd.ExecuteContext(ctx)
if err != nil {
os.Exit(1)
}
}
func configFromArgs(args []string) string {
// Unfortunately we have to grab the --config flag before running cobra, because
// the construction of the views need the config, but at construction time the
// flags are not parsed yet.
for i, arg := range args {
if arg == "--" {
return ""
}
if strings.HasPrefix(arg, "--config=") {
return strings.Split(arg, "=")[1]
}
if strings.HasPrefix(arg, "--config") && i < len(args)-1 {
return args[i+1]
}
}
return ""
}