Add flag iterators
The flag package lets you walk flags only with Visit (set flags) and VisitAll (all flags). Both take callbacks that can't stop early, so they don't fit Go's range-over-func iterators.
The proposal adds a package-level All function and a FlagSet.All method. Both return an iter.Seq[*Flag] that yields flags in lexicographical order. Instead of a separate iterator for set flags, the Flag struct gets a new IsSet field that reports whether the flag was set on the command line.
for f := range flag.All() {
if f.IsSet {
fmt.Printf("%s = %s\n", f.Name, f.Value)
}
}
- Proposal
- #65675 by earthboundkid
- Status
- Implemented on Aug 24, 2026
- Release
- Go 1.28
- Impact
- medium
- Area
- flag