MCPcopy
hub / github.com/cli/cli / content

Function content

internal/licenses/licenses.go:17–85  ·  view source on GitHub ↗
(embedFS fs.ReadFileFS, rootDir string)

Source from the content-addressed store, hash-verified

15}
16
17func content(embedFS fs.ReadFileFS, rootDir string) string {
18 var b strings.Builder
19
20 reportPath := path.Join(rootDir, "report.txt")
21 thirdPartyPath := path.Join(rootDir, "third-party")
22
23 report, err := fs.ReadFile(embedFS, reportPath)
24 if err != nil {
25 return "License information is only available in official release builds.\n"
26 }
27
28 b.Write(report)
29 b.WriteString("\n")
30
31 // Walk the third-party directory and output each license/notice file
32 // grouped by module path.
33 type moduleFiles struct {
34 path string
35 files []string
36 }
37
38 thirdPartyFS, err := fs.Sub(embedFS, thirdPartyPath)
39 if err != nil {
40 return b.String()
41 }
42
43 modules := map[string]*moduleFiles{}
44 fs.WalkDir(thirdPartyFS, ".", func(filePath string, d fs.DirEntry, err error) error {
45 if err != nil {
46 return fmt.Errorf("failed to read embedded file %s: %w", filePath, err)
47 }
48
49 if d.IsDir() {
50 return nil
51 }
52
53 dir := path.Dir(filePath)
54 if _, ok := modules[dir]; !ok {
55 modules[dir] = &moduleFiles{path: dir}
56 }
57 modules[dir].files = append(modules[dir].files, filePath)
58 return nil
59 })
60
61 // Sort modules by path for deterministic output
62 sorted := make([]string, 0, len(modules))
63 for k := range modules {
64 sorted = append(sorted, k)
65 }
66 sort.Strings(sorted)
67
68 for _, modPath := range sorted {
69 mod := modules[modPath]
70 b.WriteString("================================================================================\n")
71 fmt.Fprintf(&b, "%s\n", mod.path)
72 b.WriteString("================================================================================\n\n")
73
74 for _, filePath := range mod.files {

Callers 2

ContentFunction · 0.85
TestContent_tableTestsFunction · 0.85

Calls 4

JoinMethod · 0.80
WriteMethod · 0.65
ErrorfMethod · 0.65
StringMethod · 0.45

Tested by 1

TestContent_tableTestsFunction · 0.68