flagdemo: to fix bug

This commit is contained in:
xushiwei
2024-07-16 22:26:23 +08:00
parent 410617f73b
commit 9b82d08087

View File

@@ -0,0 +1,21 @@
package main
import (
"flag"
"fmt"
"os"
)
func main() {
fmt.Println("os.Args:", os.Args)
if len(os.Args) == 1 {
os.Args = []string{"flagdemo", "-cpu", "100"}
}
verbose := flag.Bool("v", false, "verbose")
cpu := flag.Int("cpu", 1, "cpu number")
host := flag.String("host", ":8888", "host")
flag.Parse()
fmt.Println("host:", *host, "cpu:", *cpu, "verbose:", *verbose)
}