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
+6.7k Golang : Skip or discard items of non-interest when iterating example
+7.1k Golang : Transform lisp or spinal case to Pascal case example
+7.8k Golang : Example of how to detect which type of script a word belongs to
+23.9k Golang : Use regular expression to validate domain name
+14k Golang : Google Drive API upload and rename example
+8.3k Golang : Check if integer is power of four example
+5.9k Unix/Linux : How to open tar.gz file ?
+14.8k Golang : Get URI segments by number and assign as variable example
+10.2k Golang : Bcrypting password
+18.4k Golang : Read binary file into memory
+17k Golang : Fix cannot convert buffer (type *bytes.Buffer) to type string error