commands.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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> <plugin version (optional)>",
  25. Action: runCommand(installCommand),
  26. }, {
  27. Name: "list-remote",
  28. Usage: "list remote available plugins",
  29. Action: runCommand(listremoteCommand),
  30. }, {
  31. Name: "list-versions",
  32. Usage: "list-versions <plugin id>",
  33. Action: runCommand(listversionsCommand),
  34. }, {
  35. Name: "update",
  36. Usage: "update <plugin id>",
  37. Aliases: []string{"upgrade"},
  38. Action: runCommand(upgradeCommand),
  39. }, {
  40. Name: "update-all",
  41. Aliases: []string{"upgrade-all"},
  42. Usage: "update all your installed plugins",
  43. Action: runCommand(upgradeAllCommand),
  44. }, {
  45. Name: "ls",
  46. Usage: "list all installed plugins",
  47. Action: runCommand(lsCommand),
  48. }, {
  49. Name: "uninstall",
  50. Aliases: []string{"remove"},
  51. Usage: "uninstall <plugin id>",
  52. Action: runCommand(removeCommand),
  53. },
  54. }
  55. var Commands = []cli.Command{
  56. {
  57. Name: "plugins",
  58. Usage: "Manage plugins for grafana",
  59. Subcommands: pluginCommands,
  60. },
  61. }