mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-11-17 18:06:15 -05:00
faee88163c
Co-authored-by: loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
53 lines
1.0 KiB
Go
53 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/common/log"
|
|
_ "github.com/v2fly/v2ray-core/v4/infra/conf/geodata/memconservative"
|
|
_ "github.com/v2fly/v2ray-core/v4/infra/conf/geodata/standard"
|
|
"github.com/v2fly/v2ray-core/v4/infra/control"
|
|
)
|
|
|
|
func getCommandName() string {
|
|
if len(os.Args) > 1 {
|
|
return os.Args[1]
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func main() {
|
|
// let the v2ctl prints log at stderr
|
|
log.RegisterHandler(log.NewLogger(log.CreateStderrLogWriter()))
|
|
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)
|
|
}
|
|
}
|
|
}
|