The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/cmd/grafana-cli/commands/ls_command.go

50 lines
1.1 KiB

package commands
import (
"errors"
"github.com/fatih/color"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
)
var ls_getPlugins func(path string) []models.InstalledPlugin = services.GetLocalPlugins
var validateLsCommand = func(pluginDir string) error {
if pluginDir == "" {
return errors.New("missing path flag")
}
logger.Debug("plugindir: " + pluginDir + "\n")
pluginDirInfo, err := services.IoHelper.Stat(pluginDir)
if err != nil {
return err
}
if !pluginDirInfo.IsDir() {
return errors.New("plugin path is not a directory")
}
return nil
}
func (cmd Command) lsCommand(c utils.CommandLine) error {
pluginDir := c.PluginDirectory()
if err := validateLsCommand(pluginDir); err != nil {
return err
}
plugins := ls_getPlugins(pluginDir)
if len(plugins) > 0 {
logger.Info("installed plugins:\n")
}
for _, plugin := range plugins {
logger.Infof("%s %s %s\n", plugin.Id, color.YellowString("@"), plugin.Info.Version)
}
return nil
}