-
Notifications
You must be signed in to change notification settings - Fork 7
/
list.auto.go
167 lines (144 loc) · 3.55 KB
/
list.auto.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
// Code generated from specification version 1.0.0: DO NOT EDIT
package list
import (
"fmt"
"io"
"net/http"
"github.com/MakeNowJust/heredoc/v2"
"github.com/reubenmiller/go-c8y-cli/v2/pkg/cmd/subcommand"
"github.com/reubenmiller/go-c8y-cli/v2/pkg/cmderrors"
"github.com/reubenmiller/go-c8y-cli/v2/pkg/cmdutil"
"github.com/reubenmiller/go-c8y-cli/v2/pkg/completion"
"github.com/reubenmiller/go-c8y-cli/v2/pkg/flags"
"github.com/reubenmiller/go-c8y-cli/v2/pkg/mapbuilder"
"github.com/reubenmiller/go-c8y/pkg/c8y"
"github.com/spf13/cobra"
)
// ListCmd command
type ListCmd struct {
*subcommand.SubCommand
factory *cmdutil.Factory
}
// NewListCmd creates a command to Get data broker collection
func NewListCmd(f *cmdutil.Factory) *ListCmd {
ccmd := &ListCmd{
factory: f,
}
cmd := &cobra.Command{
Use: "list",
Short: "Get data broker collection",
Long: `Get a collection of existing data broker connectors`,
Example: heredoc.Doc(`
$ c8y databroker list
Get a list of data broker connectors
`),
PreRunE: func(cmd *cobra.Command, args []string) error {
return nil
},
RunE: ccmd.RunE,
}
cmd.SilenceUsage = true
completion.WithOptions(
cmd,
)
flags.WithOptions(
cmd,
flags.WithExtendedPipelineSupport("", "", false),
flags.WithCollectionProperty("connectors"),
)
// Required flags
ccmd.SubCommand = subcommand.NewSubCommand(cmd)
return ccmd
}
// RunE executes the command
func (n *ListCmd) RunE(cmd *cobra.Command, args []string) error {
cfg, err := n.factory.Config()
if err != nil {
return err
}
// Runtime flag options
flags.WithOptions(
cmd,
flags.WithRuntimePipelineProperty(),
)
client, err := n.factory.Client()
if err != nil {
return err
}
inputIterators, err := cmdutil.NewRequestInputIterators(cmd, cfg)
if err != nil {
return err
}
// query parameters
query := flags.NewQueryTemplate()
err = flags.WithQueryParameters(
cmd,
query,
inputIterators,
flags.WithCustomStringSlice(func() ([]string, error) { return cfg.GetQueryParameters(), nil }, "custom"),
)
if err != nil {
return cmderrors.NewUserError(err)
}
commonOptions, err := cfg.GetOutputCommonOptions(cmd)
if err != nil {
return cmderrors.NewUserError(fmt.Sprintf("Failed to get common options. err=%s", err))
}
commonOptions.AddQueryParameters(query)
queryValue, err := query.GetQueryUnescape(true)
if err != nil {
return cmderrors.NewSystemError("Invalid query parameter")
}
// headers
headers := http.Header{}
err = flags.WithHeaders(
cmd,
headers,
inputIterators,
flags.WithCustomStringSlice(func() ([]string, error) { return cfg.GetHeader(), nil }, "header"),
)
if err != nil {
return cmderrors.NewUserError(err)
}
// form data
formData := make(map[string]io.Reader)
err = flags.WithFormDataOptions(
cmd,
formData,
inputIterators,
)
if err != nil {
return cmderrors.NewUserError(err)
}
// body
body := mapbuilder.NewInitializedMapBuilder(false)
err = flags.WithBody(
cmd,
body,
inputIterators,
)
if err != nil {
return cmderrors.NewUserError(err)
}
// path parameters
path := flags.NewStringTemplate("/databroker/connectors")
err = flags.WithPathParameters(
cmd,
path,
inputIterators,
)
if err != nil {
return err
}
req := c8y.RequestOptions{
Method: "GET",
Path: path.GetTemplate(),
Query: queryValue,
Body: body,
FormData: formData,
Header: headers,
IgnoreAccept: cfg.IgnoreAcceptHeader(),
DryRun: cfg.ShouldUseDryRun(cmd.CommandPath()),
}
return n.factory.RunWithWorkers(client, cmd, &req, inputIterators)
}