サンプル
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