forked from open-telemetry/opentelemetry-collector
/
command_components.go
58 lines (51 loc) · 1.62 KB
/
command_components.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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package otelcol // import "go.opentelemetry.io/collector/otelcol"
import (
"fmt"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
"go.opentelemetry.io/collector/component"
)
type componentsOutput struct {
BuildInfo component.BuildInfo
Receivers []component.Type
Processors []component.Type
Exporters []component.Type
Connectors []component.Type
Extensions []component.Type
}
// newBuildSubCommand constructs a new cobra.Command sub command using the given CollectorSettings.
func newBuildSubCommand(set CollectorSettings) *cobra.Command {
buildCmd := &cobra.Command{
Use: "components",
Short: "Outputs available components in this collector distribution",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
components := componentsOutput{}
for con := range set.Factories.Connectors {
components.Connectors = append(components.Connectors, con)
}
for ext := range set.Factories.Extensions {
components.Extensions = append(components.Extensions, ext)
}
for prs := range set.Factories.Processors {
components.Processors = append(components.Processors, prs)
}
for rcv := range set.Factories.Receivers {
components.Receivers = append(components.Receivers, rcv)
}
for exp := range set.Factories.Exporters {
components.Exporters = append(components.Exporters, exp)
}
components.BuildInfo = set.BuildInfo
yamlData, err := yaml.Marshal(components)
if err != nil {
return err
}
fmt.Fprint(cmd.OutOrStdout(), string(yamlData))
return nil
},
}
return buildCmd
}