command.go 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. package command
  2. import (
  3. "github.com/codegangsta/cli"
  4. "github.com/docker/libcompose/cli/app"
  5. )
  6. // CreateCommand defines the libcompose create subcommand.
  7. func CreateCommand(factory app.ProjectFactory) cli.Command {
  8. return cli.Command{
  9. Name: "create",
  10. Usage: "Create all services but do not start",
  11. Action: app.WithProject(factory, app.ProjectCreate),
  12. Flags: []cli.Flag{
  13. cli.BoolFlag{
  14. Name: "no-recreate",
  15. Usage: "If containers already exist, don't recreate them. Incompatible with --force-recreate.",
  16. },
  17. cli.BoolFlag{
  18. Name: "force-recreate",
  19. Usage: "Recreate containers even if their configuration and image haven't changed. Incompatible with --no-recreate.",
  20. },
  21. cli.BoolFlag{
  22. Name: "no-build",
  23. Usage: "Don't build an image, even if it's missing.",
  24. },
  25. },
  26. }
  27. }
  28. // BuildCommand defines the libcompose build subcommand.
  29. func BuildCommand(factory app.ProjectFactory) cli.Command {
  30. return cli.Command{
  31. Name: "build",
  32. Usage: "Build or rebuild services.",
  33. Action: app.WithProject(factory, app.ProjectBuild),
  34. Flags: []cli.Flag{
  35. cli.BoolFlag{
  36. Name: "no-cache",
  37. Usage: "Do not use cache when building the image",
  38. },
  39. cli.BoolFlag{
  40. Name: "force-rm",
  41. Usage: "Always remove intermediate containers",
  42. },
  43. cli.BoolFlag{
  44. Name: "pull",
  45. Usage: "Always attempt to pull a newer version of the image",
  46. },
  47. },
  48. }
  49. }
  50. // PsCommand defines the libcompose ps subcommand.
  51. func PsCommand(factory app.ProjectFactory) cli.Command {
  52. return cli.Command{
  53. Name: "ps",
  54. Usage: "List containers",
  55. Action: app.WithProject(factory, app.ProjectPs),
  56. Flags: []cli.Flag{
  57. cli.BoolFlag{
  58. Name: "q",
  59. Usage: "Only display IDs",
  60. },
  61. },
  62. }
  63. }
  64. // PortCommand defines the libcompose port subcommand.
  65. func PortCommand(factory app.ProjectFactory) cli.Command {
  66. return cli.Command{
  67. Name: "port",
  68. Usage: "Print the public port for a port binding",
  69. Action: app.WithProject(factory, app.ProjectPort),
  70. Flags: []cli.Flag{
  71. cli.StringFlag{
  72. Name: "protocol",
  73. Usage: "tcp or udp ",
  74. Value: "tcp",
  75. },
  76. cli.IntFlag{
  77. Name: "index",
  78. Usage: "index of the container if there are multiple instances of a service",
  79. Value: 1,
  80. },
  81. },
  82. }
  83. }
  84. // UpCommand defines the libcompose up subcommand.
  85. func UpCommand(factory app.ProjectFactory) cli.Command {
  86. return cli.Command{
  87. Name: "up",
  88. Usage: "Bring all services up",
  89. Action: app.WithProject(factory, app.ProjectUp),
  90. Flags: []cli.Flag{
  91. cli.BoolFlag{
  92. Name: "d",
  93. Usage: "Do not block and log",
  94. },
  95. cli.BoolFlag{
  96. Name: "no-build",
  97. Usage: "Don't build an image, even if it's missing.",
  98. },
  99. cli.BoolFlag{
  100. Name: "no-recreate",
  101. Usage: "If containers already exist, don't recreate them. Incompatible with --force-recreate.",
  102. },
  103. cli.BoolFlag{
  104. Name: "force-recreate",
  105. Usage: "Recreate containers even if their configuration and image haven't changed. Incompatible with --no-recreate.",
  106. },
  107. },
  108. }
  109. }
  110. // StartCommand defines the libcompose start subcommand.
  111. func StartCommand(factory app.ProjectFactory) cli.Command {
  112. return cli.Command{
  113. Name: "start",
  114. Usage: "Start services",
  115. Action: app.WithProject(factory, app.ProjectStart),
  116. Flags: []cli.Flag{
  117. cli.BoolTFlag{
  118. Name: "d",
  119. Usage: "Do not block and log",
  120. },
  121. },
  122. }
  123. }
  124. // RunCommand defines the libcompose run subcommand.
  125. func RunCommand(factory app.ProjectFactory) cli.Command {
  126. return cli.Command{
  127. Name: "run",
  128. Usage: "Run a one-off command",
  129. Action: app.WithProject(factory, app.ProjectRun),
  130. Flags: []cli.Flag{},
  131. }
  132. }
  133. // PullCommand defines the libcompose pull subcommand.
  134. func PullCommand(factory app.ProjectFactory) cli.Command {
  135. return cli.Command{
  136. Name: "pull",
  137. Usage: "Pulls images for services",
  138. Action: app.WithProject(factory, app.ProjectPull),
  139. Flags: []cli.Flag{
  140. cli.BoolFlag{
  141. Name: "ignore-pull-failures",
  142. Usage: "Pull what it can and ignores images with pull failures.",
  143. },
  144. },
  145. }
  146. }
  147. // LogsCommand defines the libcompose logs subcommand.
  148. func LogsCommand(factory app.ProjectFactory) cli.Command {
  149. return cli.Command{
  150. Name: "logs",
  151. Usage: "Get service logs",
  152. Action: app.WithProject(factory, app.ProjectLog),
  153. Flags: []cli.Flag{
  154. cli.IntFlag{
  155. Name: "lines",
  156. Usage: "number of lines to tail",
  157. Value: 100,
  158. },
  159. cli.BoolFlag{
  160. Name: "follow",
  161. Usage: "Follow log output.",
  162. },
  163. },
  164. }
  165. }
  166. // RestartCommand defines the libcompose restart subcommand.
  167. func RestartCommand(factory app.ProjectFactory) cli.Command {
  168. return cli.Command{
  169. Name: "restart",
  170. Usage: "Restart services",
  171. Action: app.WithProject(factory, app.ProjectRestart),
  172. Flags: []cli.Flag{
  173. cli.IntFlag{
  174. Name: "timeout,t",
  175. Usage: "Specify a shutdown timeout in seconds.",
  176. Value: 10,
  177. },
  178. },
  179. }
  180. }
  181. // StopCommand defines the libcompose stop subcommand.
  182. func StopCommand(factory app.ProjectFactory) cli.Command {
  183. return cli.Command{
  184. Name: "stop",
  185. Usage: "Stop services",
  186. Action: app.WithProject(factory, app.ProjectStop),
  187. Flags: []cli.Flag{
  188. cli.IntFlag{
  189. Name: "timeout,t",
  190. Usage: "Specify a shutdown timeout in seconds.",
  191. Value: 10,
  192. },
  193. },
  194. }
  195. }
  196. // DownCommand defines the libcompose stop subcommand.
  197. func DownCommand(factory app.ProjectFactory) cli.Command {
  198. return cli.Command{
  199. Name: "down",
  200. Usage: "Stop and remove containers, networks, images, and volumes",
  201. Action: app.WithProject(factory, app.ProjectDown),
  202. Flags: []cli.Flag{
  203. cli.BoolFlag{
  204. Name: "volumes,v",
  205. Usage: "Remove data volumes",
  206. },
  207. cli.StringFlag{
  208. Name: "rmi",
  209. Usage: "Remove images, type may be one of: 'all' to remove all images, or 'local' to remove only images that don't have an custom name set by the `image` field",
  210. },
  211. cli.BoolFlag{
  212. Name: "remove-orphans",
  213. Usage: "Remove containers for services not defined in the Compose file",
  214. },
  215. },
  216. }
  217. }
  218. // ScaleCommand defines the libcompose scale subcommand.
  219. func ScaleCommand(factory app.ProjectFactory) cli.Command {
  220. return cli.Command{
  221. Name: "scale",
  222. Usage: "Scale services",
  223. Action: app.WithProject(factory, app.ProjectScale),
  224. Flags: []cli.Flag{
  225. cli.IntFlag{
  226. Name: "timeout,t",
  227. Usage: "Specify a shutdown timeout in seconds.",
  228. Value: 10,
  229. },
  230. },
  231. }
  232. }
  233. // RmCommand defines the libcompose rm subcommand.
  234. func RmCommand(factory app.ProjectFactory) cli.Command {
  235. return cli.Command{
  236. Name: "rm",
  237. Usage: "Delete services",
  238. Action: app.WithProject(factory, app.ProjectDelete),
  239. Flags: []cli.Flag{
  240. cli.BoolFlag{
  241. Name: "force,f",
  242. Usage: "Allow deletion of all services",
  243. },
  244. cli.BoolFlag{
  245. Name: "v",
  246. Usage: "Remove volumes associated with containers",
  247. },
  248. },
  249. }
  250. }
  251. // KillCommand defines the libcompose kill subcommand.
  252. func KillCommand(factory app.ProjectFactory) cli.Command {
  253. return cli.Command{
  254. Name: "kill",
  255. Usage: "Force stop service containers",
  256. Action: app.WithProject(factory, app.ProjectKill),
  257. Flags: []cli.Flag{
  258. cli.StringFlag{
  259. Name: "signal,s",
  260. Usage: "SIGNAL to send to the container",
  261. Value: "SIGKILL",
  262. },
  263. },
  264. }
  265. }
  266. // PauseCommand defines the libcompose pause subcommand.
  267. func PauseCommand(factory app.ProjectFactory) cli.Command {
  268. return cli.Command{
  269. Name: "pause",
  270. Usage: "Pause services.",
  271. // ArgsUsage: "[SERVICE...]",
  272. Action: app.WithProject(factory, app.ProjectPause),
  273. }
  274. }
  275. // UnpauseCommand defines the libcompose unpause subcommand.
  276. func UnpauseCommand(factory app.ProjectFactory) cli.Command {
  277. return cli.Command{
  278. Name: "unpause",
  279. Usage: "Unpause services.",
  280. // ArgsUsage: "[SERVICE...]",
  281. Action: app.WithProject(factory, app.ProjectUnpause),
  282. }
  283. }
  284. // VersionCommand defines the libcompose version subcommand.
  285. func VersionCommand(factory app.ProjectFactory) cli.Command {
  286. return cli.Command{
  287. Name: "version",
  288. Usage: "Show version informations",
  289. Action: app.Version,
  290. Flags: []cli.Flag{
  291. cli.BoolFlag{
  292. Name: "short",
  293. Usage: "Shows only Compose's version number.",
  294. },
  295. },
  296. }
  297. }
  298. // CommonFlags defines the flags that are in common for all subcommands.
  299. func CommonFlags() []cli.Flag {
  300. return []cli.Flag{
  301. cli.BoolFlag{
  302. Name: "verbose,debug",
  303. },
  304. cli.StringSliceFlag{
  305. Name: "file,f",
  306. Usage: "Specify one or more alternate compose files (default: docker-compose.yml)",
  307. Value: &cli.StringSlice{},
  308. EnvVar: "COMPOSE_FILE",
  309. },
  310. cli.StringFlag{
  311. Name: "project-name,p",
  312. Usage: "Specify an alternate project name (default: directory name)",
  313. EnvVar: "COMPOSE_PROJECT_NAME",
  314. },
  315. }
  316. }