github.com/skippbox/kompose-origin@v0.0.0-20160524133224-16a9dca7bac2/cli/command/command.go (about)

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