/
getManagedObjectChildAssetCollectionCmd.auto.go
123 lines (96 loc) · 3.04 KB
/
getManagedObjectChildAssetCollectionCmd.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
// Code generated from specification version 1.0.0: DO NOT EDIT
package cmd
import (
"fmt"
"io"
"net/http"
"net/url"
"github.com/reubenmiller/go-c8y-cli/pkg/mapbuilder"
"github.com/reubenmiller/go-c8y/pkg/c8y"
"github.com/spf13/cobra"
)
type getManagedObjectChildAssetCollectionCmd struct {
*baseCmd
}
func newGetManagedObjectChildAssetCollectionCmd() *getManagedObjectChildAssetCollectionCmd {
ccmd := &getManagedObjectChildAssetCollectionCmd{}
cmd := &cobra.Command{
Use: "listChildAssets",
Short: "Get a collection of managedObjects child references",
Long: `Get a collection of managedObjects child references`,
Example: `
$ c8y inventoryReferences listChildAssets --device 12345
Get a list of the child devices of an existing device
`,
PreRunE: nil,
RunE: ccmd.getManagedObjectChildAssetCollection,
}
cmd.SilenceUsage = true
cmd.Flags().StringSlice("device", []string{""}, "Device.")
cmd.Flags().StringSlice("group", []string{""}, "Group.")
// Required flags
ccmd.baseCmd = newBaseCmd(cmd)
return ccmd
}
func (n *getManagedObjectChildAssetCollectionCmd) getManagedObjectChildAssetCollection(cmd *cobra.Command, args []string) error {
commonOptions, err := getCommonOptions(cmd)
if err != nil {
return newUserError(fmt.Sprintf("Failed to get common options. err=%s", err))
}
// query parameters
queryValue := url.QueryEscape("")
query := url.Values{}
commonOptions.AddQueryParameters(&query)
queryValue, err = url.QueryUnescape(query.Encode())
if err != nil {
return newSystemError("Invalid query parameter")
}
// headers
headers := http.Header{}
// form data
formData := make(map[string]io.Reader)
// body
body := mapbuilder.NewMapBuilder()
// path parameters
pathParameters := make(map[string]string)
if cmd.Flags().Changed("device") {
deviceInputValues, deviceValue, err := getFormattedDeviceSlice(cmd, args, "device")
if err != nil {
return newUserError("no matching devices found", deviceInputValues, err)
}
if len(deviceValue) == 0 {
return newUserError("no matching devices found", deviceInputValues)
}
for _, item := range deviceValue {
if item != "" {
pathParameters["id"] = newIDValue(item).GetID()
}
}
}
if cmd.Flags().Changed("group") {
groupInputValues, groupValue, err := getFormattedDeviceGroupSlice(cmd, args, "group")
if err != nil {
return newUserError("no matching device groups found", groupInputValues, err)
}
if len(groupValue) == 0 {
return newUserError("no matching device groups found", groupInputValues)
}
for _, item := range groupValue {
if item != "" {
pathParameters["id"] = newIDValue(item).GetID()
}
}
}
path := replacePathParameters("inventory/managedObjects/{id}/childAssets", pathParameters)
req := c8y.RequestOptions{
Method: "GET",
Path: path,
Query: queryValue,
Body: body.GetMap(),
FormData: formData,
Header: headers,
IgnoreAccept: false,
DryRun: globalFlagDryRun,
}
return processRequestAndResponse([]c8y.RequestOptions{req}, commonOptions)
}