Beispiel
Parsing flags with NoOptDefVal assigns the no-option default and preserves subsequent space-separated arguments as positional parameters unless explicit equals delimiter syntax is used
sha256:cc2c397664e089bf5638765dcfb834232cd669f9970283902c9b8947b773b043
PUBLISHED
L3_CONTRACT_PASS
MIT-0
Fall
- Ziel
- Parsing flags with NoOptDefVal assigns the no-option default and preserves subsequent space-separated arguments as positional parameters unless explicit equals delimiter syntax is used HOW
- Pakete
- github.com/spf13/pflag 1.0.10
- Umgebung
- go
- Erstellt
- 2026-08-16T12:28:14Z
Häufige Annahme
a flag with NoOptDefVal set binds a subsequent space-separated argument as its value during command-line parsing
So hat der Autor des Samples festgehalten, was eine Entwicklerin oder ein Modell hier erwarten würde. Der Vertrag darunter ist das, was tatsächlich lief.
Contract
- fs.Parse([]string{"--format", "yaml", "pos1"}) sets format to "json" from NoOptDefVal and preserves "yaml" and "pos1" in fs.Args()
- fs.Parse([]string{"--format=yaml", "pos1"}) sets format to "yaml" and leaves only "pos1" in fs.Args()
- fs.Parse([]string{"-f", "yaml", "pos1"}) sets format to "json" and preserves "yaml" and "pos1" in fs.Args()
- fs.Parse([]string{"-f=yaml", "pos1"}) sets format to "yaml" and leaves only "pos1" in fs.Args()
- fs.Parse([]string{"pos1"}) retains base default value "text" and leaves format marked false in fs.Changed()
- fs.Parse([]string{"--format"}) sets format to "json" and marks format as true in fs.Changed()
Dateien
- NOTES.md
- csx.json
- go.mod
- go.sum
- pflag_test.go
Verifiziertes Artefakt herunterladen (tar.gz) — genau die Bytes, gegen die der Contract lief
Ursprungs-Seeder
Verifizierungsbelege
- go 1.26 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · golang@1 · 2026-08-16 · ed25519:d91480838ac982c9