1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 18:17:52 -05:00
v2fly/infra/control/main/main.go

52 lines
944 B
Go
Raw Normal View History

2019-02-10 13:04:11 -05:00
package main
import (
"flag"
"fmt"
"os"
2020-01-02 20:26:48 -05:00
commlog "v2ray.com/core/common/log"
// _ "v2ray.com/core/infra/conf/command"
2019-02-10 13:04:11 -05:00
"v2ray.com/core/infra/control"
)
func getCommandName() string {
if len(os.Args) > 1 {
return os.Args[1]
}
return ""
}
func main() {
2020-01-02 20:26:48 -05:00
// let the v2ctl prints log at stderr
commlog.RegisterHandler(commlog.NewLogger(commlog.CreateStderrLogWriter()))
2019-02-10 13:04:11 -05:00
name := getCommandName()
cmd := control.GetCommand(name)
if cmd == nil {
fmt.Fprintln(os.Stderr, "Unknown command:", name)
fmt.Fprintln(os.Stderr)
fmt.Println("v2ctl <command>")
fmt.Println("Available commands:")
control.PrintUsage()
return
}
if err := cmd.Execute(os.Args[2:]); err != nil {
hasError := false
if err != flag.ErrHelp {
fmt.Fprintln(os.Stderr, err.Error())
fmt.Fprintln(os.Stderr)
hasError = true
}
for _, line := range cmd.Description().Usage {
fmt.Println(line)
}
if hasError {
os.Exit(-1)
}
}
}