mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-29 22:51:36 -08:00
fix: apply suggested changes
Signed-off-by: François Gouteroux <francois.gouteroux@gmail.com>
This commit is contained in:
parent
ce00e8c7a8
commit
488ece2899
|
@ -128,7 +128,7 @@ func main() {
|
||||||
ruleFiles := checkRulesCmd.Arg(
|
ruleFiles := checkRulesCmd.Arg(
|
||||||
"rule-files",
|
"rule-files",
|
||||||
"The rule files to check, default is read from standard input (STDIN).",
|
"The rule files to check, default is read from standard input (STDIN).",
|
||||||
).Default("-").Strings()
|
).ExistingFiles()
|
||||||
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",
|
||||||
|
@ -699,6 +699,11 @@ func CheckRules(ls lintConfig, files ...string) int {
|
||||||
failed := false
|
failed := false
|
||||||
hasErrors := false
|
hasErrors := false
|
||||||
|
|
||||||
|
// add empty string to avoid matching filename
|
||||||
|
if len(files) == 0 {
|
||||||
|
files = append(files, "")
|
||||||
|
}
|
||||||
|
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
if n, errs := checkRules(f, ls); errs != nil {
|
if n, errs := checkRules(f, ls); errs != nil {
|
||||||
fmt.Fprintln(os.Stderr, " FAILED:")
|
fmt.Fprintln(os.Stderr, " FAILED:")
|
||||||
|
@ -726,15 +731,16 @@ func CheckRules(ls lintConfig, files ...string) int {
|
||||||
func checkRules(filename string, lintSettings lintConfig) (int, []error) {
|
func checkRules(filename string, lintSettings lintConfig) (int, []error) {
|
||||||
var rgs *rulefmt.RuleGroups
|
var rgs *rulefmt.RuleGroups
|
||||||
var errs []error
|
var errs []error
|
||||||
if filename == "-" || filename == "" {
|
|
||||||
var buf bytes.Buffer
|
// if filename is an empty string it is a stdin
|
||||||
tee := io.TeeReader(os.Stdin, &buf)
|
if filename == "" {
|
||||||
if _, err := buf.ReadFrom(tee); err != nil {
|
data, err := io.ReadAll(os.Stdin)
|
||||||
|
if err != nil {
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
return failureExitCode, errs
|
return failureExitCode, errs
|
||||||
}
|
}
|
||||||
fmt.Println("Checking stdin")
|
fmt.Println("Checking stdin")
|
||||||
rgs, errs = rulefmt.Parse(buf.Bytes())
|
rgs, errs = rulefmt.Parse(data)
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Checking", filename)
|
fmt.Println("Checking", filename)
|
||||||
rgs, errs = rulefmt.ParseFile(filename)
|
rgs, errs = rulefmt.ParseFile(filename)
|
||||||
|
|
|
@ -181,9 +181,9 @@ Check if the rule files are valid or not.
|
||||||
|
|
||||||
###### Arguments
|
###### Arguments
|
||||||
|
|
||||||
| Argument | Description | Default |
|
| Argument | Description |
|
||||||
| --- | --- | --- |
|
| --- | --- |
|
||||||
| rule-files | The rule files to check, default is read from standard input (STDIN). | `-` |
|
| rule-files | The rule files to check, default is read from standard input (STDIN). |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue