-
Notifications
You must be signed in to change notification settings - Fork 7
/
list.auto.go
189 lines (164 loc) · 5.12 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// 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/c8yfetcher"
"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 binary collection
func NewListCmd(f *cmdutil.Factory) *ListCmd {
ccmd := &ListCmd{
factory: f,
}
cmd := &cobra.Command{
Use: "list",
Short: "Get binary collection",
Long: `Get a collection of inventory binaries. The results include the meta information about binary and not the binary itself.
`,
Example: heredoc.Doc(`
$ c8y binaries list --pageSize 100
Get a list of binaries
$ c8y binaries list --type package_debian
Get a list of binaries with the type package_debian
`),
PreRunE: func(cmd *cobra.Command, args []string) error {
return nil
},
RunE: ccmd.RunE,
}
cmd.SilenceUsage = true
cmd.Flags().StringSlice("ids", []string{""}, "The managed object IDs to search for.")
cmd.Flags().String("type", "", "The type of managed object to search for. (accepts pipeline)")
cmd.Flags().String("owner", "", "Username of the owner of the managed objects.")
cmd.Flags().String("text", "", "Search for managed objects where any property value is equal to the given one. Only string values are supported.")
cmd.Flags().String("childAdditionId", "", "Search for a specific child addition and list all the groups to which it belongs.")
cmd.Flags().String("childAssetId", "", "Search for a specific child asset and list all the groups to which it belongs.")
cmd.Flags().StringSlice("childDeviceId", []string{""}, "Search for a specific child device and list all the groups to which it belongs.")
completion.WithOptions(
cmd,
completion.WithDevice("childDeviceId", func() (*c8y.Client, error) { return ccmd.factory.Client() }),
)
flags.WithOptions(
cmd,
flags.WithExtendedPipelineSupport("type", "type", false, "type"),
flags.WithPipelineAliases("childDeviceId", "deviceId", "source.id", "managedObject.id", "id"),
flags.WithCollectionProperty("managedObjects"),
)
// 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"),
flags.WithStringSliceCSV("ids", "ids", ""),
flags.WithStringValue("type", "type"),
flags.WithStringValue("owner", "owner"),
flags.WithStringValue("text", "text"),
flags.WithStringValue("childAdditionId", "childAdditionId"),
flags.WithStringValue("childAssetId", "childAssetId"),
c8yfetcher.WithDeviceByNameFirstMatch(n.factory, args, "childDeviceId", "childDeviceId"),
)
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("/inventory/binaries")
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)
}