forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ls_command.go
51 lines (38 loc) · 1.07 KB
/
ls_command.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package commands
import (
"errors"
"fmt"
"github.com/fatih/color"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/log"
m "github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
s "github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
)
var ls_getPlugins func(path string) []m.InstalledPlugin = s.GetLocalPlugins
var validateLsCommand = func(pluginDir string) error {
if pluginDir == "" {
return errors.New("missing path flag")
}
log.Debug("plugindir: " + pluginDir + "\n")
pluginDirInfo, err := s.IoHelper.Stat(pluginDir)
if err != nil {
return fmt.Errorf("error: %s", err)
}
if pluginDirInfo.IsDir() == false {
return errors.New("plugin path is not a directory")
}
return nil
}
func lsCommand(c CommandLine) error {
pluginDir := c.GlobalString("pluginsDir")
if err := validateLsCommand(pluginDir); err != nil {
return err
}
plugins := ls_getPlugins(pluginDir)
if len(plugins) > 0 {
log.Info("installed plugins:\n")
}
for _, plugin := range plugins {
log.Infof("%s %s %s \n", plugin.Id, color.YellowString("@"), plugin.Info.Version)
}
return nil
}