-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind.go
68 lines (61 loc) · 1.47 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package ma
import (
"strings"
"github.com/bzimmer/smugmug"
"github.com/urfave/cli/v2"
"golang.org/x/sync/errgroup"
)
func find(c *cli.Context) error {
mg := runtime(c).Smugmug()
scope := c.String("scope")
if scope == "" {
user, err := mg.User.AuthUser(c.Context)
if err != nil {
return err
}
scope = user.URI
}
q := strings.Join(c.Args().Slice(), " ")
options := []smugmug.APIOption{smugmug.WithSearch(scope, q)}
grp, ctx := errgroup.WithContext(c.Context)
if c.Bool("node") {
grp.Go(func() error {
return mg.Node.SearchIter(ctx, nodeIterFunc(c, true, "find"), options...)
})
}
if c.Bool("album") {
grp.Go(func() error {
return mg.Album.SearchIter(c.Context, albumIterFunc(c, "find"), options...)
})
}
return grp.Wait()
}
func CommandFind() *cli.Command {
return &cli.Command{
Name: "find",
HelpName: "find",
Aliases: []string{"search"},
Usage: "Search for albums or folders by name",
Description: `Find albums or folders by name
(if neither --album nor --node is specified, both will be searched)
`,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "scope",
Usage: "root the search at the scope, if not specified the authenticated user's scope will be used",
},
&cli.BoolFlag{
Name: "album",
Usage: "search for albums",
Aliases: []string{"a"},
},
&cli.BoolFlag{
Name: "node",
Usage: "search for nodes",
Aliases: []string{"n", "f"},
},
},
Before: albumOrNode,
Action: find,
}
}