-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
main.go
61 lines (53 loc) · 1.07 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"context"
"log"
"os"
"os/signal"
"github.com/rsteube/carapace"
"github.com/zaquestion/lab/cmd"
"github.com/zaquestion/lab/internal/config"
lab "github.com/zaquestion/lab/internal/gitlab"
)
// version gets set on releases during build by goreleaser.
var version = "master"
func main() {
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
cmd.Version = version
initSkipped := skipInit()
if !initSkipped {
h, u, t, ca, skipVerify := config.LoadMainConfig()
if ca != "" {
if err := lab.InitWithCustomCA(ctx, h, u, t, ca); err != nil {
log.Fatal(err)
}
} else {
lab.Init(ctx, h, u, t, skipVerify)
}
}
cmd.Execute(initSkipped)
}
func skipInit() bool {
if carapace.IsCallback() {
return true
}
nArgs := len(os.Args)
if nArgs <= 1 {
return false
}
switch os.Args[nArgs-1] {
case "-h", "--help":
return true
}
switch os.Args[1] {
case "-v", "--version", "version":
return true
case "-h", "--help", "help":
return true
case "completion":
return true
default:
return false
}
}