-
Notifications
You must be signed in to change notification settings - Fork 211
Expand file tree
/
Copy pathapp.go
More file actions
55 lines (45 loc) · 1.46 KB
/
app.go
File metadata and controls
55 lines (45 loc) · 1.46 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
package cli
import (
"fmt"
"os/signal"
"syscall"
"github.com/Ehco1996/ehco/internal/constant"
"github.com/Ehco1996/ehco/pkg/log"
cli "github.com/urfave/cli/v2"
)
var cliLogger = log.MustNewLogger("info").Sugar().Named("cli")
func startAction(ctx *cli.Context) error {
// No subcommand and no config source given -> the user almost certainly
// just typed `ehco` to see what it does. Show help instead of fataling
// with "invalid listen".
if ConfigPath == "" && LocalAddr == "" {
return cli.ShowAppHelp(ctx)
}
cfg, err := InitConfigAndComponents()
if err != nil {
cliLogger.Fatalf("InitConfigAndComponents meet err=%s", err.Error())
}
mainCtx, stop := signal.NotifyContext(ctx.Context, syscall.SIGINT, syscall.SIGTERM)
defer stop()
MustStartComponents(mainCtx, cfg)
<-mainCtx.Done()
cliLogger.Info("ehco exit now...")
return nil
}
func CreateCliAPP() *cli.App {
cli.VersionPrinter = func(c *cli.Context) {
println("Welcome to ehco (ehco is a network relay tool and a typo)")
println(fmt.Sprintf("Version=%s", constant.Version))
println(fmt.Sprintf("GitBranch=%s", constant.GitBranch))
println(fmt.Sprintf("GitRevision=%s", constant.GitRevision))
println(fmt.Sprintf("BuildTime=%s", constant.BuildTime))
}
app := cli.NewApp()
app.Name = "ehco"
app.Flags = RootFlags
app.Version = constant.Version
app.Commands = []*cli.Command{InstallCMD, UpdateCMD}
app.Usage = "ehco is a network relay tool and a typo :)"
app.Action = startAction
return app
}