-
Notifications
You must be signed in to change notification settings - Fork 0
/
find.go
48 lines (35 loc) · 921 Bytes
/
find.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
package main
import (
"doozer/client"
"fmt"
"os"
)
func init() {
cmds["find"] = cmd{find, "<glob>", "list files"}
cmdHelp["find"] = `Prints the tree matching <glob>
Rules for <glob> pattern-matching:
- '?' matches a single char in a single path component
- '*' matches zero or more chars in a single path component
- '**' matches zero or more chars in zero or more components
- any other sequence matches itself
Prints a sequence of paths, one for each file/directory. Format of each record:
<path> LF
Here, <path> is the file's path, and LF is an ASCII line-feed char.
`
}
func find(glob string) {
c := client.New("<test>", *addr)
if glob[len(glob)-1:] != "/" {
glob = glob+"/"
}
w, err := c.Walk(glob+"**", 0)
if err != nil {
bail(err)
}
for ev := range w.C {
if ev.Err != nil {
fmt.Fprintln(os.Stderr, ev.Err)
}
fmt.Println(ev.Path)
}
}