commands.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package commands
  2. import (
  3. "github.com/codegangsta/cli"
  4. "github.com/grafana/grafana/pkg/cmd/grafana-cli/log"
  5. "os"
  6. )
  7. func runCommand(command func(commandLine CommandLine) error) func(context *cli.Context) {
  8. return func(context *cli.Context) {
  9. cmd := &contextCommandLine{context}
  10. if err := command(cmd); err != nil {
  11. log.Error("\nError: ")
  12. log.Errorf("%s\n\n", err)
  13. cmd.ShowHelp()
  14. os.Exit(1)
  15. } else {
  16. log.Info("\nRestart grafana after installing plugins . <service grafana-server restart>\n\n")
  17. }
  18. }
  19. }
  20. var pluginCommands = []cli.Command{
  21. {
  22. Name: "install",
  23. Usage: "install <plugin name>",
  24. Action: runCommand(installCommand),
  25. }, {
  26. Name: "list-remote",
  27. Usage: "list remote available plugins",
  28. Action: runCommand(listremoteCommand),
  29. }, {
  30. Name: "upgrade",
  31. Usage: "upgrade <plugin name>",
  32. Action: runCommand(upgradeCommand),
  33. }, {
  34. Name: "upgrade-all",
  35. Usage: "upgrades all your installed plugins",
  36. Action: runCommand(upgradeAllCommand),
  37. }, {
  38. Name: "ls",
  39. Usage: "list all installed plugins",
  40. Action: runCommand(lsCommand),
  41. }, {
  42. Name: "remove",
  43. Usage: "remove <plugin name>",
  44. Action: runCommand(removeCommand),
  45. },
  46. }
  47. var Commands = []cli.Command{
  48. {
  49. Name: "plugins",
  50. Usage: "Manage plugins for grafana",
  51. Subcommands: pluginCommands,
  52. },
  53. }