summaryrefslogtreecommitdiff
path: root/cobol.go
blob: 793075e488811c72b52efe2f04fb00dd96fcd63a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package main

import (
	"fmt"

	"go.wit.com/lib/protobuf/gitpb"
	"go.wit.com/log"
)

// 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() {
	log.DaemonMode(true)

	// log.Info(standardStart5("gopath", "cur name", "master", "user", "repo type"))
	log.Info(standardStart8("gopath", "cur name", "target", "master", "devel", "user", "curver", "repo type"))
	all := me.found.SortByFullPath()
	for all.Scan() {
		repo := all.Next()
		verifyPrint(repo)
	}
}

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)
}

func standardStart8(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 string) string {
	len1 := 40
	len2 := 12
	len3 := 16
	len4 := 16
	len5 := 16
	len6 := 16
	len7 := 16
	len8 := 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   "

	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"

	return fmt.Sprintf(s, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
}

func verifyPrint(repo *gitpb.Repo) {
	var end string
	if repo.CheckDirty() {
		end += "(dirty) "
	}
	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())
		}
	}

	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

	// start := fmt.Sprintf("%-40s %-12s %-12s %-12s %-8s", s["gopath"], cname, mhort, uhort, s["rtype"])
	start := standardStart8(s["gopath"], cname, thort, mhort, dhort, uhort, chort, s["rtype"])

	if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
		end += "(readonly) "
	}

	log.Info(start, end)
}

func verify(repo *gitpb.Repo, s map[string]string) bool {
	s["gopath"] = repo.GetGoPath()
	s["rtype"] = repo.GetRepoType()

	s["mname"] = repo.GetMasterBranchName()
	if s["mname"] == "" {
		log.Info("verify() no master branch name", repo.FullPath)
		s["mver"] = repo.GetMasterVersion()
		// return false
	}
	s["mver"] = repo.GetMasterVersion()

	s["dname"] = repo.GetDevelBranchName()
	if s["dname"] == "" {
		log.Info("verify() no devel branch name", repo.GetGoPath())
		// return false
	}
	s["uname"] = repo.GetUserBranchName()
	if s["uname"] == "" {
		log.Info("verify() no user branch name", repo.GetGoPath())
		// return false
	}
	s["cname"] = repo.GetCurrentBranchName()

	s["mver"] = repo.GetMasterVersion()
	if s["mver"] == "" {
		log.Info("verify() no master branch name", repo.FullPath, repo.GetMasterBranchName())
	}
	s["dver"] = repo.GetDevelVersion()
	if s["dver"] == "" {
		log.Info("verify() no devel branch name", repo.GetGoPath(), repo.GetDevelBranchName())
	}
	s["uver"] = repo.GetUserVersion()
	if s["uver"] == "" {
		log.Info("verify() no user branch name", repo.GetGoPath(), repo.GetUserBranchName())
	}
	s["cver"] = repo.GetCurrentBranchVersion()
	s["tver"] = repo.GetTargetVersion()
	s["url"] = repo.URL

	return true
}