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