-
Notifications
You must be signed in to change notification settings - Fork 40
/
list.go
150 lines (131 loc) · 3.72 KB
/
list.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package cmd
import (
"fmt"
"os"
"strings"
"github.com/MakeNowJust/heredoc"
"github.com/raystack/meteor/registry"
"github.com/raystack/salt/printer"
"github.com/raystack/salt/term"
"github.com/spf13/cobra"
)
// ListCmd creates a command object for linting recipes
func ListCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "list <command>",
Short: "List available plugins",
Annotations: map[string]string{
"group": "core",
},
}
cmd.AddCommand(ListExtCmd())
cmd.AddCommand(ListSinksCmd())
cmd.AddCommand(ListProccCmd())
return cmd
}
// ListExtCmd creates a command object for listing extractors
func ListExtCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "extractors",
Aliases: []string{"e"},
Short: "List available extractors",
Long: heredoc.Doc(`
List available extractors.
This command lists all available extractors.
Extractors are used to extract metadata from a source.
For example, you can use an extractor to extract metadata from a file.
`),
Example: heredoc.Doc(`
$ meteor list extractors
# list all extractors with alias 'e'
$ meteor list e
`),
Annotations: map[string]string{
"group": "core",
},
Run: func(cmd *cobra.Command, args []string) {
extractors := registry.Extractors.List()
fmt.Printf(" \nShowing %d of %d extractors\n \n", len(extractors), len(extractors))
report := [][]string{}
index := 1
for n, i := range extractors {
report = append(report, []string{
term.Greenf("#%02d", index), n, i.Description, term.Greyf(" (%s)", strings.Join(i.Tags, ", ")),
})
index++
}
printer.Table(os.Stdout, report)
},
}
return cmd
}
// ListSinksCmd creates a command object for listing sinks
func ListSinksCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "sinks",
Aliases: []string{"s"},
Short: "List available sinks",
Long: heredoc.Doc(`
List available sinks.
This command lists all available sinks.
Sinks are used to send data to a target.
For example, you can use a sink to send metadata to standard output.`),
Example: heredoc.Doc(`
$ meteor list sinks
# list all sinks with alias 's'
$ meteor list s
`),
Annotations: map[string]string{
"group": "core",
},
Run: func(cmd *cobra.Command, args []string) {
sinks := registry.Sinks.List()
fmt.Printf(" \nShowing %d of %d sinks\n \n", len(sinks), len(sinks))
report := [][]string{}
index := 1
for n, i := range sinks {
report = append(report, []string{
term.Greenf("#%02d", index), n, i.Description, term.Greyf(" (%s)", strings.Join(i.Tags, ", ")),
})
index++
}
printer.Table(os.Stdout, report)
},
}
return cmd
}
// ListProccCmd creates a command object for listing processors
func ListProccCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "processors",
Aliases: []string{"p"},
Short: "List available processors",
Long: heredoc.Doc(`
List available processors.
This command lists all available processors.
Processors are used to transform data before it is sent to a sink.
For example, you can use a processor to enrich custom attributes.`),
Example: heredoc.Doc(`
$ meteor list processors
# list all processors with alias 'p'
$ meteor list p
`),
Annotations: map[string]string{
"group": "core",
},
Run: func(cmd *cobra.Command, args []string) {
processors := registry.Processors.List()
fmt.Printf(" \nShowing %d of %d processors\n \n", len(processors), len(processors))
report := [][]string{}
index := 1
for n, i := range processors {
report = append(report, []string{
term.Greenf("#%02d", index), n, i.Description, term.Greyf(" (%s)", strings.Join(i.Tags, ", ")),
})
index++
}
printer.Table(os.Stdout, report)
},
}
return cmd
}