cli.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package control
  2. import (
  3. "fmt"
  4. "os"
  5. "github.com/rancher/os/cmd/control/service"
  6. "github.com/rancher/os/config"
  7. "github.com/rancher/os/pkg/log"
  8. "github.com/codegangsta/cli"
  9. )
  10. func Main() {
  11. log.InitLogger()
  12. cli.VersionPrinter = func(c *cli.Context) {
  13. cfg := config.LoadConfig()
  14. runningName := cfg.Rancher.Upgrade.Image + ":" + config.Version
  15. fmt.Fprintf(c.App.Writer, "version %s from os image %s\n", c.App.Version, runningName)
  16. }
  17. app := cli.NewApp()
  18. app.Name = os.Args[0]
  19. app.Usage = fmt.Sprintf("Control and configure RancherOS\nbuilt: %s", config.BuildDate)
  20. app.Version = config.Version
  21. app.Author = "Rancher Labs, Inc."
  22. app.EnableBashCompletion = true
  23. app.Before = func(c *cli.Context) error {
  24. if os.Geteuid() != 0 {
  25. log.Fatalf("%s: Need to be root", os.Args[0])
  26. }
  27. return nil
  28. }
  29. app.Commands = []cli.Command{
  30. {
  31. Name: "config",
  32. ShortName: "c",
  33. Usage: "configure settings",
  34. HideHelp: true,
  35. Subcommands: configSubcommands(),
  36. },
  37. {
  38. Name: "console",
  39. Usage: "manage which console container is used",
  40. HideHelp: true,
  41. Subcommands: consoleSubcommands(),
  42. },
  43. {
  44. Name: "console-init",
  45. Hidden: true,
  46. HideHelp: true,
  47. SkipFlagParsing: true,
  48. Action: consoleInitAction,
  49. },
  50. {
  51. Name: "dev",
  52. Hidden: true,
  53. HideHelp: true,
  54. SkipFlagParsing: true,
  55. Action: devAction,
  56. },
  57. {
  58. Name: "docker-init",
  59. Hidden: true,
  60. HideHelp: true,
  61. SkipFlagParsing: true,
  62. Action: dockerInitAction,
  63. },
  64. {
  65. Name: "engine",
  66. Usage: "manage which Docker engine is used",
  67. HideHelp: true,
  68. Subcommands: engineSubcommands(),
  69. },
  70. {
  71. Name: "entrypoint",
  72. Hidden: true,
  73. HideHelp: true,
  74. SkipFlagParsing: true,
  75. Action: entrypointAction,
  76. },
  77. {
  78. Name: "env",
  79. Hidden: true,
  80. HideHelp: true,
  81. SkipFlagParsing: true,
  82. Action: envAction,
  83. },
  84. service.Commands(),
  85. {
  86. Name: "os",
  87. Usage: "operating system upgrade/downgrade",
  88. HideHelp: true,
  89. Subcommands: osSubcommands(),
  90. },
  91. {
  92. Name: "preload-images",
  93. Hidden: true,
  94. HideHelp: true,
  95. SkipFlagParsing: true,
  96. Action: preloadImagesAction,
  97. },
  98. {
  99. Name: "recovery-init",
  100. Hidden: true,
  101. HideHelp: true,
  102. SkipFlagParsing: true,
  103. Action: recoveryInitAction,
  104. },
  105. {
  106. Name: "switch-console",
  107. Hidden: true,
  108. HideHelp: true,
  109. SkipFlagParsing: true,
  110. Action: switchConsoleAction,
  111. },
  112. {
  113. Name: "tls",
  114. Usage: "setup tls configuration",
  115. HideHelp: true,
  116. Subcommands: tlsConfCommands(),
  117. },
  118. {
  119. Name: "udev-settle",
  120. Hidden: true,
  121. HideHelp: true,
  122. SkipFlagParsing: true,
  123. Action: udevSettleAction,
  124. },
  125. {
  126. Name: "user-docker",
  127. Hidden: true,
  128. HideHelp: true,
  129. SkipFlagParsing: true,
  130. Action: userDockerAction,
  131. },
  132. installCommand,
  133. selinuxCommand(),
  134. }
  135. app.Run(os.Args)
  136. }