amtool: add support for stdin to check-config (#1431)

* amtool: add support for stdin to check-config

Signed-off-by: Simon Pasquier <spasquie@redhat.com>

* Address Stuart's comment

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
Simon Pasquier 2018-07-09 19:27:04 +02:00 committed by stuart nelson
parent 42ea9a565b
commit 5aac7c840b
1 changed files with 9 additions and 0 deletions

View File

@ -15,6 +15,7 @@ package cli
import (
"fmt"
"os"
"github.com/prometheus/alertmanager/config"
"github.com/prometheus/alertmanager/template"
@ -47,6 +48,14 @@ func (c *checkConfigCmd) checkConfig(ctx *kingpin.ParseContext) error {
}
func CheckConfig(args []string) error {
if len(args) == 0 {
stat, _ := os.Stdin.Stat()
if (stat.Mode() & os.ModeCharDevice) != 0 {
kingpin.Fatalf("Failed to read from standard input")
}
args = []string{os.Stdin.Name()}
}
failed := 0
for _, arg := range args {