-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.go
41 lines (35 loc) · 883 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
40
41
package cli
import (
"context"
"errors"
"fmt"
"log"
"os"
"os/signal"
"strings"
"syscall"
"time"
"github.com/logrusorgru/aurora"
"github.com/modernice/goes/cli/internal/clifactory"
)
// Main is the entrypoint for the CLI. Call Main from an actual main function.
func Main() {
log.SetFlags(0)
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
app := New(clifactory.Context(ctx), clifactory.ConnectTimeout(time.Second))
err := app.Run()
if err != nil {
if errors.Is(err, clifactory.ErrConnectorUnavailable) {
addr := app.Factory().ConnectorAddress
if strings.HasPrefix(addr, ":") {
addr = fmt.Sprintf("localhost%s", addr)
}
log.Fatalf(
aurora.Red("Unable to connect to your application. Did you setup the CLI Connector at %s?").String(),
addr,
)
}
log.Fatal(aurora.Red(err))
}
}