Capture immutable command declarations

This commit is contained in:
2026-10-11 01:15:13 +00:00
parent 476e98a463
commit de9bfdcc4c
16 changed files with 368 additions and 474 deletions

View File

@@ -9,7 +9,6 @@ import (
"testing"
internalcobra "gitea.maximumdirect.net/eric/CommandKit/internal/cobra"
"gitea.maximumdirect.net/eric/promptkit"
)
func TestAppParseUsesRegisteredBindingsWithTheAdapter(t *testing.T) {
@@ -17,7 +16,7 @@ func TestAppParseUsesRegisteredBindingsWithTheAdapter(t *testing.T) {
scope Supplied[string]
id Supplied[string]
}
show, err := NewCommand(CommandSpec[input]{
show := NewCommand(CommandSpec[input]{
Name: "show",
Flags: []Flag[input]{ValueFlag(FlagMeta{Name: "scope"}, (*string)(nil), func(value string) (string, error) {
return value, nil
@@ -27,13 +26,8 @@ func TestAppParseUsesRegisteredBindingsWithTheAdapter(t *testing.T) {
}, func(value *input, supplied Supplied[string]) { value.id = supplied })},
Run: func(Invocation, input) Outcome { return Success() },
})
if err != nil {
t.Fatal(err)
}
config, err := Group("config", "configuration", show)
if err != nil {
t.Fatal(err)
}
config := Group("config", "configuration", show)
var err error
app, err := New(Identity{Name: "example"}, config)
if err != nil {
t.Fatal(err)
@@ -54,13 +48,10 @@ func TestAppParseUsesRegisteredBindingsWithTheAdapter(t *testing.T) {
}
func TestExecutionRefreshesHelpMetadataAfterRegistration(t *testing.T) {
first, err := NewCommand(CommandSpec[struct{}]{
first := NewCommand(CommandSpec[struct{}]{
Name: "first",
Run: func(Invocation, struct{}) Outcome { return Success() },
})
if err != nil {
t.Fatal(err)
}
app, err := New(Identity{Name: "example"}, first)
if err != nil {
t.Fatal(err)
@@ -72,14 +63,11 @@ func TestExecutionRefreshesHelpMetadataAfterRegistration(t *testing.T) {
t.Fatalf("initial parse failed: %s", parsed.Failure.Message)
}
late, err := NewCommand(CommandSpec[struct{}]{
late := NewCommand(CommandSpec[struct{}]{
Name: "late",
Summary: "registered during execution",
Run: func(Invocation, struct{}) Outcome { return Success() },
})
if err != nil {
t.Fatal(err)
}
if err := app.Register(late); err != nil {
t.Fatal(err)
}