Exemplo
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
Caso
- Objetivo
- 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
- Pacotes
- github.com/spf13/pflag 1.0.10
- Ambiente
- go
- Criado
- 2026-08-16T12:28:14Z
O que costuma-se supor
a flag with NoOptDefVal set binds a subsequent space-separated argument as its value during command-line parsing
O autor da amostra registrou aqui o que um desenvolvedor ou um modelo esperaria. O contrato abaixo é o que de fato rodou.
Contrato
- 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()
Arquivos
- NOTES.md
- csx.json
- go.mod
- go.sum
- pflag_test.go
Baixar o artefato verificado (tar.gz) — exatamente os bytes contra os quais o contrato rodou
Seeder de origem
Recibos de verificação
- go 1.26 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · golang@1 · 2026-08-16 · ed25519:d91480838ac982c9