Show metadata-only groups in parent help inventories
This commit is contained in:
@@ -505,3 +505,50 @@ func TestNilDiagnosticWritersHaveNoOutputAndDoNotHideCauses(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParentHelpDiscoversMetadataOnlyGroups(t *testing.T) {
|
||||
leaf, err := commandkit.Group("notes", "Read notes metadata.")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
parent, err := commandkit.Group("topics", "Browse topic metadata.", leaf)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
app, err := commandkit.New(commandkit.Identity{Name: "example"}, parent)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
loads := 0
|
||||
if err := commandkit.RegisterConfig(app, commandkit.ConfigSuite[struct{}]{Scopes: []commandkit.ConfigScope[struct{}]{{Name: "app", Operations: []commandkit.ConfigOperation{commandkit.ConfigValidate}, Acquire: func(context.Context, commandkit.ConfigRequest, struct{}) (commandkit.Acquired[commandkit.ConfigView], error) {
|
||||
loads++
|
||||
return commandkit.Acquired[commandkit.ConfigView]{}, nil
|
||||
}}}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
args []string
|
||||
content string
|
||||
}{
|
||||
{nil, "Browse topic metadata."},
|
||||
{[]string{"topics"}, "Read notes metadata."},
|
||||
{[]string{"topics", "--help"}, "Read notes metadata."},
|
||||
{[]string{"help", "topics"}, "Read notes metadata."},
|
||||
{[]string{"topics", "notes"}, "Read notes metadata."},
|
||||
{[]string{"help", "topics", "notes"}, "Read notes metadata."},
|
||||
} {
|
||||
var out bytes.Buffer
|
||||
result := app.Execute(context.Background(), tc.args, commandkit.Streams{Out: &out})
|
||||
if result.Kind != commandkit.OutcomeSuccess || !strings.Contains(out.String(), tc.content) || loads != 0 {
|
||||
t.Fatalf("%v: result=%#v output=%q loads=%d", tc.args, result, out.String(), loads)
|
||||
}
|
||||
if len(tc.args) == 1 && (!strings.Contains(out.String(), "Available Commands:") || !strings.Contains(out.String(), "[command]")) {
|
||||
t.Fatalf("missing child inventory/usage: %q", out.String())
|
||||
}
|
||||
}
|
||||
var diagnostic bytes.Buffer
|
||||
result := app.Execute(context.Background(), []string{"topics", "unknown"}, commandkit.Streams{Err: &diagnostic})
|
||||
if result.Kind != commandkit.OutcomeUsage || !strings.Contains(diagnostic.String(), "[command]") {
|
||||
t.Fatalf("result=%#v diagnostic=%q", result, diagnostic.String())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user