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 Max Leonard Inden
parent 579acdc9e2
commit 45567a804d
No known key found for this signature in database
GPG Key ID: 5403C5464810BC26
1 changed files with 9 additions and 0 deletions

View File

@ -15,6 +15,7 @@ package cli
import ( import (
"fmt" "fmt"
"os"
"github.com/prometheus/alertmanager/config" "github.com/prometheus/alertmanager/config"
"github.com/prometheus/alertmanager/template" "github.com/prometheus/alertmanager/template"
@ -47,6 +48,14 @@ func (c *checkConfigCmd) checkConfig(ctx *kingpin.ParseContext) error {
} }
func CheckConfig(args []string) 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 failed := 0
for _, arg := range args { for _, arg := range args {