-
Notifications
You must be signed in to change notification settings - Fork 0
/
sfind.go
59 lines (53 loc) · 1.35 KB
/
sfind.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
package main
import (
"os"
"github.com/codegangsta/cli"
)
func main() {
app := cli.NewApp()
app.Name = "SFind"
app.Version = "0.1.0"
app.Usage = "A simple find tool"
app.UsageText = "sfind [options] [PATTERN] [PATH]"
app.Flags = []cli.Flag {
cli.BoolFlag {
Name: "count, c",
Usage: "Return a count of matches",
},
cli.BoolFlag {
Name: "ext, e",
Usage: "Use extended regex patterns",
},
cli.BoolFlag {
Name: "invert, i",
Usage: "Only return items that don't match PATTERN",
},
cli.BoolFlag {
Name: "insensitive, I",
Usage: "Case insensitive matches",
},
cli.BoolFlag {
Name: "include-dirs, d",
Usage: "Include directories in matches. This has presidence over 'dirs-only'",
},
cli.BoolFlag {
Name: "dirs-only, D",
Usage: "Only match directories",
},
cli.BoolFlag {
Name: "full-path, f",
Usage: "Match PATTERN again the full file (or directory) path. Ext option is implied.",
},
cli.StringFlag{
Name: "type, t",
Usage: "The file type/extension to additionally filter by",
},
}
app.Action = func(c *cli.Context) {
pattern, base_path := determineArgs(c)
matcher := createMatcher(pattern, c)
result := createResult(c)
outputResults(base_path, result, matcher, c)
}
app.Run(os.Args)
}