From 0c248599e00c923a985ffc18feadb81e4777adbb Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sat, 25 Jan 2020 20:09:01 +0100 Subject: [PATCH] Allow specifying input file Signed-off-by: Knut Ahlers --- main.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 920de97..8388d4d 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "bufio" "fmt" + "io" "os" "regexp" @@ -62,7 +63,18 @@ func main() { log.WithError(err).Fatal("Unable to create metrics client") } - scanner := bufio.NewScanner(os.Stdin) + var input io.Reader = os.Stdin + if len(rconfig.Args()) > 1 { + f, err := os.Open(rconfig.Args()[1]) + if err != nil { + log.WithError(err).Fatal("Unable to open input file") + } + defer f.Close() + + input = f + } + + scanner := bufio.NewScanner(input) for scanner.Scan() { var line = scanner.Text()