forked from airbytehq/abctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
62 lines (51 loc) · 1.4 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
62
package main
import (
"context"
"errors"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"github.com/airbytehq/abctl/internal/build"
"github.com/airbytehq/abctl/internal/cmd"
"github.com/airbytehq/abctl/internal/update"
"github.com/pterm/pterm"
)
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// check for update
updateCtx, updateCancel := context.WithTimeout(ctx, 2*time.Second)
defer updateCancel()
updateChan := make(chan updateInfo)
go func() {
info := updateInfo{}
info.version, info.err = update.Check(updateCtx, http.DefaultClient, build.Version)
updateChan <- info
}()
// listen for shutdown signals
go func() {
signalCh := make(chan os.Signal, 1)
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)
<-signalCh
cancel()
}()
// ensure the pterm info width matches the other printers
pterm.Info.Prefix.Text = " INFO "
root := cmd.NewCmd()
cmd.Execute(ctx, root)
newRelease := <-updateChan
if newRelease.err != nil {
if errors.Is(newRelease.err, update.ErrDevVersion) {
pterm.DefaultLogger.Debug("Release checking is disabled for dev builds")
}
} else if newRelease.version != "" {
pterm.Println()
pterm.Info.Printfln("A new release of abctl is available: %s -> %s\nUpdating to the latest version is highly recommended", build.Version, newRelease.version)
}
}
type updateInfo struct {
version string
err error
}