-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
39 lines (31 loc) · 856 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
package main
import (
"context"
"flag"
"log/slog"
"os"
"os/signal"
"syscall"
"github.com/google/subcommands"
)
func main() {
subcommands.Register(subcommands.HelpCommand(), "")
subcommands.Register(subcommands.FlagsCommand(), "")
subcommands.Register(subcommands.CommandsCommand(), "")
subcommands.Register(new(versionCmd), "")
subcommands.Register(new(generateCmd), "")
subcommands.Register(new(createCmd), "")
subcommands.Register(new(migrateCmd), "")
flag.Parse()
// Listen for ctrl+c and kill signals
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go func() {
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
got := <-sig
slog.Info("Received signal, shutting down", slog.String("signal", got.String()))
cancel()
}()
os.Exit(int(subcommands.Execute(ctx)))
}