CodeSampleX

Exemplo

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

Amostra verificada para golang github.com/spf13/pflag v1.0.10: ContinueOnError. O contrato rodou em go 1.26 · linux alpine/x64 · docker e passou.

sha256:f42f27cbbdc82fbc7a5768c0ce558d2fb8540e2ac16b18f46eb7004484320da0

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado linux 24 · ubuntu · glibc 2.39 x64 go

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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

Caso

HOW
Objetivo
verify github.com/spf13/pflag.ContinueOnError in pkg:golang/github.com/spf13/pflag@v1.0.10
Pacotes
Símbolos
  • github.com/spf13/pflag.ContinueOnError
Criado
2026-08-30T14:31:10Z

Contrato

  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

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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")
}

Seeder de origem

anônimo