summaryrefslogtreecommitdiff
path: root/human.go
blob: dbbd6278dbc7a124dba14c3621255044e162912b (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
// Copyright 2025 WIT.COM Inc Licensed GPL 3.0

package forgepb

import (
	"fmt"
	"path/filepath"

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

// 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 {
	return fmt.Sprintf("%-4s %-40s %s", "", "Path", "flags")
}

func (f *Forge) standardHeader(r *ForgeConfig) string {
	var flags string
	var readonly string
	if f.Config.IsPrivate(r.GoPath) {
		flags += "(private) "
	}
	if f.Config.IsFavorite(r.GoPath) {
		flags += "(favorite) "
	}
	if f.Config.IsReadOnly(r.GoPath) {
		readonly = ""
	} else {
		readonly = "r/w"
	}
	if r.MasterBranchName != "" {
		flags += "(master=" + r.MasterBranchName + ") "
	}
	if r.DevelBranchName != "" {
		flags += "(devel=" + r.DevelBranchName + ") "
	}
	if r.UserBranchName != "" {
		flags += "(user=" + r.UserBranchName + ") "
	}
	if r.DebName != "" {
		flags += "(deb=" + r.DebName + ") "
	}
	return fmt.Sprintf("%-4s %-40s %s", readonly, r.GoPath, flags)
}

// print a human readable table to STDOUT
func (f *Forge) ConfigPrintTable() {
	if f == nil {
		return
	}
	log.Info(standardHeader())
	all := f.Config.All()
	for all.Scan() {
		r := all.Next()
		log.Info(f.standardHeader(r))
	}
}

// show information while doing golang releases
func (f *Forge) StandardReleaseHeader(repo *gitpb.Repo, state string) string {
	// tag := repo.NewestTag()
	// gitAge, _ := tag.GetDate()
	dur := repo.NewestAge()

	curname := repo.GetCurrentBranchName()

	lastTag := repo.GetLastTag()
	target := repo.GetTargetVersion()
	master := repo.GetMasterVersion()
	user := repo.GetUserVersion()

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

func (f *Forge) PrintReleaseReport(repos *gitpb.Repos) int {
	var count int

	log.Info(ReleaseReportHeader())

	loop := repos.SortByFullPath()
	for loop.Scan() {
		check := loop.Next()
		count += 1
		if check == nil {
			// wtf
			continue
		}
		var state string
		if check.CheckDirty() {
			state = "(dirty)"
		}
		log.Info(f.StandardReleaseHeader(check, state))
	}
	log.Info(fmt.Sprintf("total repo count = %d", count))
	return count
}

func (f *Forge) PrintPullTable(all *gitpb.Repos) {
	tablePB := f.makePullTable(all)
	tablePB.PrintTable()
}

func (f *Forge) makePullTable(pb *gitpb.Repos) *gitpb.ReposTable {
	t := pb.NewTable("pullTable")
	t.NewUuid()

	var col *gitpb.RepoAnyFunc
	// var col int

	col = t.AddMasterBranchName()
	col.Width = 10

	col = t.AddMasterVersion()
	// col.SetTitle("mver")
	col.Width = 15

	col = t.AddStringFunc("blah", func(r *gitpb.Repo) string {
		_, base := filepath.Split(r.Namespace)
		return base
	})
	col.Width = 9

	col = t.AddDevelVersion()
	col.Width = 15

	col = t.AddNamespace()
	col.Width = 18

	col = t.AddFullPath()
	col.Width = -1
	return t
}