-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
89 lines (78 loc) · 2.38 KB
/
main.go
File metadata and controls
89 lines (78 loc) · 2.38 KB
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
package main
import (
"os"
"strings"
"time"
"github.com/airbytehq/airbyte-agent-cli/cmd"
"github.com/airbytehq/airbyte-agent-cli/internal/auth"
"github.com/airbytehq/airbyte-agent-cli/internal/client"
"github.com/airbytehq/airbyte-agent-cli/internal/config"
"github.com/airbytehq/airbyte-agent-cli/internal/registry"
"github.com/airbytehq/airbyte-agent-cli/internal/resources"
"github.com/airbytehq/airbyte-agent-cli/internal/telemetry"
"github.com/airbytehq/airbyte-agent-cli/internal/versioncheck"
)
func main() {
cfg := config.Load()
settings, _ := auth.ResolveSettings()
var c *client.Client
var t *telemetry.Tracker
if settings != nil {
creds := settings.Credentials
tm := auth.NewTokenManager(cfg.APIHost, settings.OrganizationID, &creds)
c = client.New(cfg.APIHost, settings.OrganizationID, cmd.Version, tm,
client.WithDebugFunc(cmd.GetVerbose),
client.WithDefaultWorkspace(settings.Workspace),
client.WithAllowDestructive(settings.AllowDestructive),
)
t = telemetry.New(
telemetry.ResolveMode(settings.TelemetryEnabled),
settings.OrganizationID,
cmd.Version,
settings.IsInternalUser,
)
}
// Version check runs even when settings are missing (e.g. before
// `login`) so a stale CLI still gets nudged on its very first
// command. Run is bounded internally by a 1s network timeout on the
// first-run sync fetch.
vcEnabled := versionCheckEnabled(settings)
vcIsTTY := versioncheck.IsTerminal(os.Stderr)
vcDone := versioncheck.Run(
cmd.Version,
vcEnabled,
vcIsTTY,
os.Stderr,
)
versioncheck.CheckSkill(
cmd.ExpectedSkillVersion,
vcEnabled,
vcIsTTY,
os.Stderr,
)
registry.SetTracker(t)
resources.RegisterAll()
registry.Build(cmd.GetRootCmd(), c, cmd.FlagAccessor())
err := cmd.Execute()
t.Flush()
if vcDone != nil {
select {
case <-vcDone:
case <-time.After(500 * time.Millisecond):
}
}
if err != nil {
os.Exit(1)
}
}
// versionCheckEnabled resolves whether the version-check nudge should
// run on this invocation. When settings exist, the file's value (with
// env override already applied) wins. When settings are missing, fall
// back to the env override directly so CI can suppress the nudge before
// `login` has ever run.
func versionCheckEnabled(s *auth.Settings) bool {
if s != nil {
return s.VersionCheckEnabled
}
return !strings.EqualFold(strings.TrimSpace(os.Getenv("AIRBYTE_VERSION_CHECK")), "disabled")
}