-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
66 lines (56 loc) · 1.11 KB
/
main.go
File metadata and controls
66 lines (56 loc) · 1.11 KB
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
package main
import (
"fmt"
"os"
"github.com/urfave/cli"
)
func main() {
var word string
var path string
var recursive bool
app := cli.NewApp()
app.Name = "pptgrep"
app.Usage = "Searching PPTfile which has an input word"
app.Version = "1.0.0"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "word, w",
Usage: "Searching files which has the word",
Destination: &word,
},
cli.StringFlag{
Name: "path, p",
Value: ".",
Usage: "Starting point",
Destination: &path,
},
cli.BoolFlag{
Name: "r",
Usage: "Searching Recursively",
Destination: &recursive,
},
}
app.Action = func(c *cli.Context) error {
if word != "" {
// collect files
var files []string
if !recursive {
files = listFiles(path)
} else {
files = listFilesWalk(path)
}
// search file which has the word
for _, file := range files {
if isPpt(file) {
if containWord(file, word) {
fmt.Println(file)
}
}
}
} else {
fmt.Println(`Please look at usage. ( $ ./pptgrep -h )`)
}
return nil
}
app.Run(os.Args)
}