forgepb/human.go

51 lines
1.0 KiB
Go

package forgepb
import (
"fmt"
"os"
"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 (all *Repos) standardHeader(r *Repo) string {
var flags string
var readonly string
if all.IsPrivate(r.GoPath) {
flags += "(private) "
}
if all.IsFavorite(r.GoPath) {
flags += "(favorite) "
}
if all.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 (all *Repos) PrintTable() {
if all == nil {
log.Info("WTF")
os.Exit(0)
}
log.Info(standardHeader())
loop := all.SortByPath()
for loop.Scan() {
r := loop.Repo()
log.Info(all.standardHeader(r))
}
}