Golang flag.NFlag() function example

package flag

NFlag returns the number of command-line flags that have been set.

Golang flag.NFlag() function usage example

 ...
 func main() {
 flag.Parse()

 if flag.NFlag() == 0 {
 fmt.Println("Usage : thisprogramname filename")
 os.Exit(1)
 }
 ...

Reference :

http://golang.org/pkg/flag/#NFlag

  See also : Golang flag.NArg() function example

Advertisement