Xray-core/main/main.go

62 lines
1.4 KiB
Go
Raw Permalink Normal View History

2020-11-25 13:01:53 +02:00
package main
import (
"flag"
"os"
2020-12-04 03:36:16 +02:00
"github.com/xtls/xray-core/main/commands/base"
_ "github.com/xtls/xray-core/main/distro/all"
2020-11-25 13:01:53 +02:00
)
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 {
2021-10-19 19:57:14 +03:00
// fmt.Println("DEPRECATED: -h, WILL BE REMOVED IN V5.")
// fmt.Println("PLEASE USE: xray help")
// fmt.Println()
2020-11-25 13:01:53 +02:00
return []string{os.Args[0], "help"}
}
if version {
2021-10-19 19:57:14 +03:00
// fmt.Println("DEPRECATED: -version, WILL BE REMOVED IN V5.")
// fmt.Println("PLEASE USE: xray version")
// fmt.Println()
2020-11-25 13:01:53 +02:00
return []string{os.Args[0], "version"}
}
2021-10-19 19:57:14 +03:00
// fmt.Println("COMPATIBLE MODE, DEPRECATED.")
// fmt.Println("PLEASE USE: xray run [arguments] INSTEAD.")
// fmt.Println()
2020-11-25 13:01:53 +02:00
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
}