Standard library / flag
flag.FlagSet.Args()
Returns remaining arguments after parsing stops at the first positional argument or --. Run with arguments: ["file", "-x"]. Expected stdout: '[file -x]\n'.
Formal Syntax & Structure
go syntaxgo
func (f *FlagSet) Args() []stringReturn Value
[]string
Returns remaining arguments after parsing stops at the first positional argument or --.
Working Example
Example Snippetgo
package main
import ( "flag" "fmt" "os")
func check(e error) { if e != nil { panic(e) }}
func main() { f := flag.NewFlagSet("demo", flag.ContinueOnError) v := f.Int("x", 0, "value") _ = v check(f.Parse(os.Args[1:])) fmt.Println(f.Args())}