2016-02-15 21:09:34 +08:00
|
|
|
package commands
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
2016-03-29 03:42:26 +08:00
|
|
|
|
2016-03-16 21:07:20 +08:00
|
|
|
"github.com/fatih/color"
|
2023-01-30 16:26:42 +08:00
|
|
|
|
2016-06-03 18:19:04 +08:00
|
|
|
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
|
2020-03-04 20:18:13 +08:00
|
|
|
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
|
2019-05-27 16:47:21 +08:00
|
|
|
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
|
2016-02-15 21:09:34 +08:00
|
|
|
)
|
|
|
|
|
|
2020-08-14 20:43:25 +08:00
|
|
|
var (
|
|
|
|
|
errMissingPathFlag = errors.New("missing path flag")
|
|
|
|
|
errNotDirectory = errors.New("plugin path is not a directory")
|
|
|
|
|
)
|
2016-03-10 21:43:21 +08:00
|
|
|
var validateLsCommand = func(pluginDir string) error {
|
2016-02-15 21:09:34 +08:00
|
|
|
if pluginDir == "" {
|
2020-08-14 20:43:25 +08:00
|
|
|
return errMissingPathFlag
|
2016-02-15 21:09:34 +08:00
|
|
|
}
|
|
|
|
|
|
2016-06-03 18:19:04 +08:00
|
|
|
logger.Debug("plugindir: " + pluginDir + "\n")
|
2020-03-04 20:18:13 +08:00
|
|
|
pluginDirInfo, err := services.IoHelper.Stat(pluginDir)
|
2016-02-15 21:09:34 +08:00
|
|
|
if err != nil {
|
2020-02-26 19:27:31 +08:00
|
|
|
return err
|
2016-02-15 21:09:34 +08:00
|
|
|
}
|
|
|
|
|
|
Simplify comparison to bool constant (gosimple)
This fixes:
build.go:553:6: should omit comparison to bool constant, can be simplified to !strings.Contains(path, ".sha256") (S1002)
pkg/cmd/grafana-cli/commands/ls_command.go:27:5: should omit comparison to bool constant, can be simplified to !pluginDirInfo.IsDir() (S1002)
pkg/components/dynmap/dynmap_test.go:24:5: should omit comparison to bool constant, can be simplified to !value (S1002)
pkg/components/dynmap/dynmap_test.go:122:14: should omit comparison to bool constant, can be simplified to b (S1002)
pkg/components/dynmap/dynmap_test.go:125:14: should omit comparison to bool constant, can be simplified to !b (S1002)
pkg/components/dynmap/dynmap_test.go:128:14: should omit comparison to bool constant, can be simplified to !b (S1002)
pkg/models/org_user.go:51:5: should omit comparison to bool constant, can be simplified to !(*r).IsValid() (S1002)
pkg/plugins/datasource/wrapper/datasource_plugin_wrapper_test.go:77:12: should omit comparison to bool constant, can be simplified to !haveBool (S1002)
pkg/services/alerting/conditions/evaluator.go:23:9: should omit comparison to bool constant, can be simplified to !reducedValue.Valid (S1002)
pkg/services/alerting/conditions/evaluator.go:48:5: should omit comparison to bool constant, can be simplified to !reducedValue.Valid (S1002)
pkg/services/alerting/conditions/evaluator.go:91:5: should omit comparison to bool constant, can be simplified to !reducedValue.Valid (S1002)
pkg/services/alerting/conditions/query.go:56:6: should omit comparison to bool constant, can be simplified to !reducedValue.Valid (S1002)
pkg/services/alerting/extractor.go:107:20: should omit comparison to bool constant, can be simplified to !enabled.MustBool() (S1002)
pkg/services/alerting/notifiers/telegram.go:222:41: should omit comparison to bool constant, can be simplified to this.UploadImage (S1002)
pkg/services/sqlstore/apikey.go:58:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/apikey.go:72:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/dashboard.go:66:33: should omit comparison to bool constant, can be simplified to !cmd.Overwrite (S1002)
pkg/services/sqlstore/dashboard.go:175:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/dashboard.go:311:13: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/dashboard.go:444:12: should omit comparison to bool constant, can be simplified to !exists (S1002)
pkg/services/sqlstore/dashboard.go:472:12: should omit comparison to bool constant, can be simplified to !exists (S1002)
pkg/services/sqlstore/dashboard.go:554:32: should omit comparison to bool constant, can be simplified to !cmd.Overwrite (S1002)
pkg/services/sqlstore/dashboard_snapshot.go:83:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/plugin_setting.go:39:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/quota.go:34:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/quota.go:111:6: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/quota.go:136:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/quota.go:213:6: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/temp_user.go:129:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/user.go:157:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/user.go:182:5: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/user.go:191:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/user.go:212:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/user.go:307:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/social/generic_oauth.go:185:5: should omit comparison to bool constant, can be simplified to !s.extractToken(&data, token) (S1002)
pkg/tsdb/mssql/mssql.go:148:39: should omit comparison to bool constant, can be simplified to ok (S1002)
pkg/tsdb/mssql/mssql.go:212:6: should omit comparison to bool constant, can be simplified to !query.Model.Get("fillNull").MustBool(false) (S1002)
pkg/tsdb/mssql/mssql.go:247:56: should omit comparison to bool constant, can be simplified to ok (S1002)
pkg/tsdb/mssql/mssql.go:274:7: should omit comparison to bool constant, can be simplified to !exist (S1002)
pkg/tsdb/mssql/mssql.go:282:8: should omit comparison to bool constant, can be simplified to !exist (S1002)
pkg/tsdb/mysql/mysql.go:221:6: should omit comparison to bool constant, can be simplified to !query.Model.Get("fillNull").MustBool(false) (S1002)
pkg/tsdb/mysql/mysql.go:256:56: should omit comparison to bool constant, can be simplified to ok (S1002)
pkg/tsdb/mysql/mysql.go:283:7: should omit comparison to bool constant, can be simplified to !exist (S1002)
pkg/tsdb/mysql/mysql.go:291:8: should omit comparison to bool constant, can be simplified to !exist (S1002)
pkg/tsdb/postgres/postgres.go:134:39: should omit comparison to bool constant, can be simplified to ok (S1002)
pkg/tsdb/postgres/postgres.go:201:6: should omit comparison to bool constant, can be simplified to !query.Model.Get("fillNull").MustBool(false) (S1002)
pkg/tsdb/postgres/postgres.go:236:56: should omit comparison to bool constant, can be simplified to ok (S1002)
pkg/tsdb/postgres/postgres.go:263:7: should omit comparison to bool constant, can be simplified to !exist (S1002)
pkg/tsdb/postgres/postgres.go:271:8: should omit comparison to bool constant, can be simplified to !exist (S1002)
2018-04-17 02:12:59 +08:00
|
|
|
if !pluginDirInfo.IsDir() {
|
2020-08-14 20:43:25 +08:00
|
|
|
return errNotDirectory
|
2016-02-15 21:09:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-04 16:52:09 +08:00
|
|
|
func lsCommand(c utils.CommandLine) error {
|
2016-06-25 02:14:58 +08:00
|
|
|
pluginDir := c.PluginDirectory()
|
2016-03-10 21:43:21 +08:00
|
|
|
if err := validateLsCommand(pluginDir); err != nil {
|
2016-02-15 21:09:34 +08:00
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-08 16:58:47 +08:00
|
|
|
plugins := services.GetLocalPlugins(pluginDir)
|
2016-03-07 23:41:22 +08:00
|
|
|
|
|
|
|
|
if len(plugins) > 0 {
|
2016-06-03 18:19:04 +08:00
|
|
|
logger.Info("installed plugins:\n")
|
2023-02-22 16:24:13 +08:00
|
|
|
} else {
|
|
|
|
|
logger.Info("no installed plugins found\n")
|
2016-03-07 23:41:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, plugin := range plugins {
|
2023-05-08 16:58:47 +08:00
|
|
|
logger.Infof("%s %s %s\n", plugin.Primary.JSONData.ID,
|
|
|
|
|
color.YellowString("@"), plugin.Primary.JSONData.Info.Version)
|
2016-02-15 21:09:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|