MCPcopy Create free account
hub / github.com/celer-pkg/celer / PrintResolvedRefs

Function PrintResolvedRefs

pkgs/refs/output.go:18–90  ·  view source on GitHub ↗

PrintResolvedRefs prints a formatted list of resolved refs to the terminal.

(projectName string, results []ResolvedRef)

Source from the content-addressed store, hash-verified

16
17// PrintResolvedRefs prints a formatted list of resolved refs to the terminal.
18func PrintResolvedRefs(projectName string, results []ResolvedRef) {
19 title := fmt.Sprintf("\n================================ Resolved all dependency refs for %s ================================", projectName)
20 color.Println(color.Title, title)
21
22 // Build rows first to calculate dynamic column widths.
23 type row struct {
24 name string
25 srcType string
26 url string
27 ref string
28 resolved string
29 isError bool
30 isVirtual bool
31 }
32
33 rows := make([]row, 0, len(results))
34 for _, r := range results {
35 resolved := "-"
36 if r.ResolvedCommit != "" {
37 resolved = r.ResolvedCommit
38 }
39 rows = append(rows, row{
40 name: r.NameVersion,
41 srcType: string(r.SourceType),
42 url: r.Url,
43 ref: r.OriginalRef,
44 resolved: resolved,
45 isError: r.Error != "",
46 isVirtual: r.SourceType == SourceVirtual,
47 })
48 }
49
50 // Calculate max width per column.
51 maxName := len("NAME@VERSION")
52 maxType := len("TYPE")
53 maxURL := len("URL")
54 maxRef := len("REF")
55 for _, r := range rows {
56 if len(r.name) > maxName {
57 maxName = len(r.name)
58 }
59 if len(r.srcType) > maxType {
60 maxType = len(r.srcType)
61 }
62 if len(r.url) > maxURL {
63 maxURL = len(r.url)
64 }
65 if len(r.ref) > maxRef {
66 maxRef = len(r.ref)
67 }
68 }
69
70 // Cap URL column to avoid excessively wide tables.
71 if maxURL > 55 {
72 maxURL = 55
73 }
74
75 format := fmt.Sprintf(" %%-%ds %%-%ds %%-%ds %%-%ds %%s\n", maxName, maxType, maxURL, maxRef)

Callers 1

resolveAllRefsMethod · 0.92

Calls 4

PrintlnFunction · 0.92
PrintfFunction · 0.92
truncateFunction · 0.85
SprintfMethod · 0.80

Tested by

no test coverage detected