MCPcopy Index your code
hub / github.com/devspace-sh/devspace / GetByName

Method GetByName

pkg/devspace/plugin/plugin.go:280–326  ·  view source on GitHub ↗
(name string)

Source from the content-addressed store, hash-verified

278}
279
280func (c *client) GetByName(name string) (string, *Metadata, error) {
281 pluginFolder, err := c.PluginFolder()
282 if err != nil {
283 return "", nil, err
284 }
285
286 plugins, err := os.ReadDir(pluginFolder)
287 if err != nil {
288 if os.IsNotExist(err) {
289 return "", nil, nil
290 }
291
292 return "", nil, err
293 }
294
295 for _, dirEntry := range plugins {
296 plugin, err := dirEntry.Info()
297 if err != nil {
298 continue
299 }
300
301 metadataFileContents, err := os.ReadFile(filepath.Join(pluginFolder, plugin.Name(), pluginYaml))
302 if os.IsNotExist(err) {
303 _ = os.RemoveAll(filepath.Join(pluginFolder, plugin.Name()))
304 continue
305 }
306
307 metadata := Metadata{}
308 err = yaml.Unmarshal(metadataFileContents, &metadata)
309 if err != nil {
310 c.log.Warnf("Error parsing plugin.yaml for plugin %s: %v", plugin, err)
311 continue
312 }
313
314 if metadata.Name == name {
315 decoded, err := Decode(plugin.Name())
316 if err != nil {
317 return "", nil, errors.Wrap(err, "decode plugin path")
318 }
319
320 metadata.PluginFolder = filepath.Join(pluginFolder, plugin.Name())
321 return string(decoded), &metadata, nil
322 }
323 }
324
325 return "", nil, nil
326}
327
328func (c *client) Get(path string) (*Metadata, error) {
329 pluginFolder, err := c.PluginFolder()

Callers 2

UpdateMethod · 0.95
RemoveMethod · 0.95

Calls 5

PluginFolderMethod · 0.95
DecodeFunction · 0.85
NameMethod · 0.65
InfoMethod · 0.45
WarnfMethod · 0.45

Tested by

no test coverage detected