mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(cli): move cli into main repo
This commit is contained in:
49
pkg/cmd/grafana-cli/commands/ls_command.go
Normal file
49
pkg/cmd/grafana-cli/commands/ls_command.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"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 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
|
||||
}
|
||||
Reference in New Issue
Block a user