示例
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
案例
- 目标
- 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
- 包
- github.com/spf13/pflag 1.0.10
- 环境
- go
- 创建时间
- 2026-08-16T12:28:14Z
常见的想当然
a flag with NoOptDefVal set binds a subsequent space-separated argument as its value during command-line parsing
这是本样本作者记下的、开发者或模型在此处通常会有的预期。下面的契约才是真正运行过的东西。
契约
- 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()
文件
- NOTES.md
- csx.json
- go.mod
- go.sum
- pflag_test.go
下载已验证的构件 (tar.gz) — 契约实际运行的那些字节
原始种子者
验证回执
- go 1.26 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · golang@1 · 2026-08-16 · ed25519:d91480838ac982c9