Commit 1555c0d9 authored by ale's avatar ale

Add list-books matchers for missing sources and ISBNs

parent 3b4b6075
Pipeline #463 passed with stages
in 1 minute and 24 seconds
......@@ -26,7 +26,9 @@ func (c *listCommand) Usage() string {
+incomplete
+invalid
+source:<SOURCE>
-source:<SOURCE>
+nofiles
+noisbn
+missingcover
`
......@@ -46,6 +48,20 @@ func matchSource(source string) func(*liber.Book) bool {
}
}
func matchMissingSource(source string) func(*liber.Book) bool {
return func(book *liber.Book) bool {
if book.Metadata == nil {
return true
}
for _, msrc := range book.Metadata.Sources {
if msrc.Name == source {
return false
}
}
return true
}
}
func matchNoFiles(db *liber.Database) func(*liber.Book) bool {
return func(book *liber.Book) bool {
f, _ := db.GetBookFiles(book.Id)
......@@ -65,6 +81,10 @@ func matchIncomplete(book *liber.Book) bool {
return (book.Metadata != nil && book.Metadata.Complete())
}
func matchNoISBN(book *liber.Book) bool {
return book.Metadata == nil || len(book.Metadata.ISBN) == 0
}
func matchInvalid(_ *liber.Book) bool {
return false
}
......@@ -75,7 +95,10 @@ func matchAll(_ *liber.Book) bool {
func (c *listCommand) parseTag(db *liber.Database, tag string) (func(*liber.Book) bool, error) {
if strings.HasPrefix(tag, "+source:") {
return matchSource(tag[7:]), nil
return matchSource(tag[8:]), nil
}
if strings.HasPrefix(tag, "-source:") {
return matchMissingSource(tag[8:]), nil
}
switch tag {
......@@ -89,6 +112,8 @@ func (c *listCommand) parseTag(db *liber.Database, tag string) (func(*liber.Book
return matchNoFiles(db), nil
case "+missingcover":
return matchMissingCover, nil
case "+noisbn":
return matchNoISBN, nil
default:
return nil, fmt.Errorf("unknown tag '%s'", tag)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment