-
-
Notifications
You must be signed in to change notification settings - Fork 415
/
main.go
36 lines (29 loc) · 722 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
package main
import (
"context"
"os"
"os/signal"
surveyterm "github.com/AlecAivazis/survey/v2/terminal"
"github.com/fatih/color"
"github.com/go-faster/errors"
"go.etcd.io/bbolt"
"github.com/iyear/tdl/cmd"
)
func main() {
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
humanizeErrors := map[error]string{
bbolt.ErrTimeout: "Current database is used by another process, please terminate it first",
surveyterm.InterruptErr: "Interrupted",
}
if err := cmd.New().ExecuteContext(ctx); err != nil {
for e, m := range humanizeErrors {
if errors.Is(err, e) {
color.Red("%s", m)
os.Exit(1)
}
}
color.Red("Error: %+v", err)
os.Exit(1)
}
}