From d50b006af9ee1aa181df5c26c5335c3d7bf098b2 Mon Sep 17 00:00:00 2001 From: Virgil Date: Tue, 31 Mar 2026 20:21:03 +0000 Subject: [PATCH] feat(help): show snippets in search results Co-Authored-By: Virgil --- cmd/core/help/cmd.go | 3 +++ cmd/core/help/cmd_test.go | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/cmd/core/help/cmd.go b/cmd/core/help/cmd.go index 50385bf..67c9a72 100644 --- a/cmd/core/help/cmd.go +++ b/cmd/core/help/cmd.go @@ -48,6 +48,9 @@ func renderSearchResults(results []*gohelp.SearchResult, query string) error { cli.Section("Search Results") for _, res := range results { cli.Println(" %s - %s", res.Topic.ID, res.Topic.Title) + if snippet := strings.TrimSpace(res.Snippet); snippet != "" { + cli.Println("%s", cli.DimStr(" "+snippet)) + } } return nil } diff --git a/cmd/core/help/cmd_test.go b/cmd/core/help/cmd_test.go index a1859f1..91ef803 100644 --- a/cmd/core/help/cmd_test.go +++ b/cmd/core/help/cmd_test.go @@ -59,6 +59,25 @@ func TestAddHelpCommands_Good(t *testing.T) { assert.Contains(t, out, topics[0].ID) } +func TestRenderSearchResults_Good(t *testing.T) { + out := captureOutput(t, func() { + err := renderSearchResults([]*gohelp.SearchResult{ + { + Topic: &gohelp.Topic{ + ID: "config", + Title: "Configuration", + }, + Snippet: "Core is configured via environment variables.", + }, + }, "config") + require.NoError(t, err) + }) + + assert.Contains(t, out, "SEARCH RESULTS") + assert.Contains(t, out, "config - Configuration") + assert.Contains(t, out, "Core is configured via environment variables.") +} + func TestAddHelpCommands_Bad(t *testing.T) { t.Run("missing search results", func(t *testing.T) { cmd := newHelpCommand(t)