Standard library / flag
flag.FlagSet.NFlag()
Counts distinct flags set, not the number of occurrences. Run with arguments: ["-x=1", "-x=2"]. Expected stdout: '1\n'.
Formal Syntax & Structure
go syntaxgo
func (f *FlagSet) NFlag() intReturn Value
int
Counts distinct flags set, not the number of occurrences.
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.NFlag())}