-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
42 lines (34 loc) · 921 Bytes
/
main.go
File metadata and controls
42 lines (34 loc) · 921 Bytes
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
package main
import (
"context"
"log"
"os"
"os/signal"
"path/filepath"
"syscall"
"github.com/jxsl13/twlog/cmd/what"
"github.com/jxsl13/twlog/cmd/who"
"github.com/jxsl13/twlog/internal/sharedcontext"
"github.com/spf13/cobra"
)
func main() {
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer cancel()
cmd := NewRootCmd(ctx)
if err := cmd.Execute(); err != nil {
log.Fatal(err)
}
}
func NewRootCmd(ctx context.Context) *cobra.Command {
root := sharedcontext.NewRoot(ctx)
cmd := cobra.Command{
Use: filepath.Base(os.Args[0]),
Short: "twlog is a utility for analyzing Teeworlds server logs",
}
cmd.PersistentPreRunE = root.PersistentPreRunE(&cmd)
cmd.PersistentPostRunE = root.PersistentPostRunE(&cmd)
cmd.AddCommand(NewCompletionCommand(&cmd))
cmd.AddCommand(who.NewWhoCommand(root))
cmd.AddCommand(what.NewWhatCommand(root))
return &cmd
}