This repository was archived by the owner on Dec 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
71 lines (58 loc) · 1.38 KB
/
main.go
File metadata and controls
71 lines (58 loc) · 1.38 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package main
import (
"context"
"os"
"os/signal"
"sync"
"syscall"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
cmd "github.com/yp05327/teachart/cmd/teachart"
"github.com/yp05327/teachart/pkg/app"
"github.com/yp05327/teachart/pkg/options"
)
var Cancel context.CancelFunc
var CleanWaitGroup sync.WaitGroup
func main() {
var sig os.Signal
sigs := make(chan os.Signal, 1)
errChan := make(chan error, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
ctx := context.Background()
ctx, Cancel = context.WithCancel(ctx)
go func() {
// set logger formatter
logrus.SetFormatter(&logrus.TextFormatter{
DisableTimestamp: true,
DisableLevelTruncation: true,
})
// for execute all persistent pre-runs from the root parent till this command.
cobra.EnableTraverseRunHooks = true
globalOptions := options.NewGlobalOptions(app.DefaultRepoDir)
rootCmd, err := cmd.NewRootCmd(ctx, globalOptions)
if err != nil {
errChan <- err
return
}
errChan <- rootCmd.Execute()
}()
select {
case sig = <-sigs:
if sig != nil {
Cancel()
// See http://tldp.org/LDP/abs/html/exitcodes.html
switch sig {
case syscall.SIGINT:
os.Exit(130)
case syscall.SIGTERM:
os.Exit(143)
}
}
case err := <-errChan:
if err != nil {
logrus.Error(err)
}
}
}