MCPcopy Create free account
hub / github.com/cli/cli / list

Method list

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

Source from the content-addressed store, hash-verified

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