CodeSampleX

Sample

github.com/spf13/pflag v1.0.10: ContinueOnError

Verified sample for golang github.com/spf13/pflag v1.0.10: ContinueOnError. The contract ran on go 1.26 · linux alpine/x64 · docker and passed.

sha256:f42f27cbbdc82fbc7a5768c0ce558d2fb8540e2ac16b18f46eb7004484320da0

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment linux 24 · ubuntu · glibc 2.39 x64 go

Verification-run environments

Environment Contract Stages Run
go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-08-30

Case

HOW
Goal
verify github.com/spf13/pflag.ContinueOnError in pkg:golang/github.com/spf13/pflag@v1.0.10
Packages
Symbols
  • github.com/spf13/pflag.ContinueOnError
Created
2026-08-30T14:31:10Z

Contract

  1. NewFlagSet with ContinueOnError returns an error on unknown flag instead of exiting or panicking
  2. NewFlagSet with ContinueOnError returns ErrHelp when --help flag is parsed without custom help definition
  3. NewFlagSet with ContinueOnError returns an error on invalid flag value without exiting or panicking
  4. NewFlagSet with ContinueOnError parses valid flags successfully returning nil error

Files

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

Download the source artifact (tar.gz)

Source

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify github.com/spf13/pflag.ContinueOnError in pkg:golang/github.com/spf13/pflag@v1.0.10
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/spf13/pflag@v1.0.10
Demonstrate these symbols/APIs:
  - github.com/spf13/pflag.ContinueOnError

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:f4ecc9c6f07636a95d813d379e5d668c73162934c3380883a3d220359983b01b","contract":["NewFlagSet with ContinueOnError returns an error on unknown flag instead of exiting or panicking","NewFlagSet with ContinueOnError returns ErrHelp when --help flag is parsed without custom help definition","NewFlagSet with ContinueOnError returns an error on invalid flag value without exiting or panicking","NewFlagSet with ContinueOnError parses valid flags successfully returning nil error"],"goal":"verify github.com/spf13/pflag.ContinueOnError in pkg:golang/github.com/spf13/pflag@v1.0.10","kind":"HOW","packages":["pkg:golang/github.com/spf13/pflag@v1.0.10"],"schemaVersion":1,"symbols":["github.com/spf13/pflag.ContinueOnError"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/spf13/pflag@v1.0.10"],"schemaVersion":1,"subject":"pkg:golang/github.com/spf13/pflag@v1.0.10","symbols":["github.com/spf13/pflag.ContinueOnError"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.22

require github.com/spf13/pflag v1.0.10
go.sum
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
main.go
package main

import (
	"errors"
	"fmt"
	"os"

	"github.com/spf13/pflag"
)

func parseConfig(args []string) (string, int, error) {
	flags := pflag.NewFlagSet("app", pflag.ContinueOnError)
	name := flags.StringP("name", "n", "default", "User name")
	port := flags.IntP("port", "p", 8080, "Port number")

	if err := flags.Parse(args); err != nil {
		return "", 0, err
	}
	return *name, *port, nil
}

func main() {
	name, port, err := parseConfig(os.Args[1:])
	if err != nil {
		if errors.Is(err, pflag.ErrHelp) {
			os.Exit(0)
		}
		fmt.Fprintf(os.Stderr, "parse error: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("Config: name=%s, port=%d\n", name, port)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/spf13/pflag.ContinueOnError in pkg:golang/github.com/spf13/pflag@v1.0.10",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/spf13/pflag@v1.0.10"
  ],
  "symbols": [
    "github.com/spf13/pflag.ContinueOnError"
  ]
}
test/contract.go
package main

import (
	"errors"
	"fmt"
	"os"

	"github.com/spf13/pflag"
)

func main() {
	// 1. Unknown flag returns an error instead of exiting or panicking
	{
		flags := pflag.NewFlagSet("contract-unknown", pflag.ContinueOnError)
		flags.String("host", "localhost", "hostname")
		err := flags.Parse([]string{"--invalid-flag"})
		if err == nil {
			fmt.Fprintf(os.Stderr, "FAIL: expected error on unknown flag, got nil\n")
			os.Exit(1)
		}
	}

	// 2. Undefined help flag returns pflag.ErrHelp instead of exiting
	{
		flags := pflag.NewFlagSet("contract-help", pflag.ContinueOnError)
		flags.String("host", "localhost", "hostname")
		err := flags.Parse([]string{"--help"})
		if !errors.Is(err, pflag.ErrHelp) {
			fmt.Fprintf(os.Stderr, "FAIL: expected ErrHelp on --help, got %v\n", err)
			os.Exit(1)
		}
	}

	// 3. Invalid flag value returns error instead of exiting or panicking
	{
		flags := pflag.NewFlagSet("contract-invalid", pflag.ContinueOnError)
		flags.Int("port", 8080, "port number")
		err := flags.Parse([]string{"--port=not-an-int"})
		if err == nil {
			fmt.Fprintf(os.Stderr, "FAIL: expected error on invalid int flag value, got nil\n")
			os.Exit(1)
		}
	}

	// 4. Valid flags parse successfully and return nil error
	{
		flags := pflag.NewFlagSet("contract-valid", pflag.ContinueOnError)
		host := flags.String("host", "localhost", "hostname")
		port := flags.Int("port", 8080, "port number")
		verbose := flags.BoolP("verbose", "v", false, "verbose mode")

		err := flags.Parse([]string{"--host=example.com", "--port=9000", "-v"})
		if err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: expected nil error on valid flags, got %v\n", err)
			os.Exit(1)
		}
		if *host != "example.com" || *port != 9000 || !*verbose {
			fmt.Fprintf(os.Stderr, "FAIL: parsed flag values mismatch: host=%s, port=%d, verbose=%v\n", *host, *port, *verbose)
			os.Exit(1)
		}
	}

	fmt.Println("PASS: all contract assertions passed")
}

Origin Seeder

anonymous