command_line.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package utils
  2. import (
  3. "github.com/codegangsta/cli"
  4. "github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
  5. "github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
  6. )
  7. type CommandLine interface {
  8. ShowHelp()
  9. ShowVersion()
  10. Application() *cli.App
  11. Args() cli.Args
  12. Bool(name string) bool
  13. Int(name string) int
  14. String(name string) string
  15. StringSlice(name string) []string
  16. GlobalString(name string) string
  17. FlagNames() (names []string)
  18. Generic(name string) interface{}
  19. PluginDirectory() string
  20. RepoDirectory() string
  21. PluginURL() string
  22. ApiClient() ApiClient
  23. }
  24. type ApiClient interface {
  25. GetPlugin(pluginId, repoUrl string) (models.Plugin, error)
  26. DownloadFile(pluginName, filePath, url string, checksum string) (content []byte, err error)
  27. ListAllPlugins(repoUrl string) (models.PluginRepo, error)
  28. }
  29. type ContextCommandLine struct {
  30. *cli.Context
  31. }
  32. func (c *ContextCommandLine) ShowHelp() {
  33. cli.ShowCommandHelp(c.Context, c.Command.Name)
  34. }
  35. func (c *ContextCommandLine) ShowVersion() {
  36. cli.ShowVersion(c.Context)
  37. }
  38. func (c *ContextCommandLine) Application() *cli.App {
  39. return c.App
  40. }
  41. func (c *ContextCommandLine) HomePath() string { return c.GlobalString("homepath") }
  42. func (c *ContextCommandLine) ConfigFile() string { return c.GlobalString("config") }
  43. func (c *ContextCommandLine) PluginDirectory() string {
  44. return c.GlobalString("pluginsDir")
  45. }
  46. func (c *ContextCommandLine) RepoDirectory() string {
  47. return c.GlobalString("repo")
  48. }
  49. func (c *ContextCommandLine) PluginURL() string {
  50. return c.GlobalString("pluginUrl")
  51. }
  52. func (c *ContextCommandLine) OptionsString() string {
  53. return c.GlobalString("configOverrides")
  54. }
  55. func (c *ContextCommandLine) ApiClient() ApiClient {
  56. return &services.GrafanaComClient{}
  57. }