diff --git a/test/instrumentation/BUILD b/test/instrumentation/BUILD index 7221bf609cc..01002628640 100644 --- a/test/instrumentation/BUILD +++ b/test/instrumentation/BUILD @@ -44,7 +44,7 @@ genrule( "//:all-srcs", ], outs = ["stable-metrics-list.yaml"], - cmd = "./$(locations :instrumentation) $(locations //:all-srcs) > $@", + cmd = "for loc in $(locations //:all-srcs); do echo $$loc; done | ./$(locations :instrumentation) - > $@", message = "Listing all stable metrics.", tools = [":instrumentation"], ) diff --git a/test/instrumentation/main.go b/test/instrumentation/main.go index a997c68a300..96d9655bfc9 100644 --- a/test/instrumentation/main.go +++ b/test/instrumentation/main.go @@ -17,6 +17,7 @@ limitations under the License. package main import ( + "bufio" "flag" "fmt" "go/ast" @@ -42,18 +43,34 @@ const ( func main() { flag.Parse() if len(flag.Args()) < 1 { - fmt.Fprintf(os.Stderr, "USAGE: %s [...]\n", os.Args[0]) + fmt.Fprintf(os.Stderr, "USAGE: %s [...]\n", os.Args[0]) os.Exit(64) } stableMetrics := []metric{} errors := []error{} + addStdin := false for _, arg := range flag.Args() { + if arg == "-" { + addStdin = true + continue + } ms, es := searchPathForStableMetrics(arg) stableMetrics = append(stableMetrics, ms...) errors = append(errors, es...) } + if addStdin { + scanner := bufio.NewScanner(os.Stdin) + scanner.Split(bufio.ScanLines) + for scanner.Scan() { + arg := scanner.Text() + ms, es := searchPathForStableMetrics(arg) + stableMetrics = append(stableMetrics, ms...) + errors = append(errors, es...) + } + } + for _, err := range errors { fmt.Fprintf(os.Stderr, "%s\n", err) }