tech(cli): remove loop and head straight for plugindir
This commit is contained in:
@@ -2,10 +2,10 @@ package commands
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"fmt"
|
||||
m "github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
|
||||
services "github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var getPluginss func(path string) []m.InstalledPlugin = services.GetLocalPlugins
|
||||
@@ -13,19 +13,21 @@ var removePlugin func(pluginPath, id string) error = services.RemoveInstalledPlu
|
||||
|
||||
func removeCommand(c CommandLine) error {
|
||||
pluginPath := c.PluginDirectory()
|
||||
localPlugins := getPluginss(pluginPath)
|
||||
|
||||
plugin := c.Args().First()
|
||||
if plugin == "" {
|
||||
return errors.New("Missing plugin parameter")
|
||||
}
|
||||
|
||||
for _, p := range localPlugins {
|
||||
if p.Id == c.Args().First() {
|
||||
removePlugin(pluginPath, p.Id)
|
||||
return nil
|
||||
err := removePlugin(pluginPath, plugin)
|
||||
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "no such file or directory") {
|
||||
return fmt.Errorf("Plugin does not exist")
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return fmt.Errorf("Could not find plugin named %s", c.Args().First())
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user