commands.go 1.5 KB

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