forked from keeferrourke/imgrep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
93 lines (84 loc) · 1.98 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
/* Standard library packages */
"fmt"
"os"
/* Third party */
// imports as "cli", pinned to v1; cliv2 is going to be drastically
// different and pinning to v1 avoids issues with unstable API changes
"gopkg.in/urfave/cli.v1"
/* Local packages */
"github.com/keeferrourke/imgrep/files"
"github.com/keeferrourke/imgrep/storage"
)
/* cli commands */
// search db
var Search = cli.Command{
Name: "search",
Aliases: []string{"s", "find"},
Usage: "search image database for keywords",
Action: files.Grep,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "no-preindex, n",
Usage: "run without preindex",
},
},
}
// update/initialize sql db
var UpdateDB = cli.Command{
Name: "updatedb",
Aliases: []string{"init"},
Usage: "initialize the database of images",
Action: files.InitFromPath,
Flags: []cli.Flag{
cli.StringFlag{
Name: "dir, d",
Value: files.WALKPATH,
Usage: "specify the base filesystem subtree to scan",
Destination: &files.WALKPATH,
},
cli.BoolFlag{
Name: "verbose, v",
Usage: "enable verbose output",
},
},
}
func init() {
storage.InitDB(files.DBFILE)
}
/* run application */
func main() {
// customize cli
cli.VersionPrinter = func(c *cli.Context) {
fmt.Fprintf(c.App.Writer, "%s %s - %s\n",
c.App.Name, c.App.Version, c.App.Description)
}
// set up the application
app := cli.NewApp()
app.Authors = []cli.Author{
cli.Author{
Name: "Keefer Rourke",
Email: "mail@krourke.org",
},
cli.Author{
Name: "Ivan Zhang",
Email: "ivan@ivanzhang.ca",
},
}
app.Copyright = "(c) 2017 under the MIT License"
app.EnableBashCompletion = true
app.Name = "imgrep"
app.Description = "go-cli image grepper using tesseract"
app.Usage = "grep image files for words"
app.Version = "v0"
app.Commands = []cli.Command{
Search,
UpdateDB,
}
app.CommandNotFound = func(c *cli.Context, command string) {
fmt.Fprintf(c.App.Writer, "Did you read the manual?\n")
}
app.Run(os.Args)
return
}