bpm-repo: add 'apply' flag to 'check-versions' subcommand

This commit is contained in:
2026-01-11 11:50:03 +02:00
parent 07a9e8c9d2
commit bf9874af6b
+20
View File
@@ -3,6 +3,7 @@ package main
import ( import (
bpmutilsshared "bpm-utils-shared" bpmutilsshared "bpm-utils-shared"
"bufio" "bufio"
"bytes"
"context" "context"
"fmt" "fmt"
"io/fs" "io/fs"
@@ -85,6 +86,7 @@ func main() {
flagset := flag.NewFlagSet("check-versions", flag.ExitOnError) flagset := flag.NewFlagSet("check-versions", flag.ExitOnError)
flagset.BoolP("verbose", "v", false, "Show additional information about the current operation") flagset.BoolP("verbose", "v", false, "Show additional information about the current operation")
flagset.BoolP("force", "f", false, "Force current operation to bypass certain conditions") flagset.BoolP("force", "f", false, "Force current operation to bypass certain conditions")
flagset.BoolP("apply", "a", false, "Apply new versions to packages")
setupFlagsAndHelp(flagset, fmt.Sprintf("bpm-repo %s <options>", subcommand), "Manage BPM repositories and databases", os.Args[2:]) setupFlagsAndHelp(flagset, fmt.Sprintf("bpm-repo %s <options>", subcommand), "Manage BPM repositories and databases", os.Args[2:])
currentFlagSet = flagset currentFlagSet = flagset
@@ -126,6 +128,7 @@ func checkVersionsFunc(repo string) {
// Get flags // Get flags
verbose, _ := currentFlagSet.GetBool("verbose") verbose, _ := currentFlagSet.GetBool("verbose")
force, _ := currentFlagSet.GetBool("force") force, _ := currentFlagSet.GetBool("force")
apply, _ := currentFlagSet.GetBool("apply")
// Read environment files // Read environment files
err := readEnvFile(repo) err := readEnvFile(repo)
@@ -241,6 +244,23 @@ func checkVersionsFunc(repo string) {
OldVersion: pkgInfo.Version, OldVersion: pkgInfo.Version,
NewVersion: latestVersion, NewVersion: latestVersion,
} }
// Apply new version
pkgInfo.Version = latestVersion
pkgInfo.Revision = 1
if apply {
var data bytes.Buffer
encoder := yaml.NewEncoder(&data)
encoder.SetIndent(2)
encoder.Encode(pkgInfo)
fmt.Println(path.Join(dir, "pkg.info"))
err := os.WriteFile(path.Join(dir, "pkg.info"), data.Bytes(), 0644)
if err != nil {
log.Printf("Warning: could not write new version for package (%s) to file: %s", pkgInfo.Name, err)
}
}
continue continue
} }