-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
69 lines (59 loc) · 1.73 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"database/sql"
"flag"
"fmt"
"log"
_ "github.com/mattn/go-sqlite3"
useCases "github.com/brunofpessoa/kindle-highlights/use_cases"
"github.com/brunofpessoa/kindle-highlights/util"
)
func main() {
var dbFileName, fileName, bookName string
var minLen, maxLen int
var showAll, noDuplicates, listBooks bool
flag.IntVar(&maxLen, "max", 500, "Max length of the highlight")
flag.IntVar(&minLen, "min", 10, "Min length of the highlight")
flag.StringVar(&dbFileName, "db", "database.sqlite3", "Database name")
flag.StringVar(&fileName, "file", "My Clippings.txt", "File path")
flag.StringVar(
&bookName,
"book",
"",
"Specifies which book to take the highlight from. Can be the full name or part of it",
)
flag.BoolVar(&showAll, "all", false, "Show all highlights")
flag.BoolVar(
&noDuplicates,
"no-duplicates",
true,
"Determine if should remove duplicated highlights. If true will keep the last one created",
)
flag.BoolVar(&listBooks, "list-books", false, "List all books")
flag.Parse()
if minLen > maxLen {
log.Fatal("min length must be less than max length")
}
db, err := sql.Open("sqlite3", dbFileName)
if err != nil {
log.Fatal(err)
}
defer db.Close()
if !util.FileExists(dbFileName) {
fmt.Println("Wait, creating database...")
useCases.PersistHighlights(db, fileName, noDuplicates)
fmt.Println("Done! Run again to print your highlights")
return
}
if bookName != "" && showAll {
useCases.PrintAllByBook(db, minLen, maxLen, bookName)
} else if bookName != "" {
useCases.PrintRandByBook(db, minLen, maxLen, bookName)
} else if showAll {
useCases.PrintAll(db, minLen, maxLen)
} else if listBooks {
useCases.PrintAllBooks(db)
} else {
useCases.PrintRand(db, minLen, maxLen)
}
}