Golang flag.FlagSet.Args() function example
package flag
Args returns the non-flag arguments.
Golang flag.FlagSet.Args() function usage example
package main
import (
"flag"
"fmt"
"os"
)
func main() {
flags := flag.NewFlagSet("", flag.ContinueOnError)
cmd := "help"
var cmdArgs []string
if err := flags.Parse(os.Args[1:]); err == nil && flags.NArg() != 0 {
cmd = flags.Arg(0)
cmdArgs = flags.Args()[1:] // <-- here
if cmd == "help" && flags.NArg() == 2 {
cmd = flags.Arg(1)
cmdArgs = []string{"--help"}
}
}
fmt.Println(cmdArgs)
}
Reference :
Advertisement
Something interesting
Tutorials
+22.7k Golang : Set and Get HTTP request headers example
+18k Golang : Get all upper case or lower case characters from string example
+62.7k Golang : Convert HTTP Response body to string
+7.5k Golang : Rot13 and Rot5 algorithms example
+5.4k Golang : Intercept, inject and replay HTTP traffics from web server
+11.2k Google Maps URL parameters configuration
+32.1k Golang : Validate email address with regular expression
+13.6k Golang : Get user input until a command or receive a word to stop
+10.7k Golang : Get currencies exchange rates example
+10.7k Golang : Underscore string example
+9.8k Golang : Resumable upload to Google Drive(RESTful) example
+5.6k Fix fatal error: evacuation not done in time problem