-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter.go
73 lines (64 loc) · 1.58 KB
/
filter.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
package opcli
import (
"strings"
)
// Filter represents a filter flag passed to 1Password CLI some commands.
type Filter func() []string
// IncludeArchive expands item list to include items in the Archive.
func IncludeArchive() Filter {
return func() []string {
return []string{"--include-archive"}
}
}
// WithCategories limits results to only include items matching given categories.
func WithCategories(categories ...Category) Filter {
return func() []string {
if len(categories) == 0 {
return nil
}
var s []string
for _, c := range categories {
s = append(s, string(c))
}
return []string{"--categories", strings.Join(s, ",")}
}
}
// WithGroup limits results to only include resources from the given group.
func WithGroup(name string) Filter {
return func() []string {
if name == "" {
return nil
}
return []string{"--group", name}
}
}
// WithFavorite limits results to only include favorite items.
func WithFavorite() Filter {
return func() []string {
return []string{"--favorite"}
}
}
// WithTags limits results to only include items matching given tags.
func WithTags(tags ...string) Filter {
return func() []string {
if len(tags) == 0 {
return nil
}
return []string{"--tags", strings.Join(tags, ",")}
}
}
// WithVault limits results to only include resources from the given vault.
func WithVault(name string) Filter {
return func() []string {
if name == "" {
return nil
}
return []string{"--vault", name}
}
}
func applyFilters(cmd []string, filters []Filter) []string {
for _, f := range filters {
cmd = append(cmd, f()...)
}
return cmd
}