mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-21 03:16:00 -08:00
promtool: read from stdin if no filenames are provided in check rules
Signed-off-by: François Gouteroux <francois.gouteroux@gmail.com>
This commit is contained in:
parent
04ce186a4d
commit
ce00e8c7a8
|
@ -127,8 +127,8 @@ func main() {
|
||||||
checkRulesCmd := checkCmd.Command("rules", "Check if the rule files are valid or not.")
|
checkRulesCmd := checkCmd.Command("rules", "Check if the rule files are valid or not.")
|
||||||
ruleFiles := checkRulesCmd.Arg(
|
ruleFiles := checkRulesCmd.Arg(
|
||||||
"rule-files",
|
"rule-files",
|
||||||
"The rule files to check.",
|
"The rule files to check, default is read from standard input (STDIN).",
|
||||||
).Required().ExistingFiles()
|
).Default("-").Strings()
|
||||||
checkRulesLint := checkRulesCmd.Flag(
|
checkRulesLint := checkRulesCmd.Flag(
|
||||||
"lint",
|
"lint",
|
||||||
"Linting checks to apply. Available options are: "+strings.Join(lintOptions, ", ")+". Use --lint=none to disable linting",
|
"Linting checks to apply. Available options are: "+strings.Join(lintOptions, ", ")+". Use --lint=none to disable linting",
|
||||||
|
@ -724,9 +724,22 @@ func CheckRules(ls lintConfig, files ...string) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkRules(filename string, lintSettings lintConfig) (int, []error) {
|
func checkRules(filename string, lintSettings lintConfig) (int, []error) {
|
||||||
fmt.Println("Checking", filename)
|
var rgs *rulefmt.RuleGroups
|
||||||
|
var errs []error
|
||||||
|
if filename == "-" || filename == "" {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
tee := io.TeeReader(os.Stdin, &buf)
|
||||||
|
if _, err := buf.ReadFrom(tee); err != nil {
|
||||||
|
errs = append(errs, err)
|
||||||
|
return failureExitCode, errs
|
||||||
|
}
|
||||||
|
fmt.Println("Checking stdin")
|
||||||
|
rgs, errs = rulefmt.Parse(buf.Bytes())
|
||||||
|
} else {
|
||||||
|
fmt.Println("Checking", filename)
|
||||||
|
rgs, errs = rulefmt.ParseFile(filename)
|
||||||
|
}
|
||||||
|
|
||||||
rgs, errs := rulefmt.ParseFile(filename)
|
|
||||||
if errs != nil {
|
if errs != nil {
|
||||||
return successExitCode, errs
|
return successExitCode, errs
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,9 +181,9 @@ Check if the rule files are valid or not.
|
||||||
|
|
||||||
###### Arguments
|
###### Arguments
|
||||||
|
|
||||||
| Argument | Description | Required |
|
| Argument | Description | Default |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| rule-files | The rule files to check. | Yes |
|
| rule-files | The rule files to check, default is read from standard input (STDIN). | `-` |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue