commands.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package commands
  2. import (
  3. "os"
  4. "github.com/codegangsta/cli"
  5. "github.com/grafana/grafana/pkg/cmd/grafana-cli/log"
  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: "update",
  31. Usage: "update <plugin id>",
  32. Aliases: []string{"upgrade"},
  33. Action: runCommand(upgradeCommand),
  34. }, {
  35. Name: "update-all",
  36. Aliases: []string{"upgrade-all"},
  37. Usage: "update all your installed plugins",
  38. Action: runCommand(upgradeAllCommand),
  39. }, {
  40. Name: "ls",
  41. Usage: "list all installed plugins",
  42. Action: runCommand(lsCommand),
  43. }, {
  44. Name: "uninstall",
  45. Usage: "uninstall <plugin id>",
  46. Action: runCommand(removeCommand),
  47. }, {
  48. Name: "remove",
  49. Usage: "remove <plugin id>",
  50. Action: runCommand(removeCommand),
  51. },
  52. }
  53. var Commands = []cli.Command{
  54. {
  55. Name: "plugins",
  56. Usage: "Manage plugins for grafana",
  57. Subcommands: pluginCommands,
  58. },
  59. }