7276bd5e84
Showing Task Resources in alloc status
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package command
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/ryanuber/columnize"
|
|
)
|
|
|
|
// formatKV takes a set of strings and formats them into properly
|
|
// aligned k = v pairs using the columnize library.
|
|
func formatKV(in []string) string {
|
|
columnConf := columnize.DefaultConfig()
|
|
columnConf.Empty = "<none>"
|
|
columnConf.Glue = " = "
|
|
return columnize.Format(in, columnConf)
|
|
}
|
|
|
|
// formatList takes a set of strings and formats them into properly
|
|
// aligned output, replacing any blank fields with a placeholder
|
|
// for awk-ability.
|
|
func formatList(in []string) string {
|
|
columnConf := columnize.DefaultConfig()
|
|
columnConf.Empty = "<none>"
|
|
return columnize.Format(in, columnConf)
|
|
}
|
|
|
|
// formatListWithSpaces takes a set of strings and formats them into properly
|
|
// aligned output. It should be used sparingly since it doesn't replace empty
|
|
// values and hence not awk/sed friendly
|
|
func formatListWithSpaces(in []string) string {
|
|
columnConf := columnize.DefaultConfig()
|
|
return columnize.Format(in, columnConf)
|
|
}
|
|
|
|
// Limits the length of the string.
|
|
func limit(s string, length int) string {
|
|
if len(s) < length {
|
|
return s
|
|
}
|
|
|
|
return s[:length]
|
|
}
|
|
|
|
// formatTime formats the time to string based on RFC822
|
|
func formatTime(t time.Time) string {
|
|
return t.Format("02/01/06 15:04:05 MST")
|
|
}
|