-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathls.go
133 lines (127 loc) · 3.04 KB
/
ls.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package ma
import (
"fmt"
"github.com/bzimmer/smugmug"
"github.com/urfave/cli/v2"
)
func image(c *cli.Context) error {
mg := runtime(c).Smugmug()
for i := 0; i < c.NArg(); i++ {
id := c.Args().Get(i)
if !imageRE.MatchString(id) {
id = fmt.Sprintf("%s-0", id)
}
image, err := mg.Image.Image(c.Context, id, smugmug.WithExpansions("ImageAlbum"))
if err != nil {
return err
}
f := imageIterFunc(c, image.Album, "ls")
if _, err = f(image); err != nil {
return err
}
}
return nil
}
func album(c *cli.Context) error {
mg := runtime(c).Smugmug()
f := albumIterFunc(c, "ls")
for _, id := range c.Args().Slice() {
album, err := mg.Album.Album(c.Context, id)
if err != nil {
return err
}
if _, err = f(album); err != nil {
return err
}
}
return nil
}
func node(c *cli.Context) error {
mg := runtime(c).Smugmug()
nodeIDs := c.Args().Slice()
if len(nodeIDs) == 0 {
user, err := mg.User.AuthUser(c.Context, smugmug.WithExpansions("Node"))
if err != nil {
return err
}
nodeIDs = []string{user.Node.NodeID}
}
depth := c.Int("depth")
f := nodeIterFunc(c, c.Bool("recurse"), "ls")
for i := range nodeIDs {
if err := mg.Node.WalkN(c.Context, nodeIDs[i], f, depth, smugmug.WithExpansions("Album", "ParentNode")); err != nil {
return err
}
}
return nil
}
func CommandList() *cli.Command {
return &cli.Command{
Name: "ls",
HelpName: "ls",
Aliases: []string{"list"},
Usage: "List nodes, albums, and/or images",
Description: "List the details of albums, nodes, and/or images",
Subcommands: []*cli.Command{
{
Name: "album",
HelpName: "album",
Usage: "list albums",
Description: "list the contents of an album(s)",
ArgsUsage: "<album key> [<album key>, ...]",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "image",
Aliases: []string{"i", "R"},
Usage: "include images in the query",
},
},
Action: album,
},
{
Name: "node",
HelpName: "node",
Usage: "list nodes",
Description: "list the contents of a node(s)",
ArgsUsage: "<node id> [<node id>, ...]",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "album",
Aliases: []string{"a"},
Usage: "include albums in the query",
},
&cli.BoolFlag{
Name: "node",
Aliases: []string{"n", "f"},
Usage: "include nodes in the query",
},
&cli.BoolFlag{
Name: "image",
Aliases: []string{"i"},
Usage: "include images in the query",
},
&cli.BoolFlag{
Name: "recurse",
Aliases: []string{"R"},
Usage: "walk the node tree",
},
&cli.IntFlag{
Name: "depth",
Value: -1,
Usage: "walk the node tree to the specified depth",
},
},
Before: albumOrNode,
Action: node,
},
{
Name: "image",
HelpName: "image",
Usage: "list images",
Description: "list the details of an image(s)",
ArgsUsage: "<image key> [<image key>, ...]",
Action: image,
},
},
}
}