github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/infra/control/main/main.go (about) 1 package main 2 3 import ( 4 "flag" 5 "fmt" 6 "os" 7 8 commlog "v2ray.com/core/common/log" 9 // _ "v2ray.com/core/infra/conf/command" 10 "v2ray.com/core/infra/control" 11 ) 12 13 func getCommandName() string { 14 if len(os.Args) > 1 { 15 return os.Args[1] 16 } 17 return "" 18 } 19 20 func main() { 21 // let the v2ctl prints log at stderr 22 commlog.RegisterHandler(commlog.NewLogger(commlog.CreateStderrLogWriter())) 23 name := getCommandName() 24 cmd := control.GetCommand(name) 25 if cmd == nil { 26 fmt.Fprintln(os.Stderr, "Unknown command:", name) 27 fmt.Fprintln(os.Stderr) 28 29 fmt.Println("v2ctl <command>") 30 fmt.Println("Available commands:") 31 control.PrintUsage() 32 return 33 } 34 35 if err := cmd.Execute(os.Args[2:]); err != nil { 36 hasError := false 37 if err != flag.ErrHelp { 38 fmt.Fprintln(os.Stderr, err.Error()) 39 fmt.Fprintln(os.Stderr) 40 hasError = true 41 } 42 43 for _, line := range cmd.Description().Usage { 44 fmt.Println(line) 45 } 46 47 if hasError { 48 os.Exit(-1) 49 } 50 } 51 }