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 :
Advertisement
Something interesting
Tutorials
+7.7k Golang : Command line ticker to show work in progress
+11.6k Get form post value in Go
+25.3k Golang : Convert uint value to string type
+7.3k Golang : Not able to grep log.Println() output
+9.4k Golang : Timeout example
+14.5k Golang : Overwrite previous output with count down timer
+17.6k Golang : Parse date string and convert to dd-mm-yyyy format
+9.5k Golang : Extract or copy items from map based on value
+19.9k Golang : Count JSON objects and convert to slice/array
+6.5k PHP : Shuffle to display different content or advertisement
+7.2k Golang : Null and nil value
+13.3k Golang : Date and Time formatting