package main import ( "flag" "fmt" ) func main() { var ( nameFlag = flag.String("name", "Sam", "Name of the person to say hello to") quietFlag = flag.Bool("quiet", false, "Toggle to be quiet when saying hello") ) flag.Parse() if !*quietFlag { fmt.Printf("Hello, %s! Welcome to the command line.\n", *nameFlag) } }
zzh@ZZHPC:/zdata/Github/ztest$ go run main.go Hello, Sam! Welcome to the command line. zzh@ZZHPC:/zdata/Github/ztest$ go run main.go --name=Cassie Hello, Cassie! Welcome to the command line. zzh@ZZHPC:/zdata/Github/ztest$ go run main.go --name=Cassie --quiet=true zzh@ZZHPC:/zdata/Github/ztest$ go run main.go --help Usage of /tmp/go-build3614526501/b001/exe/main: -name string Name of the person to say hello to (default "Sam") -quiet Toggle to be quiet when saying hello
标签:ZZHPC,quiet,go,flag,zzh,Go,main From: https://www.cnblogs.com/zhangzhihui/p/18239939