summaryrefslogtreecommitdiff
path: root/human.go
blob: e87052497a86aa4a29e895ecfd70970a7d33641f (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
package forgepb

import (
	"fmt"

	"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.IsPrivate(r.GoPath) {
		flags += "(private) "
	}
	if f.IsFavorite(r.GoPath) {
		flags += "(favorite) "
	}
	if f.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
func (f *Forge) ConfigPrintTable() {
	if f == nil {
		log.Info("WTF forge == nil")
		panic("WTF forge == nil")
	}
	log.Info(standardHeader())
	loop := f.Config.SortByPath()
	for loop.Scan() {
		r := loop.Next()
		log.Info(f.standardHeader(r))
	}
}