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

Method list

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

Source from the content-addressed store, hash-verified

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