commands.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 id>",
  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 id>",
  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: "uninstall",
  43. Usage: "uninstall <plugin id>",
  44. Action: runCommand(removeCommand),
  45. }, {
  46. Name: "remove",
  47. Usage: "remove <plugin id>",
  48. Action: runCommand(removeCommand),
  49. },
  50. }
  51. var Commands = []cli.Command{
  52. {
  53. Name: "plugins",
  54. Usage: "Manage plugins for grafana",
  55. Subcommands: pluginCommands,
  56. },
  57. }