MCPcopy Index your code
hub / github.com/cli/cli / list

Method list

pkg/cmd/extension/manager.go:145–194  ·  view source on GitHub ↗
(includeMetadata bool)

Source from the content-addressed store, hash-verified

143}
144
145func (m *Manager) list(includeMetadata bool) ([]*Extension, error) {
146 dir := m.installDir()
147 entries, err := os.ReadDir(dir)
148 if err != nil {
149 return nil, err
150 }
151
152 results := make([]*Extension, 0, len(entries))
153 for _, f := range entries {
154 if !strings.HasPrefix(f.Name(), "gh-") {
155 continue
156 }
157 if f.IsDir() {
158 if _, err := os.Stat(filepath.Join(dir, f.Name(), manifestName)); err == nil {
159 results = append(results, &Extension{
160 path: filepath.Join(dir, f.Name(), f.Name()),
161 kind: BinaryKind,
162 httpClient: m.client,
163 })
164 } else {
165 results = append(results, &Extension{
166 path: filepath.Join(dir, f.Name(), f.Name()),
167 kind: GitKind,
168 gitClient: m.gitClient.ForRepo(filepath.Join(dir, f.Name())),
169 })
170 }
171 } else if isSymlink(f.Type()) {
172 results = append(results, &Extension{
173 path: filepath.Join(dir, f.Name(), f.Name()),
174 kind: LocalKind,
175 })
176 } else {
177 // the contents of a regular file point to a local extension on disk
178 p, err := readPathFromFile(filepath.Join(dir, f.Name()))
179 if err != nil {
180 return nil, err
181 }
182 results = append(results, &Extension{
183 path: filepath.Join(p, f.Name()),
184 kind: LocalKind,
185 })
186 }
187 }
188
189 if includeMetadata {
190 m.populateLatestVersions(results)
191 }
192
193 return results, nil
194}
195
196func (m *Manager) populateLatestVersions(exts []*Extension) {
197 var wg sync.WaitGroup

Calls 8

installDirMethod · 0.95
isSymlinkFunction · 0.85
readPathFromFileFunction · 0.85
JoinMethod · 0.80
NameMethod · 0.65
ForRepoMethod · 0.65
TypeMethod · 0.45