Command-line flags are a common way to specify options for command-line programs. For eample, in wc -l the -l is a command-line flag
package main import ( "flag" "fmt" ) func main() { wordPtr := flag.String("word", "foo", "a string") numbPtr := flag.Int("numb", 42, "an int") boolPtr := flag.Bool("fork", false, "a bool") var svar string flag.StringVar(&svar, "svar", "bar", "a string var") flag.Parse() fmt.Println("word:", *wordPtr) fmt.Println("numb:", *numbPtr) fmt.Println("fork:", *boolPtr) fmt.Println("svar:", svar) fmt.Println("tail:", flag.Args()) }
word: opt numb: 7 fork: true svar: flag tail: []
总结 :
1 : ......
有疑问加站长微信联系(非本文作者)