/
filters.go
113 lines (107 loc) · 3.87 KB
/
filters.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
package cmd
import (
"fmt"
vocab "github.com/go-ap/activitypub"
"github.com/go-ap/errors"
"github.com/go-ap/filters"
"github.com/urfave/cli/v2"
)
func types(c *cli.Context) filters.CompStrs {
if c == nil {
return nil
}
typ := c.String("type")
types := make(filters.CompStrs, 0)
for _, t := range typ {
tt := vocab.ActivityVocabularyType(t)
if vocab.Types.Contains(tt) {
types = append(types, filters.StringEquals(string(tt)))
}
}
return types
}
func names(c *cli.Context) filters.CompStrs {
if c == nil {
return nil
}
name := c.StringSlice("name")
names := make(filters.CompStrs, 0)
for _, t := range name {
names = append(names, filters.StringEquals(t))
}
return names
}
func FilterFlags() []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "path",
Usage: "Pass the path at which to start.",
Value: "/",
},
&cli.StringSliceFlag{
Name: "type",
Usage: fmt.Sprintf("The type of activitypub object to list"),
DefaultText: fmt.Sprintf("Valid values: %v", ValidGenericTypes),
},
&cli.StringSliceFlag{
Name: "name",
Usage: fmt.Sprintf("The name/preferredName of the activitypub object to list"),
},
&cli.StringSliceFlag{
Name: "cont",
Usage: fmt.Sprintf("The content of the activitypub object to list"),
},
&cli.StringSliceFlag{
Name: "to",
Usage: fmt.Sprintf("The to recipients of the activitypub object to list"),
},
&cli.StringSliceFlag{
Name: "cc",
Usage: fmt.Sprintf("The cc recipients of the activitypub object to list"),
},
&cli.StringSliceFlag{
Name: "author",
Usage: fmt.Sprintf("The author of the activitypub object to list"),
},
}
/*
baseURL vocab.IRI `qstring:"-"`
Name CompStrs `qstring:"name,omitempty"`
Cont CompStrs `qstring:"content,omitempty"`
Authenticated *vocab.Actor `qstring:"-"`
To *vocab.Actor `qstring:"-"`
Author *vocab.Actor `qstring:"-"`
Parent *vocab.Actor `qstring:"-"`
IRI vocab.IRI `qstring:"-"`
Collection h.CollectionType `qstring:"-"`
URL CompStrs `qstring:"url,omitempty"`
MedTypes []vocab.MimeType `qstring:"mediaType,omitempty"`
Aud CompStrs `qstring:"recipients,omitempty"`
Gen CompStrs `qstring:"generator,omitempty"`
Key []Hash `qstring:"-"`
ItemKey CompStrs `qstring:"iri,omitempty"`
Type vocab.ActivityVocabularyTypes `qstring:"type,omitempty"`
AttrTo CompStrs `qstring:"attributedTo,omitempty"`
InReplTo CompStrs `qstring:"inReplyTo,omitempty"`
OP CompStrs `qstring:"context,omitempty"`
FollowedBy []Hash `qstring:"followedBy,omitempty"` // todo(marius): not really used
OlderThan time.Time `qstring:"olderThan,omitempty"`
NewerThan time.Time `qstring:"newerThan,omitempty"`
Prev Hash `qstring:"before,omitempty"`
Next Hash `qstring:"after,omitempty"`
Object *Filters `qstring:"object,omitempty"`
Actor *Filters `qstring:"actor,omitempty"`
Target *Filters `qstring:"target,omitempty"`
CurPage uint `qstring:"page,omitempty"`
MaxItems uint `qstring:"maxItems,omitempty"`
*/
}
func LoadFilters(c *cli.Context) (*filters.Filters, error) {
if c == nil {
return nil, errors.Newf("invalid nil context")
}
f := new(filters.Filters)
f.Type = types(c)
f.Name = names(c)
return f, nil
}