-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathotelcomponentmapping_list.go
More file actions
43 lines (35 loc) · 1.2 KB
/
otelcomponentmapping_list.go
File metadata and controls
43 lines (35 loc) · 1.2 KB
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
package otelcomponentmapping
import (
"sort"
"github.com/spf13/cobra"
"github.com/stackvista/stackstate-cli/cmd/otelmapping"
"github.com/stackvista/stackstate-cli/generated/stackstate_api"
"github.com/stackvista/stackstate-cli/internal/common"
"github.com/stackvista/stackstate-cli/internal/di"
)
func OtelComponentMappingListCommand(deps *di.Deps) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "Lists active Otel Component Mappings",
Long: "Lists active Otel Component Mappings.",
RunE: deps.CmdRunEWithApi(RunListComponentCommand),
}
return cmd
}
func RunListComponentCommand(cmd *cobra.Command, cli *di.Deps, api *stackstate_api.APIClient, serverInfo *stackstate_api.ServerInfo) common.CLIError {
mappingsList, resp, err := api.OtelMappingApi.GetOtelComponentMappings(cli.Context).Execute()
if err != nil {
return common.NewResponseError(err, resp)
}
sort.SliceStable(mappingsList, func(i, j int) bool {
return mappingsList[i].Name < mappingsList[j].Name
})
if cli.IsJson() {
cli.Printer.PrintJson(map[string]interface{}{
"otel component mappings": mappingsList,
})
} else {
cli.Printer.Table(otelmapping.FormatOtelMappingTable(mappingsList))
}
return nil
}