-
Notifications
You must be signed in to change notification settings - Fork 4k
/
main.go
61 lines (54 loc) · 1.39 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"flag"
"os"
"github.com/xtls/xray-core/main/commands/base"
_ "github.com/xtls/xray-core/main/distro/all"
)
func main() {
os.Args = getArgsV4Compatible()
base.RootCommand.Long = "Xray is a platform for building proxies."
base.RootCommand.Commands = append(
[]*base.Command{
cmdRun,
cmdVersion,
},
base.RootCommand.Commands...,
)
base.Execute()
}
func getArgsV4Compatible() []string {
if len(os.Args) == 1 {
return []string{os.Args[0], "run"}
}
if os.Args[1][0] != '-' {
return os.Args
}
version := false
fs := flag.NewFlagSet("", flag.ContinueOnError)
fs.BoolVar(&version, "version", false, "")
// parse silently, no usage, no error output
fs.Usage = func() {}
fs.SetOutput(&null{})
err := fs.Parse(os.Args[1:])
if err == flag.ErrHelp {
// fmt.Println("DEPRECATED: -h, WILL BE REMOVED IN V5.")
// fmt.Println("PLEASE USE: xray help")
// fmt.Println()
return []string{os.Args[0], "help"}
}
if version {
// fmt.Println("DEPRECATED: -version, WILL BE REMOVED IN V5.")
// fmt.Println("PLEASE USE: xray version")
// fmt.Println()
return []string{os.Args[0], "version"}
}
// fmt.Println("COMPATIBLE MODE, DEPRECATED.")
// fmt.Println("PLEASE USE: xray run [arguments] INSTEAD.")
// fmt.Println()
return append([]string{os.Args[0], "run"}, os.Args[1:]...)
}
type null struct{}
func (n *null) Write(p []byte) (int, error) {
return len(p), nil
}