Standard library / flag

flag.FlagSet.NArg()

Counts remaining positional arguments. Run with arguments: ["a", "b"]. Expected stdout: '2\n'.

Formal Syntax & Structure

go syntaxgo
func (f *FlagSet) NArg() int

Return Value

int

Counts remaining positional arguments.

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.NArg())}
Go Reference