Golang flag.Args() function examples

package flag

Args returns the non-flag command-line arguments.

Golang flag.Args() function usage examples

Example 1:

 func main() {
  flag.Parse()

  if len(flag.Args()) < 3 {
 fmt.Println("Usage: hello_world [-port portnumber] [-write] servername bucketname key")
  }
 }

Example 2:

 for _, name := range flag.Args() {
 // Is it a directory?
 fi, err := os.Stat(name)

 if err != nil {
 fmt.Printf("error walking tree: %s", err)
 continue
 }

 if fi.IsDir() {
 dirs = true
 } else {
 files = true
 }
 }

Reference :

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

Advertisement