-
Notifications
You must be signed in to change notification settings - Fork 61
/
Txray.go
52 lines (46 loc) · 938 Bytes
/
Txray.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
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"Txray/cmd"
"Txray/core"
"Txray/core/setting"
"Txray/core/setting/key"
"Txray/log"
"os"
"path/filepath"
"github.com/abiosoft/ishell"
"github.com/spf13/viper"
)
const (
version = "v3.0.8"
name = "Txray"
)
func init() {
// 初始化日志
absPath := filepath.Join(core.GetConfigDir(), "info.log")
log.Init(
log.GetConsoleZapcore(log.INFO),
log.GetFileZapcore(absPath, log.INFO, 5),
)
}
func beforeOfRun(shell *ishell.Shell) {
cmd := viper.GetString(key.RunBefore)
if cmd != "" {
for _, line := range setting.NewAlias("", cmd).GetCmd() {
shell.Process(line...)
}
shell.Print("\n>>> ")
}
}
func main() {
shell := ishell.New()
cmd.InitShell(shell)
shell.Set("version", version)
shell.Set("name", name)
if len(os.Args) > 1 {
_ = shell.Process(os.Args[1:]...)
} else {
go beforeOfRun(shell)
shell.Printf("%s - Xray Shell Client - %s\n", name, version)
shell.Run()
}
}