直接上代码
package main
import (
"flag"
"fmt"
)
func main() {
// Define a bool flag
boolArg := flag.Bool("sync", false, "This is a bool argument")
stringArg := flag.String("des", "this is a string", "This is a bool argument")
// Parse flag
flag.Parse()
fmt.Println("Bool Arg:", *boolArg)
fmt.Println("String Arg:", *stringArg)
}
运行代码
go run main.go -sync -des="this is des"
说明
- bool类型参数-sync=true 可以简写为-sync
- string类型-dest 字符串有空格时需要双引号