From 1a6af064b0c3df0d6cbcb2ec1f49b36da569e770 Mon Sep 17 00:00:00 2001 From: bergquist Date: Mon, 7 Mar 2016 16:41:22 +0100 Subject: [PATCH] fix(cli): improve logging when folders does not exists --- pkg/cmd/grafana-cli/commands/commands.go | 2 +- pkg/cmd/grafana-cli/commands/ls_command.go | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pkg/cmd/grafana-cli/commands/commands.go b/pkg/cmd/grafana-cli/commands/commands.go index 67e9f945cfd..4993d8aa045 100644 --- a/pkg/cmd/grafana-cli/commands/commands.go +++ b/pkg/cmd/grafana-cli/commands/commands.go @@ -11,7 +11,7 @@ func runCommand(command func(commandLine CommandLine) error) func(context *cli.C cmd := &contextCommandLine{context} if err := command(cmd); err != nil { - log.Errorf("%v\n\n", err) + log.Errorf("%s\n\n", err) cmd.ShowHelp() os.Exit(1) diff --git a/pkg/cmd/grafana-cli/commands/ls_command.go b/pkg/cmd/grafana-cli/commands/ls_command.go index f863bc4b72b..5a90df89d8a 100644 --- a/pkg/cmd/grafana-cli/commands/ls_command.go +++ b/pkg/cmd/grafana-cli/commands/ls_command.go @@ -2,6 +2,7 @@ package commands import ( "errors" + "fmt" "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" @@ -14,11 +15,11 @@ var validateLsCommmand = func(pluginDir string) error { return errors.New("missing path flag") } - log.Info("plugindir: " + pluginDir + "\n") + log.Debug("plugindir: " + pluginDir + "\n") pluginDirInfo, err := s.IoHelper.Stat(pluginDir) if err != nil { - return errors.New("missing path flag") + return fmt.Errorf("error: %s", err) } if pluginDirInfo.IsDir() == false { @@ -34,8 +35,14 @@ func lsCommand(c CommandLine) error { return err } - for _, plugin := range ls_getPlugins(pluginDir) { - log.Infof("plugin: %s @ %s \n", plugin.Name, plugin.Info.Version) + plugins := ls_getPlugins(pluginDir) + + if len(plugins) > 0 { + log.Info("installed plugins:\n") + } + + for _, plugin := range plugins { + log.Infof("%s @ %s \n", plugin.Id, plugin.Info.Version) } return nil