Commit 9d2cd925 authored by ale's avatar ale

Add book matchers for missing files / missing cover image

parent 677d9ddf
Pipeline #459 passed with stages
in 1 minute and 18 seconds
......@@ -26,6 +26,8 @@ func (c *listCommand) Usage() string {
+incomplete
+invalid
+source:<SOURCE>
+nofiles
+missingcover
`
}
......@@ -44,6 +46,21 @@ func matchSource(source string) func(*liber.Book) bool {
}
}
func matchNoFiles(db *liber.Database) func(*liber.Book) bool {
return func(book *liber.Book) bool {
f, _ := db.GetBookFiles(book.Id)
return len(f) == 0
}
}
func matchMissingCover(book *liber.Book) bool {
if book.CoverPath == "" {
return true
}
_, err := os.Stat(book.CoverPath)
return err != nil && os.IsNotExist(err)
}
func matchIncomplete(book *liber.Book) bool {
return (book.Metadata != nil && book.Metadata.Complete())
}
......@@ -56,7 +73,7 @@ func matchAll(_ *liber.Book) bool {
return true
}
func (c *listCommand) parseTag(tag string) (func(*liber.Book) bool, error) {
func (c *listCommand) parseTag(db *liber.Database, tag string) (func(*liber.Book) bool, error) {
if strings.HasPrefix(tag, "+source:") {
return matchSource(tag[7:]), nil
}
......@@ -68,6 +85,10 @@ func (c *listCommand) parseTag(tag string) (func(*liber.Book) bool, error) {
return matchIncomplete, nil
case "+invalid":
return matchInvalid, nil
case "+nofiles":
return matchNoFiles(db), nil
case "+missingcover":
return matchMissingCover, nil
default:
return nil, fmt.Errorf("unknown tag '%s'", tag)
}
......@@ -84,7 +105,7 @@ func (c *listCommand) Execute(ctx context.Context, f *flag.FlagSet, _ ...interfa
var matchFuncs []func(*liber.Book) bool
for _, arg := range f.Args() {
f, err := c.parseTag(arg)
f, err := c.parseTag(db, arg)
if err != nil {
log.Printf("error: %v", err)
return subcommands.ExitUsageError
......
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