smarter human table code

This commit is contained in:
Jeff Carr 2025-04-04 06:07:23 -05:00
parent d27ad541f1
commit 050d93d401
3 changed files with 75 additions and 67 deletions

View File

@ -14,6 +14,7 @@ import "google/protobuf/timestamp.proto"; // Import the well-known type for Time
// package names sometimes must be different than the binary name
// for example 'zookeeper' is packaged as 'zookeeper-go'
// due to the prior apache foundation project. This happens and is ok!
message ForgeConfig { // `autogenpb:nomutex`
string goPath = 1; // `autogenpb:unique` `autogenpb:sort` // Examples: 'go.wit.com/apps/go-clone' or "~/mythings" or "/home/src/foo"
@ -35,8 +36,6 @@ message ForgeConfig { // `autogenpb:nom
google.protobuf.Timestamp verstamp = 12; // the git commit timestamp of the version
string goSrc = 13; // is ~/go/src unless a go.work file is found
}
// todo: fix autogenpb to look for enum
enum ForgeMode {
MASTER = 0; // "release mode"
DEVEL = 1; // "patch mode"
@ -53,10 +52,10 @@ message ForgeConfigs { // `autogenpb:mar
string defaultGui = 7; // default GUI plugin to use
ForgeMode mode = 8; // what "mode" forge is in
}
// this generic message is used by autogen to identify and
// then dump the uuid and version from any arbitrary .pb file
message Identify { // `autogenpb:marshal`
string uuid = 1; //
string version = 2; //
}
// footer was empty

View File

@ -39,12 +39,35 @@ func (f *Forge) PrintHumanTable(allr *gitpb.Repos) {
log.DaemonMode(true)
var count int
// log.Info(standardStart5("gopath", "cur name", "master", "user", "repo type"))
log.Info(standardTable10("repopath", "cur br", "age", "master", "devel", "user", "curver", "lasttag", "next", "repo type"))
// print the header
args := []string{"repopath", "cur br", "age", "master", "devel", "user", "curver", "lasttag", "next", "repo type"}
sizes := []int{40, 12, 6, 12, 16, 16, 16, 12, 12, 8}
log.Info(standardTableSize10(sizes, args))
all := allr.SortByFullPath()
for all.Scan() {
repo := all.Next()
f.printRepoToTable(repo)
f.printRepoToTable(repo, sizes, false)
count += 1
}
log.Info("Total git repositories:", count)
}
func (f *Forge) PrintHumanTableFull(allr *gitpb.Repos) {
log.DaemonMode(true)
var count int
// print the header
args := []string{"cur br", "age", "master", "devel", "user", "curver", "lasttag", "next", "repo type", "repopath"}
sizes := []int{12, 6, 12, 16, 16, 16, 12, 12, 8, 0}
log.Info(standardTableSize10(sizes, args))
all := allr.SortByFullPath()
for all.Scan() {
repo := all.Next()
f.printRepoToTable(repo, sizes, true)
count += 1
}
log.Info("Total git repositories:", count)
@ -55,11 +78,14 @@ func (f *Forge) PrintHumanTableDirty(allr *gitpb.Repos) {
log.DaemonMode(true)
var count int
// log.Info(standardStart5("gopath", "cur name", "master", "user", "repo type"))
log.Info(standardTable10("repopath", "cur br", "age", "master", "devel", "user", "curver", "lasttag", "next", "repo type"))
// all := allr.SortByFullPath()
// print the header
args := []string{"repopath", "cur br", "age", "master", "devel", "user", "curver", "lasttag", "next", "repo type"}
sizes := []int{40, 12, 6, 12, 16, 16, 16, 12, 12, 8}
log.Info(standardTableSize10(sizes, args))
for repo := range allr.IterAll() {
f.printRepoToTable(repo)
f.printRepoToTable(repo, sizes, false)
if len(repo.DirtyList) != 0 {
for _, line := range repo.DirtyList {
log.Info("\t", line)
@ -103,69 +129,44 @@ func standardTable5(arg1, arg2, arg3, arg4, arg5 string) string {
return fmt.Sprintf(s, arg1, arg2, arg3, arg4, arg5)
}
/*
func standardTable10(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10 string) string {
len1 := 40
len2 := 12
len3 := 6
len4 := 12
len5 := 16
len6 := 16
len7 := 16
len8 := 12
len9 := 12
len10 := 8
args := []string{arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10}
sizes := []int{40, 12, 6, 12, 16, 16, 16, 12, 12, 8}
return standardTableSize10(sizes, args)
}
*/
func standardTableSize10(sizes []int, args []string) string {
var s string
if len(arg1) > len1 {
arg1 = arg1[:len1]
for i, si := range sizes {
if si == 0 {
s += "%-s "
} else {
s += "%-" + fmt.Sprintf("%d", si) + "s "
if len(args[i]) > sizes[i] {
args[i] = args[i][:sizes[i]]
}
}
}
s = "%-" + fmt.Sprintf("%d", len1) + "s "
if len(arg2) > len2 {
arg2 = arg2[:len2]
}
s += "%-" + fmt.Sprintf("%d", len2) + "s "
if len(arg3) > len3 {
arg3 = arg3[:len3]
}
s += "%-" + fmt.Sprintf("%d", len3) + "s "
if len(arg4) > len4 {
arg4 = arg4[:len4]
}
s += "%-" + fmt.Sprintf("%d", len4) + "s "
if len(arg5) > len5 {
arg5 = arg5[:len5]
}
s += "%-" + fmt.Sprintf("%d", len5) + "s "
if len(arg6) > len6 {
arg6 = arg6[:len6]
}
s += "%-" + fmt.Sprintf("%d", len6) + "s "
if len(arg7) > len7 {
arg7 = arg7[:len7]
}
s += "%-" + fmt.Sprintf("%d", len7) + "s "
if len(arg8) > len8 {
arg8 = arg8[:len8]
}
s += "%-" + fmt.Sprintf("%d", len8) + "s "
if len(arg9) > len9 {
arg9 = arg9[:len9]
}
s += "%-" + fmt.Sprintf("%d", len9) + "s "
if len(arg10) > len10 {
arg10 = arg10[:len10]
}
s += "%-" + fmt.Sprintf("%d", len10) + "s "
// there must be a better syntax for this
arg1 := args[0]
arg2 := args[1]
arg3 := args[2]
arg4 := args[3]
arg5 := args[4]
arg6 := args[5]
arg7 := args[6]
arg8 := args[7]
arg9 := args[8]
arg10 := args[9]
return fmt.Sprintf(s, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10)
// return fmt.Sprintf(s, args)
}
func (f *Forge) printRepoToTable(repo *gitpb.Repo) {
func (f *Forge) printRepoToTable(repo *gitpb.Repo, sizes []int, full bool) {
var end string
// shortened version numbers
@ -199,7 +200,13 @@ func (f *Forge) printRepoToTable(repo *gitpb.Repo) {
end += "(dirty) "
}
start := standardTable10(gopath, cname, age, mhort, dhort, uhort, chort, lasttag, thort, rtype)
var args []string
if full {
args = []string{cname, age, mhort, dhort, uhort, chort, lasttag, thort, rtype, gopath}
} else {
args = []string{gopath, cname, age, mhort, dhort, uhort, chort, lasttag, thort, rtype}
}
start := standardTableSize10(sizes, args)
if rtype == "protobuf" {
if repo.GoInfo.GoBinary {

View File

@ -28,6 +28,7 @@ import "google/protobuf/timestamp.proto"; // Import the well-known type for Time
// }
// git log -1 --format="%H %aI %cI %an %ae %cn %ce"
message Patch {
string repoNamespace = 1; // the base repo git URL
bytes data = 2; // the raw data of the whole patch
@ -85,3 +86,4 @@ message Patchsets { // `autogenpb:mars
string version = 2; // `autogenpb:version:v0.0.45`
repeated Patchset Patchsets = 3;
}
// footer was empty