MCPcopy
hub / github.com/cortexlabs/cortex / String

Method String

pkg/lib/table/key_value.go:55–94  ·  view source on GitHub ↗
(options ...*KeyValuePairOpts)

Source from the content-addressed store, hash-verified

53}
54
55func (kvs KeyValuePairs) String(options ...*KeyValuePairOpts) string {
56 opts := mergeOptions(options...)
57
58 var maxLen int
59 for _, pair := range kvs.kvs {
60 keyLen := len(s.ObjFlatNoQuotes(pair.k))
61 if keyLen > maxLen {
62 maxLen = keyLen
63 }
64 }
65
66 var b strings.Builder
67 for i, pair := range kvs.kvs {
68 keyStr := s.ObjFlatNoQuotes(pair.k)
69 keyLen := len(keyStr)
70
71 if *opts.BoldKeys {
72 keyStr = console.Bold(keyStr)
73 }
74
75 valStr := s.ObjFlatNoQuotes(pair.v)
76 var str string
77 if *opts.RightJustify {
78 alignmentSpaces := strings.Repeat(" ", maxLen-keyLen)
79 delimiterSpaces := strings.Repeat(" ", *opts.NumSpaces)
80 str = alignmentSpaces + keyStr + *opts.Delimiter + delimiterSpaces + valStr + "\n"
81 } else {
82 spaces := strings.Repeat(" ", maxLen-keyLen+*opts.NumSpaces)
83 str = keyStr + *opts.Delimiter + spaces + valStr + "\n"
84 }
85
86 if *opts.BoldFirstLine && i == 0 {
87 str = console.Bold(str)
88 }
89
90 b.WriteString(str)
91 }
92
93 return b.String()
94}
95
96func (kvs KeyValuePairs) Print(options ...*KeyValuePairOpts) {
97 fmt.Print(kvs.String(options...))

Callers 5

PrintMethod · 0.95
podResourceRequestsTableFunction · 0.95
getTaskJobFunction · 0.95
getBatchJobFunction · 0.95
EventFromExceptionFunction · 0.45

Calls 2

BoldFunction · 0.92
mergeOptionsFunction · 0.85

Tested by

no test coverage detected