Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
liber
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ale
liber
Commits
9d2cd925
Commit
9d2cd925
authored
Sep 09, 2017
by
ale
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add book matchers for missing files / missing cover image
parent
677d9ddf
Pipeline
#459
passed with stages
in 1 minute and 18 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
2 deletions
+23
-2
cmd/liber/list.go
cmd/liber/list.go
+23
-2
No files found.
cmd/liber/list.go
View file @
9d2cd925
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment