forge/cobol.go

212 lines
5.2 KiB
Go
Raw Normal View History

2024-12-02 06:59:56 -06:00
package main
import (
2024-12-02 15:45:06 -06:00
"fmt"
2024-12-02 06:59:56 -06:00
2024-12-18 22:02:07 -06:00
"go.wit.com/lib/gui/shell"
"go.wit.com/lib/protobuf/gitpb"
2024-12-02 06:59:56 -06:00
"go.wit.com/log"
)
2024-12-05 12:29:47 -06:00
// ah yes, COBOL. what a throwback. for those that know
// then you know exactly what is in this file. For those that don't, here it is:
// All this does is output human readable text formatted to be viewable on
// a console with a fixed with font. AKA: a typerwriter. Which is exactly
// what COBOL did in the 1970's (60s? notsure) And the 80s.
// So, you want to dump out stuff on the console. Let's see. Something like
/*
forge --favorites
go.wit.com/apps/myapp v0.2.0 (installed)
go.wit.com/lib/somethingfun v0.0.7 (not downloaded)
*/
// anyway, you get the idea. This is also called COBOL because it does on
// thing and truncates every line output to the columns you see with stty -a
// my monitor is huge, so it's not going to work at 80x24. 160x48 is better
// actually, I'd predict some of these will probably end up 240 wide
// long live good eyesight and 4K monitors!
func doCobol() {
2024-12-03 00:33:17 -06:00
log.DaemonMode(true)
2024-12-02 06:59:56 -06:00
2024-12-17 13:11:14 -06:00
// log.Info(standardStart5("gopath", "cur name", "master", "user", "repo type"))
2024-12-27 04:36:29 -06:00
log.Info(standardStart8("repopath", "cur name", "age", "target", "master", "devel", "user", "curver", "repo type"))
2024-12-17 06:36:00 -06:00
all := me.found.SortByFullPath()
2024-12-11 19:32:04 -06:00
for all.Scan() {
repo := all.Next()
2024-12-05 12:29:47 -06:00
verifyPrint(repo)
2024-12-02 06:59:56 -06:00
}
}
2024-12-05 12:29:47 -06:00
func standardStart5(arg1, arg2, arg3, arg4, arg5 string) string {
len1 := 40
len2 := 12
len3 := 12
len4 := 16
len5 := 8
var s string
if len(arg1) > len1 {
arg1 = arg1[:len1]
}
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"
return fmt.Sprintf(s, arg1, arg2, arg3, arg4, arg5)
}
2024-12-18 22:02:07 -06:00
func standardStart8(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 string) string {
2024-12-17 13:11:14 -06:00
len1 := 40
len2 := 12
2024-12-18 22:02:07 -06:00
len3 := 6
2024-12-17 13:11:14 -06:00
len4 := 16
len5 := 16
len6 := 16
2024-12-17 20:43:00 -06:00
len7 := 16
2024-12-18 22:02:07 -06:00
len8 := 16
len9 := 8
2024-12-17 13:11:14 -06:00
var s string
if len(arg1) > len1 {
arg1 = arg1[:len1]
}
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]
}
2024-12-17 20:43:00 -06:00
s += "%-" + fmt.Sprintf("%d", len5) + "s "
2024-12-17 13:11:14 -06:00
if len(arg6) > len6 {
arg6 = arg6[:len6]
}
2024-12-17 20:43:00 -06:00
s += "%-" + fmt.Sprintf("%d", len6) + "s "
2024-12-17 13:11:14 -06:00
if len(arg7) > len7 {
arg7 = arg7[:len7]
}
2024-12-17 20:43:00 -06:00
s += "%-" + fmt.Sprintf("%d", len7) + "s "
if len(arg8) > len8 {
arg8 = arg8[:len8]
}
s += "%-" + fmt.Sprintf("%d", len8) + "s"
2024-12-18 22:02:07 -06:00
if len(arg9) > len9 {
arg9 = arg9[:len9]
}
s += "%-" + fmt.Sprintf("%d", len9) + "s"
return fmt.Sprintf(s, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
2024-12-17 13:11:14 -06:00
}
2024-12-03 00:33:17 -06:00
func verifyPrint(repo *gitpb.Repo) {
var end string
2024-12-18 22:02:07 -06:00
if repo.IsDirty() {
2024-12-03 00:33:17 -06:00
end += "(dirty) "
}
2024-12-27 04:36:29 -06:00
// s := make(map[string]string)
/*
if !verify(repo, s) {
log.Info("going to delete", repo.GetGoPath())
if argv.Fix {
me.forge.DeleteByGoPath(repo.GetGoPath())
me.forge.Repos.ConfigSave()
} else {
log.Info("need argv --fix to delete", repo.GetGoPath())
}
2024-12-03 13:23:12 -06:00
}
2024-12-27 04:36:29 -06:00
*/
var mhort string = repo.GetMasterVersion()
var dhort string = repo.GetDevelVersion()
var uhort string = repo.GetUserVersion()
var thort string = repo.GetTargetVersion()
var chort string = repo.GetCurrentBranchVersion()
var cname string = repo.GetCurrentBranchName()
2024-12-05 12:29:47 -06:00
2024-12-27 04:36:29 -06:00
var gopath string = repo.GetGoPath()
var rtype string = repo.GetRepoType()
2024-12-05 12:29:47 -06:00
2024-12-18 22:02:07 -06:00
age := shell.FormatDuration(repo.NewestAge())
2024-12-27 04:36:29 -06:00
start := standardStart8(gopath, cname, age, thort, mhort, dhort, uhort, chort, rtype)
2024-12-04 15:35:48 -06:00
2024-12-17 06:36:00 -06:00
if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
2024-12-03 13:23:12 -06:00
end += "(readonly) "
}
2024-12-04 15:35:48 -06:00
2024-12-03 00:33:17 -06:00
log.Info(start, end)
}
func verify(repo *gitpb.Repo, s map[string]string) bool {
s["gopath"] = repo.GetGoPath()
2024-12-17 06:36:00 -06:00
s["rtype"] = repo.GetRepoType()
s["mname"] = repo.GetMasterBranchName()
if s["mname"] == "" {
2024-12-17 06:36:00 -06:00
log.Info("verify() no master branch name", repo.FullPath)
2024-12-03 00:33:17 -06:00
s["mver"] = repo.GetMasterVersion()
2024-12-17 06:36:00 -06:00
// return false
}
2024-12-17 06:36:00 -06:00
s["mver"] = repo.GetMasterVersion()
s["dname"] = repo.GetDevelBranchName()
if s["dname"] == "" {
2024-12-17 06:36:00 -06:00
log.Info("verify() no devel branch name", repo.GetGoPath())
// return false
}
s["uname"] = repo.GetUserBranchName()
if s["uname"] == "" {
2024-12-17 06:36:00 -06:00
log.Info("verify() no user branch name", repo.GetGoPath())
// return false
}
s["cname"] = repo.GetCurrentBranchName()
s["mver"] = repo.GetMasterVersion()
2024-12-03 01:56:58 -06:00
if s["mver"] == "" {
2024-12-17 06:36:00 -06:00
log.Info("verify() no master branch name", repo.FullPath, repo.GetMasterBranchName())
2024-12-03 01:56:58 -06:00
}
s["dver"] = repo.GetDevelVersion()
2024-12-03 01:56:58 -06:00
if s["dver"] == "" {
2024-12-17 06:36:00 -06:00
log.Info("verify() no devel branch name", repo.GetGoPath(), repo.GetDevelBranchName())
2024-12-03 01:56:58 -06:00
}
s["uver"] = repo.GetUserVersion()
2024-12-03 01:56:58 -06:00
if s["uver"] == "" {
2024-12-17 06:36:00 -06:00
log.Info("verify() no user branch name", repo.GetGoPath(), repo.GetUserBranchName())
2024-12-03 01:56:58 -06:00
}
s["cver"] = repo.GetCurrentBranchVersion()
2024-12-17 13:11:14 -06:00
s["tver"] = repo.GetTargetVersion()
2024-12-03 01:56:58 -06:00
s["url"] = repo.URL
return true
}