command_line.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package utils
  2. import (
  3. "github.com/codegangsta/cli"
  4. )
  5. type CommandLine interface {
  6. ShowHelp()
  7. ShowVersion()
  8. Application() *cli.App
  9. Args() cli.Args
  10. Bool(name string) bool
  11. Int(name string) int
  12. String(name string) string
  13. StringSlice(name string) []string
  14. GlobalString(name string) string
  15. FlagNames() (names []string)
  16. Generic(name string) interface{}
  17. PluginDirectory() string
  18. RepoDirectory() string
  19. PluginURL() string
  20. }
  21. type ContextCommandLine struct {
  22. *cli.Context
  23. }
  24. func (c *ContextCommandLine) ShowHelp() {
  25. cli.ShowCommandHelp(c.Context, c.Command.Name)
  26. }
  27. func (c *ContextCommandLine) ShowVersion() {
  28. cli.ShowVersion(c.Context)
  29. }
  30. func (c *ContextCommandLine) Application() *cli.App {
  31. return c.App
  32. }
  33. func (c *ContextCommandLine) HomePath() string { return c.GlobalString("homepath") }
  34. func (c *ContextCommandLine) ConfigFile() string { return c.GlobalString("config") }
  35. func (c *ContextCommandLine) PluginDirectory() string {
  36. return c.GlobalString("pluginsDir")
  37. }
  38. func (c *ContextCommandLine) RepoDirectory() string {
  39. return c.GlobalString("repo")
  40. }
  41. func (c *ContextCommandLine) PluginURL() string {
  42. return c.GlobalString("pluginUrl")
  43. }
  44. func (c *ContextCommandLine) OptionsString() string {
  45. return c.GlobalString("configOverrides")
  46. }