forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ls_command.go
49 lines (37 loc) · 983 Bytes
/
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
package commands
import (
"errors"
"github.com/grafana/grafana-cli/pkg/log"
m "github.com/grafana/grafana-cli/pkg/models"
s "github.com/grafana/grafana-cli/pkg/services"
)
var getPlugins func(path string) []m.InstalledPlugin
var GetStat m.IoUtil
func init() {
getPlugins = s.GetLocalPlugins
GetStat = s.IoUtil
}
func validateCommand(pluginDir string) error {
if pluginDir == "" {
return errors.New("missing path flag")
}
log.Info("plugindir: " + pluginDir + "\n")
pluginDirInfo, err := GetStat.Stat(pluginDir)
if err != nil {
return errors.New("missing path flag")
}
if pluginDirInfo.IsDir() == false {
return errors.New("plugin path is not a directory")
}
return nil
}
func lsCommand(c CommandLine) error {
pluginDir := c.GlobalString("path")
if err := validateCommand(pluginDir); err != nil {
return err
}
for _, plugin := range getPlugins(pluginDir) {
log.Infof("plugin: %s @ %s \n", plugin.Name, plugin.Info.Version)
}
return nil
}