mirror of
https://github.com/EnumeratedDev/bpm-utils.git
synced 2026-09-16 02:56:11 +00:00
Add 'list packages' flag to bpm-repo
This commit is contained in:
@@ -5,8 +5,11 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"maps"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"slices"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
flag "github.com/spf13/pflag"
|
flag "github.com/spf13/pflag"
|
||||||
@@ -14,6 +17,7 @@ import (
|
|||||||
|
|
||||||
var createRepo = flag.BoolP("create", "c", false, "Create a new BPM repository")
|
var createRepo = flag.BoolP("create", "c", false, "Create a new BPM repository")
|
||||||
var updateDatabases = flag.BoolP("update-databases", "u", false, "Update update source and binary databases in current repository")
|
var updateDatabases = flag.BoolP("update-databases", "u", false, "Update update source and binary databases in current repository")
|
||||||
|
var listPackages = flag.BoolP("list", "l", false, "List packages")
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Setup flags and help
|
// Setup flags and help
|
||||||
@@ -48,6 +52,14 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bpmutilsshared.UpdateDatabases(repo)
|
bpmutilsshared.UpdateDatabases(repo)
|
||||||
|
} else if *listPackages {
|
||||||
|
// Get current database
|
||||||
|
repo := bpmutilsshared.GetRepository()
|
||||||
|
if repo == "" {
|
||||||
|
log.Fatal("Error: this command may only be run inside a BPM repository")
|
||||||
|
}
|
||||||
|
|
||||||
|
listPacakges(repo)
|
||||||
} else {
|
} else {
|
||||||
bpmutilsshared.ShowHelp()
|
bpmutilsshared.ShowHelp()
|
||||||
}
|
}
|
||||||
@@ -67,3 +79,46 @@ func createRepository(name, description string) {
|
|||||||
|
|
||||||
fmt.Println("Repository created successfully!")
|
fmt.Println("Repository created successfully!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func listPacakges(repo string) {
|
||||||
|
// Read databases
|
||||||
|
sourceDatabase, err := bpmutilsshared.ReadDatabase(path.Join(repo, "source/database.bpmdb"))
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
binaryDatabase, err := bpmutilsshared.ReadDatabase(path.Join(repo, "binary/database.bpmdb"))
|
||||||
|
if err != nil {
|
||||||
|
binaryDatabase = &bpmutilsshared.BPMDatabase{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort database entries
|
||||||
|
entriesSorted := slices.Collect(maps.Values(sourceDatabase.Entries))
|
||||||
|
sort.Slice(entriesSorted, func(i, j int) bool {
|
||||||
|
return entriesSorted[i].PackageInfo.Name < entriesSorted[j].PackageInfo.Name
|
||||||
|
})
|
||||||
|
|
||||||
|
// Loop through each entry
|
||||||
|
for _, entry := range entriesSorted {
|
||||||
|
if len(entry.PackageInfo.SplitPackages) > 0 {
|
||||||
|
for _, splitPkg := range entry.PackageInfo.SplitPackages {
|
||||||
|
// Handle split packages
|
||||||
|
additionalText := ""
|
||||||
|
if binaryEntry, ok := binaryDatabase.Entries[splitPkg.Name]; !ok {
|
||||||
|
additionalText += "(Binary package missing) "
|
||||||
|
} else if fmt.Sprintf("%s-%d", binaryEntry.PackageInfo.Version, binaryEntry.PackageInfo.Revision) != fmt.Sprintf("%s-%d", entry.PackageInfo.Version, entry.PackageInfo.Revision) {
|
||||||
|
additionalText += "(Binary package version mismatch) "
|
||||||
|
}
|
||||||
|
fmt.Printf("%s %s-%d %s\n", splitPkg.Name, entry.PackageInfo.Version, entry.PackageInfo.Revision, additionalText)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
additionalText := ""
|
||||||
|
if binaryEntry, ok := binaryDatabase.Entries[entry.PackageInfo.Name]; !ok {
|
||||||
|
additionalText += "(Binary package missing) "
|
||||||
|
} else if fmt.Sprintf("%s-%d", binaryEntry.PackageInfo.Version, binaryEntry.PackageInfo.Revision) != fmt.Sprintf("%s-%d", entry.PackageInfo.Version, entry.PackageInfo.Revision) {
|
||||||
|
additionalText += "(Binary package version mismatch) "
|
||||||
|
}
|
||||||
|
fmt.Printf("%s %s-%d %s\n", entry.PackageInfo.Name, entry.PackageInfo.Version, entry.PackageInfo.Revision, additionalText)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user