MCPcopy Index your code
hub / github.com/dnote/dnote / newRun

Function newRun

pkg/cli/cmd/find/find.go:153–195  ·  view source on GitHub ↗
(ctx context.DnoteCtx)

Source from the content-addressed store, hash-verified

151}
152
153func newRun(ctx context.DnoteCtx) infra.RunEFunc {
154 return func(cmd *cobra.Command, args []string) error {
155 phrase, err := escapePhrase(args[0])
156 if err != nil {
157 return errors.Wrap(err, "escaping phrase")
158 }
159
160 rows, err := doQuery(ctx, phrase, bookName)
161 if err != nil {
162 return errors.Wrap(err, "querying notes")
163 }
164 defer rows.Close()
165
166 infos := []noteInfo{}
167 for rows.Next() {
168 var info noteInfo
169
170 var body string
171 err = rows.Scan(&info.RowID, &info.BookLabel, &body)
172 if err != nil {
173 return errors.Wrap(err, "scanning a row")
174 }
175
176 body, err := formatFTSSnippet(body)
177 if err != nil {
178 return errors.Wrap(err, "formatting a body")
179 }
180
181 info.Body = body
182
183 infos = append(infos, info)
184 }
185
186 for _, info := range infos {
187 bookLabel := log.ColorYellow.Sprintf("(%s)", info.BookLabel)
188 rowid := log.ColorYellow.Sprintf("(%d)", info.RowID)
189
190 log.Plainf("%s %s %s\n", bookLabel, rowid, info.Body)
191 }
192
193 return nil
194 }
195}

Callers 1

NewCmdFunction · 0.70

Calls 5

PlainfFunction · 0.92
escapePhraseFunction · 0.85
doQueryFunction · 0.85
formatFTSSnippetFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected