tdl/main.go

37 lines
722 B
Go
Raw Normal View History

2022-09-01 15:16:59 +08:00
package main
import (
2023-03-29 18:20:23 +08:00
"context"
"os"
"os/signal"
2023-08-20 21:00:06 +08:00
2023-12-24 15:53:01 +08:00
surveyterm "github.com/AlecAivazis/survey/v2/terminal"
2023-08-20 21:00:06 +08:00
"github.com/fatih/color"
2023-12-24 15:53:01 +08:00
"github.com/go-faster/errors"
"go.etcd.io/bbolt"
2023-08-20 21:00:06 +08:00
"github.com/iyear/tdl/cmd"
)
2022-09-01 15:16:59 +08:00
func main() {
2023-03-29 18:20:23 +08:00
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
2023-12-24 15:53:01 +08:00
humanizeErrors := map[error]string{
bbolt.ErrTimeout: "Current database is used by another process, please terminate it first",
surveyterm.InterruptErr: "Interrupted",
}
2023-03-29 18:20:23 +08:00
if err := cmd.New().ExecuteContext(ctx); err != nil {
2023-12-24 15:53:01 +08:00
for e, m := range humanizeErrors {
if errors.Is(err, e) {
color.Red("%s", m)
os.Exit(1)
}
}
2023-12-04 16:31:21 +08:00
color.Red("Error: %+v", err)
2023-04-08 20:06:46 +08:00
os.Exit(1)
}
2022-09-01 15:16:59 +08:00
}