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-02 23:12:35 -06:00
|
|
|
"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-17 20:43:00 -06:00
|
|
|
log.Info(standardStart8("gopath", "cur name", "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-02 23:12:35 -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-17 20:43:00 -06:00
|
|
|
func standardStart8(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 string) string {
|
2024-12-17 13:11:14 -06:00
|
|
|
len1 := 40
|
|
|
|
len2 := 12
|
|
|
|
len3 := 16
|
|
|
|
len4 := 16
|
|
|
|
len5 := 16
|
|
|
|
len6 := 16
|
2024-12-17 20:43:00 -06:00
|
|
|
len7 := 16
|
|
|
|
len8 := 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-17 13:11:14 -06:00
|
|
|
return fmt.Sprintf(s, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
|
|
|
|
}
|
|
|
|
|
2024-12-03 00:33:17 -06:00
|
|
|
func verifyPrint(repo *gitpb.Repo) {
|
|
|
|
var end string
|
|
|
|
if repo.CheckDirty() {
|
|
|
|
end += "(dirty) "
|
2024-12-02 23:12:35 -06:00
|
|
|
}
|
2024-12-03 00:33:17 -06:00
|
|
|
s := make(map[string]string)
|
|
|
|
if !verify(repo, s) {
|
2024-12-17 06:36:00 -06:00
|
|
|
log.Info("going to delete", repo.GetGoPath())
|
2024-12-04 15:35:48 -06:00
|
|
|
if argv.Fix {
|
2024-12-17 06:36:00 -06:00
|
|
|
me.forge.DeleteByGoPath(repo.GetGoPath())
|
2024-12-03 00:33:17 -06:00
|
|
|
me.forge.Repos.ConfigSave()
|
|
|
|
} else {
|
2024-12-17 06:36:00 -06:00
|
|
|
log.Info("need argv --fix to delete", repo.GetGoPath())
|
2024-12-03 13:23:12 -06:00
|
|
|
}
|
2024-12-02 23:12:35 -06:00
|
|
|
}
|
2024-12-05 12:29:47 -06:00
|
|
|
|
2024-12-17 20:43:00 -06:00
|
|
|
var mhort string = s["mver"] // master version
|
|
|
|
var dhort string = s["dver"] // devel version
|
|
|
|
var uhort string = s["uver"] // user version
|
|
|
|
var thort string = s["tver"] // target version
|
|
|
|
var chort string = s["cver"] // current version
|
|
|
|
var cname string = s["cname"] // current branch name git is on now
|
2024-12-05 12:29:47 -06:00
|
|
|
|
|
|
|
// start := fmt.Sprintf("%-40s %-12s %-12s %-12s %-8s", s["gopath"], cname, mhort, uhort, s["rtype"])
|
2024-12-17 20:43:00 -06:00
|
|
|
start := standardStart8(s["gopath"], cname, thort, mhort, dhort, uhort, chort, s["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)
|
2024-12-02 23:12:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
2024-12-02 23:12:35 -06:00
|
|
|
|
|
|
|
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-02 23:12:35 -06:00
|
|
|
}
|
2024-12-17 06:36:00 -06:00
|
|
|
s["mver"] = repo.GetMasterVersion()
|
2024-12-02 23:12:35 -06:00
|
|
|
|
|
|
|
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
|
2024-12-02 23:12:35 -06:00
|
|
|
}
|
|
|
|
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
|
2024-12-02 23:12:35 -06:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|
2024-12-02 23:12:35 -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
|
|
|
}
|
2024-12-02 23:12:35 -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
|
|
|
}
|
2024-12-02 23:12:35 -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
|
2024-12-02 23:12:35 -06:00
|
|
|
|
|
|
|
return true
|
|
|
|
}
|