Skip to content

Commit

Permalink
Print plugin version
Browse files Browse the repository at this point in the history
  • Loading branch information
gmgigi96 committed Oct 26, 2023
1 parent 3595835 commit cba8c16
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cmd/revad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"path"
"reflect"
"regexp"
"runtime/debug"
"strings"
"sync"
"syscall"
Expand Down Expand Up @@ -123,12 +124,17 @@ func handlePluginsFlag() {
// For now we just list all the plugins.
plugins := reva.GetPlugins("")
grouped := groupByNamespace(plugins)
bi, ok := debug.ReadBuildInfo()
if !ok {
bi = &debug.BuildInfo{}
}

count := 0
for ns, plugins := range grouped {
fmt.Printf("[%s]\n", ns)
for _, p := range plugins {
fmt.Printf("%s -> %s\n", p.ID.Name(), pkgOfFunction(p.New))
pkgName := pkgOfFunction(p.New)
fmt.Printf("%s -> %s (%s)\n", p.ID.Name(), pkgName, pkgVersion(bi.Deps, pkgName))
}
count++
if len(grouped) != count {
Expand All @@ -148,6 +154,15 @@ func pkgOfFunction(f any) string {
return name[:i]
}

func pkgVersion(deps []*debug.Module, name string) string {
for _, dep := range deps {
if strings.HasPrefix(name, dep.Path) {
return dep.Version
}
}
return "<unknown>"
}

func groupByNamespace(plugins []reva.PluginInfo) map[string][]reva.PluginInfo {
m := make(map[string][]reva.PluginInfo)
for _, p := range plugins {
Expand Down

0 comments on commit cba8c16

Please sign in to comment.