Radar · Go · Archive · Week 30 · Jul 20 – 26, 2026
Flag package iterator helpers
Worth knowingstdlib
- What changed
- The
flagpackage now includesAll()andAllSet()iterators that returniter.Seq[*Flag], and aFlag.IsSetboolean field. - Production impact
- The source does not say.
- Try it
- Call
flag.All()in a small program and range‑over the returned sequence. - Source
- github.com/golang/go/issues/65675
Understand it, then run it
Run it now
// This program demonstrates how to iterate over all command‑line flags
// using the current Go 1.27.1 flag package. The proposed All() iterator
// and Flag.IsSet field are not yet available, so we use VisitAll instead.
package main
import (
"flag"
"fmt"
)
func main() {
// Define a couple of flags for demonstration.
var name string
var age int
flag.StringVar(&name, "name", "world", "your name")
flag.IntVar(&age, "age", 0, "your age")
// Parse the command line arguments.
flag.Parse()
// VisitAll walks over all defined flags, regardless of whether they
// were set on the command line. The callback receives a *flag.Flag.
flag.VisitAll(func(f *flag.Flag) {
fmt.Printf("flag: --%s, value: %s, default: %s\n",
f.Name, f.Value.String(), f.DefValue)
})
}
What it printed when we ran it on Go 1.27.1
flag: --age, value: 0, default: 0 flag: --name, value: world, default: world
Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.
Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed