From b5a2fbf4540337ece4a7bc7aa721a43b67164a0f Mon Sep 17 00:00:00 2001 From: Robert Fratto Date: Fri, 5 Apr 2024 10:09:23 -0400 Subject: [PATCH] listcomponents: introduce new internal tool to list components (#129) This tool lists all registered components with their stability. --- internal/cmd/listcomponents/main.go | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 internal/cmd/listcomponents/main.go diff --git a/internal/cmd/listcomponents/main.go b/internal/cmd/listcomponents/main.go new file mode 100644 index 0000000000..f913754aac --- /dev/null +++ b/internal/cmd/listcomponents/main.go @@ -0,0 +1,34 @@ +// Command listcomponents dumps the list of known Alloy components with their +// stability. +package main + +import ( + "fmt" + "os" + "sort" + "strconv" + "text/tabwriter" + + "github.com/grafana/alloy/internal/component" + + _ "github.com/grafana/alloy/internal/component/all" // Import all component definitions +) + +func main() { + components := component.AllNames() + sort.Strings(components) + + tw := tabwriter.NewWriter(os.Stdout, 0, 8, 0, '\t', 0) + defer func() { _ = tw.Flush() }() + + for _, name := range components { + reg, ok := component.Get(name) + if !ok { + // Not possible, but we'll ignore it anyway. + continue + } + + stability, _ := strconv.Unquote(reg.Stability.String()) + fmt.Fprintf(tw, "%s\t%s\n", reg.Name, stability) + } +}