Skip to content

Commit

Permalink
Merge pull request #41 from FUSAKLA/rudo-make-version-work
Browse files Browse the repository at this point in the history
fix: Make "promruval version" not require --config-file.
  • Loading branch information
rudo-thomas authored Feb 1, 2024
2 parents 279c750 + 524c21a commit f3994e6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
- Upgrade all dependencies
- Fix: `promruval version` now works without specifying `--config-file`

## [v2.7.0] - 2023-12-06
- Added new validator `expressionDoesNotUseMetrics`, see its [docs](docs/validations.md#expressiondoesnotusemetrics).
Expand Down
13 changes: 10 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var (
builtBy = os.Getenv("USER")

app = kingpin.New("promruval", "Prometheus rules validation tool.")
validateConfigFiles = app.Flag("config-file", "Path to validation config file. Can be passed multiple times, only validationRules will be reflected from the additional configs.").Short('c').Required().ExistingFiles()
validateConfigFiles = app.Flag("config-file", "Path to validation config file. Can be passed multiple times, only validationRules will be reflected from the additional configs.").Short('c').ExistingFiles()
debug = app.Flag("debug", "Enable debug logging.").Bool()

versionCmd = app.Command("version", "Print version and build information.")
Expand Down Expand Up @@ -95,6 +95,15 @@ func main() {

currentCommand := kingpin.MustParse(app.Parse(os.Args[1:]))

if currentCommand == versionCmd.FullCommand() {
fmt.Printf("Version: %s\nBuild date: %s\nBuild commit: %s\nBuilt by: %s\n", version, date, commit, builtBy)
return
}

if len(*validateConfigFiles) == 0 {
app.Fatalf("required flag --config-file not provided, try --help")
}

mainValidationConfig, err := loadConfigFile((*validateConfigFiles)[0])
if err != nil {
exitWithError(err)
Expand All @@ -121,8 +130,6 @@ func main() {
}

switch currentCommand {
case versionCmd.FullCommand():
fmt.Printf("Version: %s\nBuild date: %s\nBuild commit: %s\nBuilt by: %s\n", version, date, commit, builtBy)
case docsCmd.FullCommand():
var reportRules []report.ValidationRule
for _, r := range validationRules {
Expand Down

0 comments on commit f3994e6

Please sign in to comment.