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
+15.2k Golang : Save(pipe) HTTP response into a file
+34.6k Golang : How to stream file to client(browser) or write to http.ResponseWriter?
+19.2k Golang : Populate dropdown with html/template example
+25.7k Golang : missing Mercurial command
+5.6k Golang : Shortening import identifier
+47.8k Golang : Convert int to byte array([]byte)
+13k Golang : Calculate elapsed years or months since a date
+7.9k Golang : Get today's weekday name and calculate target day distance example
+15.8k Golang : Get digits from integer before and after given position example
+10.2k Golang : Find and replace data in all files recursively
+15.2k Golang : Get timezone offset from date or timestamp
+4.9k HTTP common errors and their meaning explained