Commit bff49bef authored by ale's avatar ale

Add function to read book IDs from stdin

parent 9e122e3d
Pipeline #460 passed with stages
in 1 minute and 24 seconds
package liber
import (
func (db *Database) Refine(dir string) error {
......@@ -29,3 +32,22 @@ func (db *Database) ListBooks(w io.Writer, matchFuncs ...func(book *Book) bool)
return nil
// WithBookIDs calls a function on books whose IDs are read from the
// specified io.Reader.
func (db *Database) WithBookIDs(r io.Reader, f func(book *Book) error) error {
scanner := bufio.NewScanner(r)
for scanner.Scan() {
id := ParseID(string(bytes.TrimSpace(scanner.Bytes())))
book, err := db.GetBook(id)
if err != nil {
log.Printf("error: no such book %s", id)
if err := f(book); err != nil {
log.Printf("error: %s: %v", id, err)
// Stop?
return scanner.Err()
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment