From 99bb2e39263dd477c8e438ff38ac1c158e4097a9 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 2 Mar 2026 10:58:44 +0200 Subject: store/cli: move search output to CLI layer (task 400) --- internal/cli/cli.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'internal/cli/cli.go') diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 7b18c34..11f1f7e 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -267,7 +267,7 @@ func (c *CLI) dispatch(ctx context.Context, argv []string) int { func (c *CLI) dispatchSimple(ctx context.Context, argv []string, cmd string) (int, string, bool) { switch cmd { case "ls": - indexes, err := c.st.Search(ctx, ".", store.ActionNone, nil) + indexes, err := c.st.Search(ctx, ".", store.ActionNone, nil, printIndex) if err != nil { warn(err.Error()) return 1, "", true @@ -393,7 +393,7 @@ func (c *CLI) dispatchSearch(ctx context.Context, argv []string, cmd string) (in default: // Unknown command: treat as a search term, mirroring Ruby's else branch. // This allows bare search terms to be typed without prefixing "search". - indexes, err := c.st.Search(ctx, cmd, store.ActionNone, nil) + indexes, err := c.st.Search(ctx, cmd, store.ActionNone, nil, printIndex) if err != nil { warn(err.Error()) return 1, "" @@ -513,7 +513,7 @@ func (c *CLI) cmdFullCommit(ctx context.Context) int { // cmdSearchOnly runs a search without any action and returns the result. func (c *CLI) cmdSearchOnly(ctx context.Context, term string) (int, string) { - indexes, err := c.st.Search(ctx, term, store.ActionNone, nil) + indexes, err := c.st.Search(ctx, term, store.ActionNone, nil, printIndex) if err != nil { warn(err.Error()) return 1, "" @@ -526,7 +526,7 @@ func (c *CLI) cmdSearchOnly(ctx context.Context, term string) (int, string) { // cmdSearchAction runs a search with the given action and optional callback. func (c *CLI) cmdSearchAction(ctx context.Context, term string, action store.Action, actionFn func(context.Context, *store.Index, *store.Data) error) (int, string) { - indexes, err := c.st.Search(ctx, term, action, actionFn) + indexes, err := c.st.Search(ctx, term, action, actionFn, printIndex) if err != nil { warn(err.Error()) return 1, "" @@ -537,6 +537,10 @@ func (c *CLI) cmdSearchAction(ctx context.Context, term string, action store.Act return 0, "" } +func printIndex(idx *store.Index) { + fmt.Print(idx.String()) +} + // makeActionFn returns the appropriate callback function for actions that // require external tools (paste, open, edit). For actions handled internally // by the store (cat, export, pathexport), nil is returned. -- cgit v1.2.3