forgepb/human.go

89 lines
2.0 KiB
Go
Raw Normal View History

2024-11-20 12:11:13 -06:00
package forgepb
import (
"fmt"
2024-12-02 07:01:09 -06:00
"time"
2024-12-02 07:01:09 -06:00
"go.wit.com/lib/gui/shell"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
2024-11-20 12:11:13 -06:00
// mostly just functions related to making STDOUT
// more readable by us humans
// also function shortcuts the do fixed limited formatting (it's like COBOL)
// so reporting tables of the status of what droplets and hypervisors
// are in text columns and rows that can be easily read in a terminal
func standardHeader() string {
2024-11-25 00:46:16 -06:00
return fmt.Sprintf("%-4s %-40s %s", "", "Path", "flags")
}
2024-11-28 00:02:27 -06:00
func (f *Forge) standardHeader(r *ForgeConfig) string {
var flags string
var readonly string
2024-11-28 00:02:27 -06:00
if f.IsPrivate(r.GoPath) {
flags += "(private) "
}
2024-11-28 00:02:27 -06:00
if f.IsFavorite(r.GoPath) {
2024-11-25 00:46:16 -06:00
flags += "(favorite) "
}
2024-12-03 13:24:41 -06:00
if f.Config.IsReadOnly(r.GoPath) {
readonly = ""
} else {
readonly = "r/w"
}
return fmt.Sprintf("%-4s %-40s %s", readonly, r.GoPath, flags)
}
// print a human readable table to STDOUT
2024-11-28 00:02:27 -06:00
func (f *Forge) ConfigPrintTable() {
if f == nil {
2024-12-01 22:36:36 -06:00
return
}
log.Info(standardHeader())
2024-11-30 15:33:53 -06:00
loop := f.Config.SortByGoPath()
for loop.Scan() {
r := loop.Next()
2024-11-28 00:02:27 -06:00
log.Info(f.standardHeader(r))
}
}
2024-12-02 07:01:09 -06:00
func (f *Forge) newestAge(repo *gitpb.Repo) time.Duration {
loop := repo.Tags.SortByAge()
for loop.Scan() {
r := loop.Next()
return time.Since(r.GetAuthordate().AsTime())
}
return time.Since(time.Now())
}
// show information while doing golang releases
func (f *Forge) StandardReleaseHeader(repo *gitpb.Repo, state string) string {
lastTag := repo.GetLastTag()
// tag := repo.NewestTag()
// gitAge, _ := tag.GetDate()
dur := f.newestAge(repo)
curname := repo.GetCurrentBranchName()
master := repo.GetMasterVersion()
user := repo.GetUserVersion()
target := repo.GetTargetVersion()
header := fmt.Sprintf("%-35s %5s %-10s %-10s %-10s %-20s %-20s %-15s",
repo.GetGoPath(), shell.FormatDuration(dur), curname,
lastTag, target,
master, user,
state)
return header
}
func ReleaseReportHeader() string {
return fmt.Sprintf("%-35s %5s %-10s %-10s %-10s %-20s %-20s %-15s",
"REPO", "AGE", "CUR BR",
"LAST", "TARGET",
"MASTER", "USER",
"STATE")
}