(ctx context.DnoteCtx)
| 151 | } |
| 152 | |
| 153 | func 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 | } |
no test coverage detected