diff --git a/cmd/main.go b/cmd/main.go index b5bd0ea..8f0a07f 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "net/http" + "os" "strings" . "github.com/oneclickvirt/defaultset" @@ -16,19 +17,26 @@ func main() { http.Get("https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Foneclickvirt%2Fspeedtest&count_bg=%2323E01C&title_bg=%23555555&icon=sonarcloud.svg&icon_color=%23E7E7E7&title=hits&edge_flat=false") }() fmt.Println("项目地址:", Blue("https://github.com/oneclickvirt/speedtest")) - var showVersion, nearByServer, showHead bool + var showVersion, nearByServer, showHead, help bool var language, operator, platform, testMethod string var num int - flag.BoolVar(&showVersion, "v", false, "Show version information") - flag.BoolVar(&nearByServer, "nearby", false, "Test only nearby servers") - flag.BoolVar(&showHead, "s", true, "Show head") - flag.BoolVar(&model.EnableLoger, "e", false, "Enable logging") - flag.StringVar(&language, "l", "zh", "Language parameter (options: en, zh)") - flag.StringVar(&platform, "pf", "net", "Platform parameter (options: net, cn)") - flag.StringVar(&operator, "opt", "global", "Operator parameter (options: cmcc, cu, ct, sg, tw, jp, hk, global)") - flag.StringVar(&testMethod, "m", "speedtest", "Test Method parameter (options: origin, speedtest, speedtest-go)") - flag.IntVar(&num, "num", -1, "Number of test servers, default -1 not to limit") - flag.Parse() + speedtestFlag := flag.NewFlagSet("speedtest", flag.ContinueOnError) + speedtestFlag.BoolVar(&help, "h", false, "Show help information") + speedtestFlag.BoolVar(&showVersion, "v", false, "Show version information") + speedtestFlag.BoolVar(&nearByServer, "nearby", false, "Test only nearby servers") + speedtestFlag.BoolVar(&showHead, "s", true, "Show head") + speedtestFlag.BoolVar(&model.EnableLoger, "e", false, "Enable logging") + speedtestFlag.StringVar(&language, "l", "zh", "Language parameter (options: en, zh)") + speedtestFlag.StringVar(&platform, "pf", "net", "Platform parameter (options: net, cn)") + speedtestFlag.StringVar(&operator, "opt", "global", "Operator parameter (options: cmcc, cu, ct, sg, tw, jp, hk, global)") + speedtestFlag.StringVar(&testMethod, "m", "speedtest", "Test Method parameter (options: origin, speedtest, speedtest-go)") + speedtestFlag.IntVar(&num, "num", -1, "Number of test servers, default -1 not to limit") + speedtestFlag.Parse(os.Args[1:]) + if help { + fmt.Printf("Usage: %s [options]\n", os.Args[0]) + speedtestFlag.PrintDefaults() + return + } if showVersion { fmt.Println(model.SpeedTestVersion) return