Skip to content
Snippets Groups Projects
Commit 1555c0d9 authored by ale's avatar ale
Browse files

Add list-books matchers for missing sources and ISBNs

parent 3b4b6075
No related branches found
No related tags found
No related merge requests found
......@@ -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)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment