2024-11-20 12:11:13 -06:00
|
|
|
package forgepb
|
|
|
|
|
2024-11-22 08:44:49 -06:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
2024-11-21 10:37:01 -06:00
|
|
|
|
2024-11-20 12:11:13 -06:00
|
|
|
// 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
|
|
|
|
|
2024-11-22 08:44:49 -06:00
|
|
|
func standardHeader() string {
|
2024-11-25 00:46:16 -06:00
|
|
|
return fmt.Sprintf("%-4s %-40s %s", "", "Path", "flags")
|
2024-11-21 10:37:01 -06:00
|
|
|
}
|
|
|
|
|
2024-11-27 21:05:12 -06:00
|
|
|
func (all *ForgeConfigs) standardHeader(r *ForgeConfig) string {
|
2024-11-21 10:37:01 -06:00
|
|
|
var flags string
|
2024-11-22 08:44:49 -06:00
|
|
|
var readonly string
|
|
|
|
if all.IsPrivate(r.GoPath) {
|
2024-11-21 10:37:01 -06:00
|
|
|
flags += "(private) "
|
|
|
|
}
|
2024-11-25 00:46:16 -06:00
|
|
|
if all.IsFavorite(r.GoPath) {
|
|
|
|
flags += "(favorite) "
|
|
|
|
}
|
2024-11-22 08:44:49 -06:00
|
|
|
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
|
2024-11-27 21:05:12 -06:00
|
|
|
func (all *ForgeConfigs) PrintTable() {
|
2024-11-22 08:44:49 -06:00
|
|
|
if all == nil {
|
|
|
|
log.Info("WTF")
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
log.Info(standardHeader())
|
|
|
|
loop := all.SortByPath()
|
|
|
|
for loop.Scan() {
|
2024-11-27 21:05:12 -06:00
|
|
|
r := loop.Next()
|
2024-11-22 08:44:49 -06:00
|
|
|
log.Info(all.standardHeader(r))
|
|
|
|
}
|
2024-11-21 10:37:01 -06:00
|
|
|
}
|