-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathinfo.go
176 lines (163 loc) · 4.22 KB
/
info.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package cmd
import (
"fmt"
"github.com/AlecAivazis/survey/v2"
"github.com/MakeNowJust/heredoc"
"github.com/raystack/meteor/registry"
"github.com/raystack/salt/printer"
"github.com/raystack/salt/term"
"github.com/spf13/cobra"
)
// InfoCmd creates a command object for get info about a plugin
func InfoCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "info <command>",
Short: "Display plugin information",
Annotations: map[string]string{
"group": "core",
},
}
cmd.AddCommand(InfoSinkCmd())
cmd.AddCommand(InfoExtCmd())
cmd.AddCommand(InfoProccCmd())
return cmd
}
// InfoSinkCmd creates a command object for listing sinks
func InfoSinkCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "sink <name>",
Short: "Display sink information",
Long: heredoc.Doc(`
Display sink information.
The list of supported sinks is available via the 'meteor list sinks' command.`),
Example: heredoc.Doc(`
$ meteor info sink console
$ meteor info sink compass
`),
Args: cobra.MaximumNArgs(1),
Annotations: map[string]string{
"group": "core",
},
RunE: func(cmd *cobra.Command, args []string) error {
var sinks []string
for n := range registry.Sinks.List() {
sinks = append(sinks, n)
}
// checking if plugin_name was passed as an Arg
var name string
if len(args) == 1 {
name = args[0]
} else {
if err := survey.AskOne(&survey.Select{
Message: "Select the name of sink",
Options: sinks,
}, &name); err != nil {
return err
}
}
info, err := registry.Sinks.Info(name)
if err := inform("sinks", info.Summary, err); err != nil {
return err
}
return nil
},
}
return cmd
}
// InfoExtCmd creates a command object for listing extractors
func InfoExtCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "extractor <name>",
Short: "Display extractor information",
Long: heredoc.Doc(`
Display sink information.
The list of supported extractors is available via the 'meteor list extractors' command.
`),
Example: heredoc.Doc(`
$ meteor info extractor postgres
$ meteor info extractor bigquery
`),
Args: cobra.MaximumNArgs(1),
Annotations: map[string]string{
"group": "core",
},
RunE: func(cmd *cobra.Command, args []string) error {
var extractors []string
for n := range registry.Extractors.List() {
extractors = append(extractors, n)
}
// checking if plugin_name was passed as an Arg
var name string
if len(args) == 1 {
name = args[0]
} else {
if err := survey.AskOne(&survey.Select{
Message: "Select the name of extractor",
Options: extractors,
}, &name); err != nil {
return err
}
}
info, err := registry.Extractors.Info(name)
if err := inform("extractors", info.Summary, err); err != nil {
return err
}
return nil
},
}
return cmd
}
// InfoProccCmd creates a command object for listing processors
func InfoProccCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "processor <name>",
Short: "Display processor information",
Long: heredoc.Doc(`
Display processor information.
The list of supported processors is available via the 'meteor list processors' command.
`),
Example: heredoc.Doc(`
$ meteor info processor enrich
`),
Args: cobra.MaximumNArgs(1),
Annotations: map[string]string{
"group": "core",
},
RunE: func(cmd *cobra.Command, args []string) error {
var processors []string
for n := range registry.Processors.List() {
processors = append(processors, n)
}
var name string
if len(args) > 0 {
name = args[0]
} else {
if err := survey.AskOne(&survey.Select{
Message: "Select the name of the Processor",
Options: processors,
}, &name); err != nil {
return err
}
}
info, err := registry.Processors.Info(name)
if err := inform("processors", info.Summary, err); err != nil {
return err
}
return nil
},
}
return cmd
}
func inform(typ string, summary string, err error) error {
if err != nil {
fmt.Println(term.Redf("ERROR: %s", err.Error()))
fmt.Println(term.Bluef("\nUse 'meteor list %s' for the list of supported %s.", typ, typ))
return nil
}
out, err := printer.MarkdownWithWrap(summary, 130)
if err != nil {
return err
}
fmt.Print(out)
return nil
}