common-line flags _ golang

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 : ......

posted on 2015-03-31 13:30  xjk112  阅读(234)  评论(0编辑  收藏  举报