MCPcopy Create free account
hub / github.com/voidint/g / render

Function render

cli/cli.go:147–181  ·  view source on GitHub ↗

render outputs version list in specified format.

(mode uint8, installed map[string]bool, items []*version.Version, out io.Writer)

Source from the content-addressed store, hash-verified

145
146// render outputs version list in specified format.
147func render(mode uint8, installed map[string]bool, items []*version.Version, out io.Writer) {
148 switch mode {
149 case jsonMode:
150 vs := make([]versionOut, 0, len(items))
151
152 for _, item := range items {
153 vo := versionOut{
154 Version: item.Name(),
155 Packages: item.Packages(),
156 }
157 if inuse, found := installed[item.Name()]; found {
158 vo.InUse = inuse
159 vo.Installed = found
160 }
161 vs = append(vs, vo)
162 }
163
164 enc := json.NewEncoder(out)
165 enc.SetIndent("", " ")
166 _ = enc.Encode(&vs)
167
168 default:
169 for _, item := range items {
170 if inused, found := installed[item.Name()]; found {
171 if inused {
172 _, _ = color.New(color.FgGreen).Fprintf(out, "* %s\n", item.Name())
173 } else {
174 _, _ = color.New(color.FgGreen).Fprintf(out, " %s\n", item.Name())
175 }
176 } else {
177 _, _ = fmt.Fprintf(out, " %s\n", item.Name())
178 }
179 }
180 }
181}
182
183// errstring formats error messages with consistent style.
184func errstring(err error) string {

Callers 3

listRemoteFunction · 0.85
listFunction · 0.85
Test_renderFunction · 0.85

Calls 2

PackagesMethod · 0.80
NameMethod · 0.65

Tested by 1

Test_renderFunction · 0.68