Add generated help and version commands

This commit is contained in:
2026-10-07 13:37:57 +00:00
parent c3448a2ebe
commit ecd2b19783
13 changed files with 736 additions and 27 deletions

58
builtins_test.go Normal file
View File

@@ -0,0 +1,58 @@
package commandkit
import (
"runtime/debug"
"testing"
)
func TestCommandKitBuildIdentityProjectsEffectiveModuleVersion(t *testing.T) {
tests := []struct {
name string
info *debug.BuildInfo
want string
}{
{
name: "main module tag",
info: &debug.BuildInfo{Main: debug.Module{Path: commandKitModulePath, Version: "v1.2.3"}},
want: "v1.2.3",
},
{
name: "dependency tag",
info: &debug.BuildInfo{Main: debug.Module{Path: "example.com/application", Version: "v4.0.0"}, Deps: []*debug.Module{{Path: commandKitModulePath, Version: "v1.2.3"}}},
want: "v1.2.3",
},
{
name: "versioned replacement",
info: &debug.BuildInfo{Main: debug.Module{Path: "example.com/application"}, Deps: []*debug.Module{{Path: commandKitModulePath, Version: "v1.2.3", Replace: &debug.Module{Path: "example.com/fork", Version: "v2.0.0"}}}},
want: "v2.0.0",
},
{
name: "local replacement",
info: &debug.BuildInfo{Main: debug.Module{Path: commandKitModulePath, Version: "v1.2.3", Replace: &debug.Module{Path: "../CommandKit"}}},
want: "dev",
},
{
name: "development module",
info: &debug.BuildInfo{Main: debug.Module{Path: commandKitModulePath, Version: "(devel)"}},
want: "dev",
},
{
name: "missing module",
info: &debug.BuildInfo{Main: debug.Module{Path: "example.com/application"}},
want: "dev",
},
{
name: "missing build info",
info: nil,
want: "dev",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
identity := commandKitBuildIdentity(test.info)
if identity.Name != "CommandKit" || identity.Version != test.want || identity.Revision != "" {
t.Fatalf("identity = %#v, want CommandKit %q with no revision", identity, test.want)
}
})
}
}