This repository has been archived by the owner on Jul 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
evcli.go
104 lines (80 loc) · 1.84 KB
/
evcli.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"github.com/exograd/go-program"
)
var (
p *program.Program
app *App
buildId string
skipConfirmations bool
colorOutput bool
)
func main() {
// Command line
p = program.NewProgram("evcli", "client for the eventline service")
p.AddFlag("y", "yes", "skip all confirmations")
p.AddFlag("", "no-color", "do not use colors")
p.AddOption("", "project-id", "id", "",
"the identifier of the current project")
p.AddOption("p", "project-name", "name", "",
"the name of the current project")
addConfigCommands()
addUpdateCommand()
addProjectCommands()
addCommandCommands()
addPipelineCommands()
addScratchpadCommands()
addEventCommands()
p.AddCommand("version", "print the version of evcli and exit", cmdVersion)
p.ParseCommandLine()
// Config
skipConfirmations = p.IsOptionSet("yes")
config, err := LoadConfig()
if err != nil {
p.Fatal("cannot load configuration: %v", err)
}
colorOutput = config.Interface.Color && !p.IsOptionSet("no-color")
// Application
client, err := NewClient(config)
if err != nil {
p.Fatal("cannot create api client: %v", err)
}
optionValue := func(name string) *string {
if !p.IsOptionSet(name) {
return nil
}
value := p.OptionValue(name)
return &value
}
app, err = NewApp(config, client)
if err != nil {
p.Fatal("%v", err)
}
app.projectIdOption = optionValue("project-id")
app.projectNameOption = optionValue("project-name")
name := p.CommandName()
loadAPIKey := true
for _, cmdName := range noAPIKeyCommands() {
if name == cmdName {
loadAPIKey = false
break
}
}
if loadAPIKey {
app.LoadAPIKey()
}
if !config.Misc.DisableUpdateCheck && name != "update" {
app.LookForLastBuild()
}
p.Run()
}
func noAPIKeyCommands() []string {
return []string{
"get-config",
"help",
"set-config",
"show-config",
"update",
"version",
}
}