diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-02 10:58:44 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-02 10:58:44 +0200 |
| commit | 99bb2e39263dd477c8e438ff38ac1c158e4097a9 (patch) | |
| tree | 34ef8d85af64112df6eba4efe0f69ebe112e7466 /internal/cli/cli.go | |
| parent | b636b12566ea6c2862bf3adc6686c57e0d785ca3 (diff) | |
store/cli: move search output to CLI layer (task 400)
Diffstat (limited to 'internal/cli/cli.go')
| -rw-r--r-- | internal/cli/cli.go | 12 |
1 files changed, 8 insertions, 4 deletions
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. |
