示例
github.com/urfave/cli v1.22.14: Command
已验证示例 — golang github.com/urfave/cli v1.22.14: Command. contract 在 go 1.26 · linux debian/x64 · docker 上运行并通过: cli.Command matches by Name and Aliases with…
sha256:9154b99ac1c7482ef8864137f3558e2879c80dd18b82b522768c63af6f3e363e
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
go 1.26 linux 24 · ubuntu · glibc 2.39 amd64 go 1.26 go 1.26 go 1
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a… |
2026-09-03 |
案例
HOW- 目标
- verify github.com/urfave/cli.Command in pkg:golang/github.com/urfave/cli@v1.22.14
- 符号
-
- github.com/urfave/cli.Command
- 环境
- go 1.26.6
- 创建时间
- 2026-09-03T07:33:45Z
契约
- cli.Command matches by Name and Aliases with HasName and Names
- cli.Command executes Action with parsed command-specific Flags
- cli.Command routes execution to nested Subcommands
- cli.Command executes Before and After lifecycle hooks in order
文件
- PROMPT.md
- csx.json
- go.mod
- go.sum
- spec.json
- test/contract_test.go
源代码
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/urfave/cli.Command in pkg:golang/github.com/urfave/cli@v1.22.14
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/urfave/cli@v1.22.14
Demonstrate these symbols/APIs:
- github.com/urfave/cli.Command
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.
{"case":{"caseId":"case:sha256:556a78d5ec3d13cbddf32c70a39be2cb3b40ad37a0020e3091d4339f2fecc134","contract":["cli.Command matches by Name and Aliases with HasName and Names","cli.Command executes Action with parsed command-specific Flags","cli.Command routes execution to nested Subcommands","cli.Command executes Before and After lifecycle hooks in order"],"goal":"verify github.com/urfave/cli.Command in pkg:golang/github.com/urfave/cli@v1.22.14","kind":"HOW","packages":["pkg:golang/github.com/urfave/cli@v1.22.14"],"schemaVersion":1,"symbols":["github.com/urfave/cli.Command"]},"contractCommand":["go","test","./..."],"environment":{"arch":"amd64","distro":"ubuntu","ecosystem":"golang","language":"go","languageVersion":"1.26.6","libc":"glibc","libcVersion":"2.39","moduleSystem":"go-mod","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/urfave/cli@v1.22.14"],"schemaVersion":1,"subject":"pkg:golang/github.com/urfave/cli@v1.22.14","symbols":["github.com/urfave/cli.Command"],"verifierAdapter":"golang@1"}
module urfave-cli-command
go 1.26.6
require github.com/urfave/cli v1.22.14
require (
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
)
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo=
github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/urfave/cli v1.22.14 h1:ebbhrRiGK2i4naQJr+1Xj92HXZCrK7MsyTS/ob3HnAk=
github.com/urfave/cli v1.22.14/go.mod h1:X0eDS6pD6Exaclxm99NJ3FiCDRED7vIHpx2mDOHLvkA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
{
"schemaVersion": 1,
"goal": "verify github.com/urfave/cli.Command in pkg:golang/github.com/urfave/cli@v1.22.14",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/urfave/cli@v1.22.14"
],
"symbols": [
"github.com/urfave/cli.Command"
]
}
package contract_test
import (
"errors"
"reflect"
"testing"
"github.com/urfave/cli"
)
func TestContract_CommandNameAndAliases(t *testing.T) {
cmd := cli.Command{
Name: "deploy",
Aliases: []string{"d", "dep"},
Usage: "deploy the service",
}
names := cmd.Names()
expectedNames := []string{"deploy", "d", "dep"}
if !reflect.DeepEqual(names, expectedNames) {
t.Fatalf("expected names %v, got %v", expectedNames, names)
}
if !cmd.HasName("deploy") {
t.Fatal("expected cmd.HasName('deploy') to be true")
}
if !cmd.HasName("d") {
t.Fatal("expected cmd.HasName('d') to be true for alias")
}
if !cmd.HasName("dep") {
t.Fatal("expected cmd.HasName('dep') to be true for alias")
}
if cmd.HasName("unknown") {
t.Fatal("expected cmd.HasName('unknown') to be false")
}
var executedWithAlias bool
app := cli.NewApp()
app.Commands = []cli.Command{
{
Name: "deploy",
Aliases: []string{"d"},
Action: func(c *cli.Context) error {
executedWithAlias = true
return nil
},
},
}
if err := app.Run([]string{"app", "d"}); err != nil {
t.Fatalf("unexpected error running alias: %v", err)
}
if !executedWithAlias {
t.Fatal("expected command action to execute when invoked via alias")
}
}
func TestContract_CommandFlagsAndAction(t *testing.T) {
var capturedEnv string
var capturedReplicas int
var capturedDryRun bool
var capturedArgs []string
cmd := cli.Command{
Name: "scale",
Usage: "scale service replicas",
Flags: []cli.Flag{
cli.StringFlag{
Name: "environment, e",
Value: "production",
Usage: "target deployment environment",
},
cli.IntFlag{
Name: "replicas, r",
Value: 1,
Usage: "number of replicas",
},
cli.BoolFlag{
Name: "dry-run",
Usage: "perform trial run without changes",
},
},
Action: func(c *cli.Context) error {
capturedEnv = c.String("environment")
capturedReplicas = c.Int("replicas")
capturedDryRun = c.Bool("dry-run")
capturedArgs = c.Args()
return nil
},
}
app := cli.NewApp()
app.Commands = []cli.Command{cmd}
args := []string{"app", "scale", "--environment", "staging", "-r", "5", "--dry-run", "worker-pool"}
if err := app.Run(args); err != nil {
t.Fatalf("unexpected error: %v", err)
}
if capturedEnv != "staging" {
t.Fatalf("expected environment 'staging', got %q", capturedEnv)
}
if capturedReplicas != 5 {
t.Fatalf("expected replicas 5, got %d", capturedReplicas)
}
if !capturedDryRun {
t.Fatal("expected dry-run to be true")
}
if len(capturedArgs) != 1 || capturedArgs[0] != "worker-pool" {
t.Fatalf("expected args ['worker-pool'], got %v", capturedArgs)
}
}
func TestContract_CommandSubcommands(t *testing.T) {
var capturedTarget string
var subCmdExecuted bool
app := cli.NewApp()
app.Commands = []cli.Command{
{
Name: "cluster",
Usage: "manage computing clusters",
Subcommands: []cli.Command{
{
Name: "create",
Usage: "provision a new cluster",
Action: func(c *cli.Context) error {
subCmdExecuted = true
capturedTarget = c.Args().First()
return nil
},
},
},
},
}
args := []string{"app", "cluster", "create", "prod-us-east"}
if err := app.Run(args); err != nil {
t.Fatalf("failed running subcommand: %v", err)
}
if !subCmdExecuted {
t.Fatal("expected subcommand action to execute")
}
if capturedTarget != "prod-us-east" {
t.Fatalf("expected target 'prod-us-east', got %q", capturedTarget)
}
}
func TestContract_CommandLifecycleHooks(t *testing.T) {
var executionOrder []string
cmd := cli.Command{
Name: "task",
Before: func(c *cli.Context) error {
executionOrder = append(executionOrder, "before")
return nil
},
Action: func(c *cli.Context) error {
executionOrder = append(executionOrder, "action")
return nil
},
After: func(c *cli.Context) error {
executionOrder = append(executionOrder, "after")
return nil
},
}
app := cli.NewApp()
app.Commands = []cli.Command{cmd}
if err := app.Run([]string{"app", "task"}); err != nil {
t.Fatalf("unexpected error: %v", err)
}
expectedOrder := []string{"before", "action", "after"}
if !reflect.DeepEqual(executionOrder, expectedOrder) {
t.Fatalf("expected execution order %v, got %v", expectedOrder, executionOrder)
}
var actionRunOnBeforeError bool
abortCmd := cli.Command{
Name: "failing-task",
Before: func(c *cli.Context) error {
return errors.New("before hook validation failure")
},
Action: func(c *cli.Context) error {
actionRunOnBeforeError = true
return nil
},
}
appAbort := cli.NewApp()
appAbort.Commands = []cli.Command{abortCmd}
err := appAbort.Run([]string{"app", "failing-task"})
if err == nil {
t.Fatal("expected error from app.Run when Before hook fails")
}
if actionRunOnBeforeError {
t.Fatal("expected Action not to run when Before hook returns an error")
}
}
原始种子者
匿名