Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 69 additions & 38 deletions cli/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,22 @@ import (
// CreateCommand defines the libcompose create subcommand.
func CreateCommand(factory app.ProjectFactory) cli.Command {
return cli.Command{
Name: "create",
Usage: "Create all services but do not start",
Action: app.WithProject(factory, app.ProjectCreate),
Name: "create",
Usage: "Create all services but do not start",
ArgsUsage: "[SERVICE...]",
Action: app.WithProject(factory, app.ProjectCreate),
}
}

// BuildCommand defines the libcompose build subcommand.
func BuildCommand(factory app.ProjectFactory) cli.Command {
return cli.Command{
Name: "build",
Usage: "Build or rebuild services.",
Name: "build",
Usage: "Build or rebuild services.",
ArgsUsage: "[SERVICE...]",
Description: "Services are built once and then tagged as `project_service`,\n" +
"e.g. `composetest_db`. If you change a service's `Dockerfile` or the\n" +
"contents of its build directory, you can run `libcompose-cli build` to rebuild it.",
Action: app.WithProject(factory, app.ProjectBuild),
Flags: []cli.Flag{
cli.BoolFlag{
Expand All @@ -33,9 +38,10 @@ func BuildCommand(factory app.ProjectFactory) cli.Command {
// PsCommand defines the libcompose ps subcommand.
func PsCommand(factory app.ProjectFactory) cli.Command {
return cli.Command{
Name: "ps",
Usage: "List containers",
Action: app.WithProject(factory, app.ProjectPs),
Name: "ps",
Usage: "List containers",
ArgsUsage: "[SERVICE...]",
Action: app.WithProject(factory, app.ProjectPs),
Flags: []cli.Flag{
cli.BoolFlag{
Name: "q",
Expand All @@ -48,9 +54,10 @@ func PsCommand(factory app.ProjectFactory) cli.Command {
// PortCommand defines the libcompose port subcommand.
func PortCommand(factory app.ProjectFactory) cli.Command {
return cli.Command{
Name: "port",
Usage: "Print the public port for a port binding",
Action: app.WithProject(factory, app.ProjectPort),
Name: "port",
Usage: "Print the public port for a port binding",
ArgsUsage: "SERVICE PRIVATE_PORT",
Action: app.WithProject(factory, app.ProjectPort),
Flags: []cli.Flag{
cli.StringFlag{
Name: "protocol",
Expand All @@ -69,8 +76,20 @@ func PortCommand(factory app.ProjectFactory) cli.Command {
// UpCommand defines the libcompose up subcommand.
func UpCommand(factory app.ProjectFactory) cli.Command {
return cli.Command{
Name: "up",
Usage: "Bring all services up",
Name: "up",
Usage: "Builds, (re)creates, starts, and attaches to containers for a service.",
ArgsUsage: "[SERVICE...]",
Description: "Unless they are already running, this command also starts any linked services.\n\n" +
"The `libcompose-cli up` command aggregates the output of each container. When\n" +
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unfortunate we need the back-tics in the string; having to do all the concatenation and \n\n for new lines looks tedious

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah 😓 I'm looking around to see a better way to do that (and hopefully, I'll find one).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, also thinking what a solution would be. Perhaps a separate TOML file containing the strings/descriptions? idk

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thaJeztah I wonder, I could also use backticks to not have to escape the carriage-return but.. I had trouble with them for these (backticks inside backticks…).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking if GoDoc can be used somehow, I know @calavera did some experimenting in this area in this PR moby/moby#16125. However (obviously) that's used to generate external documentation, not for usage in the output of the software itself

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spf13/cobra has a good way of dealing with this I think: https://github.com/spf13/cobra#manually-create-rootcmd

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like that also uses back-tics for quotes. Still might be worth looking into; something that's easy to maintain and reusable

"the command exits, all containers are stopped. Running `libcompose-cli up -d`\n" +
"starts the containers in the background and leaves them running.\n\n" +
"If there are existing containers for a service, and the service's configuration\n" +
"or image was changed after the container's creation, `libcompose-cli up` picks\n" +
"up the changes by stopping and recreating the containers (preserving mounted\n" +
"volumes). To prevent Compose from picking up changes, use the `--no-recreate`\n" +
"flag.\n\n" +
"If you want to force Compose to stop and recreate all containers, use the\n" +
"`--force-recreate` flag.",
Action: app.WithProject(factory, app.ProjectUp),
Flags: []cli.Flag{
cli.BoolFlag{
Expand All @@ -92,9 +111,10 @@ func UpCommand(factory app.ProjectFactory) cli.Command {
// StartCommand defines the libcompose start subcommand.
func StartCommand(factory app.ProjectFactory) cli.Command {
return cli.Command{
Name: "start",
Usage: "Start services",
Action: app.WithProject(factory, app.ProjectStart),
Name: "start",
Usage: "Start existing containers.",
ArgsUsage: "[SERVICE...]",
Action: app.WithProject(factory, app.ProjectStart),
Flags: []cli.Flag{
cli.BoolTFlag{
Name: "d",
Expand All @@ -107,18 +127,20 @@ func StartCommand(factory app.ProjectFactory) cli.Command {
// PullCommand defines the libcompose pull subcommand.
func PullCommand(factory app.ProjectFactory) cli.Command {
return cli.Command{
Name: "pull",
Usage: "Pulls images for services",
Action: app.WithProject(factory, app.ProjectPull),
Name: "pull",
Usage: "Pulls images for services.",
ArgsUsage: "[SERVICE...]",
Action: app.WithProject(factory, app.ProjectPull),
}
}

// LogsCommand defines the libcompose logs subcommand.
func LogsCommand(factory app.ProjectFactory) cli.Command {
return cli.Command{
Name: "logs",
Usage: "Get service logs",
Action: app.WithProject(factory, app.ProjectLog),
Name: "logs",
Usage: "View output from containers.",
ArgsUsage: "[SERVICE...]",
Action: app.WithProject(factory, app.ProjectLog),
Flags: []cli.Flag{
cli.IntFlag{
Name: "lines",
Expand All @@ -132,12 +154,13 @@ func LogsCommand(factory app.ProjectFactory) cli.Command {
// RestartCommand defines the libcompose restart subcommand.
func RestartCommand(factory app.ProjectFactory) cli.Command {
return cli.Command{
Name: "restart",
Usage: "Restart services",
Action: app.WithProject(factory, app.ProjectRestart),
Name: "restart",
Usage: "Restart running containers.",
ArgsUsage: "[SERVICE...]",
Action: app.WithProject(factory, app.ProjectRestart),
Flags: []cli.Flag{
cli.IntFlag{
Name: "timeout,t",
Name: "timeout, t",
Usage: "Specify a shutdown timeout in seconds.",
Value: 10,
},
Expand All @@ -148,10 +171,12 @@ func RestartCommand(factory app.ProjectFactory) cli.Command {
// StopCommand defines the libcompose stop subcommand.
func StopCommand(factory app.ProjectFactory) cli.Command {
return cli.Command{
Name: "stop",
ShortName: "down",
Usage: "Stop services",
Action: app.WithProject(factory, app.ProjectDown),
Name: "stop",
ShortName: "down", // FIXME shouldn't we deprecate that one ?
Usage: "Stop running containers without removing them.",
ArgsUsage: "[SERVICE...]",
Description: "They can be started again with `libcompose-cli start`.",
Action: app.WithProject(factory, app.ProjectDown),
Flags: []cli.Flag{
cli.IntFlag{
Name: "timeout,t",
Expand All @@ -165,8 +190,12 @@ func StopCommand(factory app.ProjectFactory) cli.Command {
// ScaleCommand defines the libcompose scale subcommand.
func ScaleCommand(factory app.ProjectFactory) cli.Command {
return cli.Command{
Name: "scale",
Usage: "Scale services",
Name: "scale",
Usage: "Set number of containers to run for a service.",
ArgsUsage: "[SERVICE=NUM...]",
Description: "Numbers are specified in the form `service=num` as arguments.\n" +
"For example:\n\n" +
" $ libcompose-cli scale web=2 worker=3",
Action: app.WithProject(factory, app.ProjectScale),
Flags: []cli.Flag{
cli.IntFlag{
Expand All @@ -181,9 +210,10 @@ func ScaleCommand(factory app.ProjectFactory) cli.Command {
// RmCommand defines the libcompose rm subcommand.
func RmCommand(factory app.ProjectFactory) cli.Command {
return cli.Command{
Name: "rm",
Usage: "Delete services",
Action: app.WithProject(factory, app.ProjectDelete),
Name: "rm",
Usage: "Remove stopped service containers.",
ArgsUsage: "[SERVICE...]",
Action: app.WithProject(factory, app.ProjectDelete),
Flags: []cli.Flag{
cli.BoolFlag{
Name: "force,f",
Expand All @@ -200,9 +230,10 @@ func RmCommand(factory app.ProjectFactory) cli.Command {
// KillCommand defines the libcompose kill subcommand.
func KillCommand(factory app.ProjectFactory) cli.Command {
return cli.Command{
Name: "kill",
Usage: "Force stop service containers",
Action: app.WithProject(factory, app.ProjectKill),
Name: "kill",
Usage: "Force stop service containers.",
ArgsUsage: "[SERVICE...]",
Action: app.WithProject(factory, app.ProjectKill),
Flags: []cli.Flag{
cli.StringFlag{
Name: "signal,s",
Expand Down
20 changes: 9 additions & 11 deletions cli/command/help.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package command

import (
"github.com/codegangsta/cli"
"os"
"path"

"github.com/codegangsta/cli"
)

func init() {
cli.AppHelpTemplate = `Usage: {{.Name}} {{if .Flags}}[OPTIONS] {{end}}COMMAND [arg...]
cli.AppHelpTemplate = `{{.Usage}}

{{.Usage}}
Usage: {{.Name}} {{if .Flags}}[options] {{end}}COMMAND [arg...]

Version: {{.Version}}{{if or .Author .Email}}

Author:{{if .Author}}
{{.Author}}{{if .Email}} - <{{.Email}}>{{end}}{{else}}
{{.Email}}{{end}}{{end}}
{{if .Flags}}
Options:
{{range .Flags}}{{.}}
Expand All @@ -25,11 +21,13 @@ Commands:
{{end}}
Run '{{.Name}} COMMAND --help' for more information on a command.
`
cli.CommandHelpTemplate = `Usage: ` + path.Base(os.Args[0]) + ` {{.Name}}{{if .Flags}} [OPTIONS]
cli.CommandHelpTemplate = `{{.Usage}}{{if .Description}}

{{.Usage}}
{{.Description}}{{end}}

Options:
Usage: ` + path.Base(os.Args[0]) + ` {{.Name}}{{if .Flags}} [options]{{end}}{{if .ArgsUsage}} {{.ArgsUsage}}{{end}}

{{if .Flags}}Options:
{{range .Flags}}{{.}}
{{end}}{{end}}
`
Expand Down
2 changes: 1 addition & 1 deletion integration/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (s *RunSuite) createCommand(c *C, projectName, command string, argsAndInput

if command == "up" {
args = append(args, "-d")
} else if command == "down" {
} else if command == "stop" {
args = append(args, "--timeout", "0")
} else if command == "restart" {
args = append(args, "--timeout", "0")
Expand Down
2 changes: 1 addition & 1 deletion integration/down_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (s *RunSuite) TestDown(c *C) {
c.Assert(cn, NotNil)
c.Assert(cn.State.Running, Equals, true)

s.FromText(c, p, "down", SimpleTemplate)
s.FromText(c, p, "stop", SimpleTemplate)

cn = s.GetContainerByName(c, name)
c.Assert(cn, NotNil)
Expand Down
2 changes: 1 addition & 1 deletion script/vendor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ rm -rf vendor/
source 'script/.vendor-helpers.sh'

clone git github.com/Sirupsen/logrus v0.8.2
clone git github.com/codegangsta/cli 6086d7927ec35315964d9fea46df6c04e6d697c1
clone git github.com/codegangsta/cli 70e3fa51ebed95df8c0fbe1519c1c1f9bc16bb13
clone git github.com/docker/distribution c6c9194e9c6097f84b0ff468a741086ff7704aa3
clone git github.com/docker/docker 58b270c338e831ac6668a29788c72d202f9fc251
clone git github.com/docker/libtrust 9cbd2a1374f46905c68a4eb3694a130610adc62a
Expand Down
9 changes: 8 additions & 1 deletion vendor/github.com/codegangsta/cli/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading