mirror of
https://github.com/rancher/os.git
synced 2025-09-01 23:04:41 +00:00
move dependencies to vendor
This commit is contained in:
229
vendor/github.com/docker/libcompose/cli/app/app.go
generated
vendored
Normal file
229
vendor/github.com/docker/libcompose/cli/app/app.go
generated
vendored
Normal file
@@ -0,0 +1,229 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/docker/libcompose/project"
|
||||
)
|
||||
|
||||
// ProjectAction is an adapter to allow the use of ordinary functions as libcompose actions.
|
||||
// Any function that has the appropriate signature can be register as an action on a codegansta/cli command.
|
||||
//
|
||||
// cli.Command{
|
||||
// Name: "ps",
|
||||
// Usage: "List containers",
|
||||
// Action: app.WithProject(factory, app.ProjectPs),
|
||||
// }
|
||||
type ProjectAction func(project *project.Project, c *cli.Context)
|
||||
|
||||
// BeforeApp is an action that is executed before any cli command.
|
||||
func BeforeApp(c *cli.Context) error {
|
||||
if c.GlobalBool("verbose") {
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
}
|
||||
logrus.Warning("Note: This is an experimental alternate implementation of the Compose CLI (https://github.com/docker/compose)")
|
||||
return nil
|
||||
}
|
||||
|
||||
// WithProject is an helper function to create a cli.Command action with a ProjectFactory.
|
||||
func WithProject(factory ProjectFactory, action ProjectAction) func(context *cli.Context) {
|
||||
return func(context *cli.Context) {
|
||||
p, err := factory.Create(context)
|
||||
if err != nil {
|
||||
logrus.Fatalf("Failed to read project: %v", err)
|
||||
}
|
||||
action(p, context)
|
||||
}
|
||||
}
|
||||
|
||||
// ProjectPs lists the containers.
|
||||
func ProjectPs(p *project.Project, c *cli.Context) {
|
||||
allInfo := project.InfoSet{}
|
||||
qFlag := c.Bool("q")
|
||||
for name := range p.Configs {
|
||||
service, err := p.CreateService(name)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
info, err := service.Info(qFlag)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
allInfo = append(allInfo, info...)
|
||||
}
|
||||
|
||||
os.Stdout.WriteString(allInfo.String(!qFlag))
|
||||
}
|
||||
|
||||
// ProjectPort prints the public port for a port binding.
|
||||
func ProjectPort(p *project.Project, c *cli.Context) {
|
||||
if len(c.Args()) != 2 {
|
||||
logrus.Fatalf("Please pass arguments in the form: SERVICE PORT")
|
||||
}
|
||||
|
||||
index := c.Int("index")
|
||||
protocol := c.String("protocol")
|
||||
|
||||
service, err := p.CreateService(c.Args()[0])
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
containers, err := service.Containers()
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if index < 1 || index > len(containers) {
|
||||
logrus.Fatalf("Invalid index %d", index)
|
||||
}
|
||||
|
||||
output, err := containers[index-1].Port(fmt.Sprintf("%s/%s", c.Args()[1], protocol))
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
fmt.Println(output)
|
||||
}
|
||||
|
||||
// ProjectDown brings all services down.
|
||||
func ProjectDown(p *project.Project, c *cli.Context) {
|
||||
err := p.Down(c.Args()...)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// ProjectBuild builds or rebuilds services.
|
||||
func ProjectBuild(p *project.Project, c *cli.Context) {
|
||||
err := p.Build(c.Args()...)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// ProjectCreate creates all services but do not start them.
|
||||
func ProjectCreate(p *project.Project, c *cli.Context) {
|
||||
err := p.Create(c.Args()...)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// ProjectUp brings all services up.
|
||||
func ProjectUp(p *project.Project, c *cli.Context) {
|
||||
err := p.Up(c.Args()...)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if !c.Bool("d") {
|
||||
wait()
|
||||
}
|
||||
}
|
||||
|
||||
// ProjectStart starts services.
|
||||
func ProjectStart(p *project.Project, c *cli.Context) {
|
||||
err := p.Start(c.Args()...)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// ProjectRestart restarts services.
|
||||
func ProjectRestart(p *project.Project, c *cli.Context) {
|
||||
err := p.Restart(c.Args()...)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// ProjectLog gets services logs.
|
||||
func ProjectLog(p *project.Project, c *cli.Context) {
|
||||
err := p.Log(c.Args()...)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
wait()
|
||||
}
|
||||
|
||||
// ProjectPull pulls images for services.
|
||||
func ProjectPull(p *project.Project, c *cli.Context) {
|
||||
err := p.Pull(c.Args()...)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// ProjectDelete delete services.
|
||||
func ProjectDelete(p *project.Project, c *cli.Context) {
|
||||
if !c.Bool("force") && len(c.Args()) == 0 {
|
||||
logrus.Fatal("Will not remove all services without --force")
|
||||
}
|
||||
err := p.Delete(c.Args()...)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// ProjectKill forces stop service containers.
|
||||
func ProjectKill(p *project.Project, c *cli.Context) {
|
||||
err := p.Kill(c.Args()...)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// ProjectScale scales services.
|
||||
func ProjectScale(p *project.Project, c *cli.Context) {
|
||||
// This code is a bit verbose but I wanted to parse everything up front
|
||||
order := make([]string, 0, 0)
|
||||
serviceScale := make(map[string]int)
|
||||
services := make(map[string]project.Service)
|
||||
|
||||
for _, arg := range c.Args() {
|
||||
kv := strings.SplitN(arg, "=", 2)
|
||||
if len(kv) != 2 {
|
||||
logrus.Fatalf("Invalid scale parameter: %s", arg)
|
||||
}
|
||||
|
||||
name := kv[0]
|
||||
|
||||
count, err := strconv.Atoi(kv[1])
|
||||
if err != nil {
|
||||
logrus.Fatalf("Invalid scale parameter: %v", err)
|
||||
}
|
||||
|
||||
if _, ok := p.Configs[name]; !ok {
|
||||
logrus.Fatalf("%s is not defined in the template", name)
|
||||
}
|
||||
|
||||
service, err := p.CreateService(name)
|
||||
if err != nil {
|
||||
logrus.Fatalf("Failed to lookup service: %s: %v", service, err)
|
||||
}
|
||||
|
||||
order = append(order, name)
|
||||
serviceScale[name] = count
|
||||
services[name] = service
|
||||
}
|
||||
|
||||
for _, name := range order {
|
||||
scale := serviceScale[name]
|
||||
logrus.Infof("Setting scale %s=%d...", name, scale)
|
||||
err := services[name].Scale(scale)
|
||||
if err != nil {
|
||||
logrus.Fatalf("Failed to set the scale %s=%d: %v", name, scale, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func wait() {
|
||||
<-make(chan interface{})
|
||||
}
|
12
vendor/github.com/docker/libcompose/cli/app/types.go
generated
vendored
Normal file
12
vendor/github.com/docker/libcompose/cli/app/types.go
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/docker/libcompose/project"
|
||||
)
|
||||
|
||||
// ProjectFactory is an interface that helps creating libcompose project.
|
||||
type ProjectFactory interface {
|
||||
// Create creates a libcompose project from the command line options (codegangsta cli context).
|
||||
Create(c *cli.Context) (*project.Project, error)
|
||||
}
|
247
vendor/github.com/docker/libcompose/cli/command/command.go
generated
vendored
Normal file
247
vendor/github.com/docker/libcompose/cli/command/command.go
generated
vendored
Normal file
@@ -0,0 +1,247 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/docker/libcompose/cli/app"
|
||||
"github.com/docker/libcompose/project"
|
||||
)
|
||||
|
||||
// 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),
|
||||
}
|
||||
}
|
||||
|
||||
// BuildCommand defines the libcompose build subcommand.
|
||||
func BuildCommand(factory app.ProjectFactory) cli.Command {
|
||||
return cli.Command{
|
||||
Name: "build",
|
||||
Usage: "Build or rebuild services.",
|
||||
Action: app.WithProject(factory, app.ProjectBuild),
|
||||
}
|
||||
}
|
||||
|
||||
// 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),
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "q",
|
||||
Usage: "Only display IDs",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// 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),
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "protocol",
|
||||
Usage: "tcp or udp ",
|
||||
Value: "tcp",
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "index",
|
||||
Usage: "index of the container if there are multiple instances of a service",
|
||||
Value: 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// UpCommand defines the libcompose up subcommand.
|
||||
func UpCommand(factory app.ProjectFactory) cli.Command {
|
||||
return cli.Command{
|
||||
Name: "up",
|
||||
Usage: "Bring all services up",
|
||||
Action: app.WithProject(factory, app.ProjectUp),
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "d",
|
||||
Usage: "Do not block and log",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "no-recreate",
|
||||
Usage: "If containers already exist, don't recreate them. Incompatible with --force-recreate.",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "force-recreate",
|
||||
Usage: "Recreate containers even if their configuration and image haven't changed. Incompatible with --no-recreate.",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// 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),
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolTFlag{
|
||||
Name: "d",
|
||||
Usage: "Do not block and log",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// 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),
|
||||
}
|
||||
}
|
||||
|
||||
// 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),
|
||||
Flags: []cli.Flag{
|
||||
cli.IntFlag{
|
||||
Name: "lines",
|
||||
Usage: "number of lines to tail",
|
||||
Value: 100,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// 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),
|
||||
Flags: []cli.Flag{
|
||||
cli.IntFlag{
|
||||
Name: "timeout,t",
|
||||
Usage: "Specify a shutdown timeout in seconds.",
|
||||
Value: 10,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// 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),
|
||||
Flags: []cli.Flag{
|
||||
cli.IntFlag{
|
||||
Name: "timeout,t",
|
||||
Usage: "Specify a shutdown timeout in seconds.",
|
||||
Value: 10,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// ScaleCommand defines the libcompose scale subcommand.
|
||||
func ScaleCommand(factory app.ProjectFactory) cli.Command {
|
||||
return cli.Command{
|
||||
Name: "scale",
|
||||
Usage: "Scale services",
|
||||
Action: app.WithProject(factory, app.ProjectScale),
|
||||
Flags: []cli.Flag{
|
||||
cli.IntFlag{
|
||||
Name: "timeout,t",
|
||||
Usage: "Specify a shutdown timeout in seconds.",
|
||||
Value: 10,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// 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),
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "force,f",
|
||||
Usage: "Allow deletion of all services",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "v",
|
||||
Usage: "Remove volumes associated with containers",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// 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),
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "signal,s",
|
||||
Usage: "SIGNAL to send to the container",
|
||||
Value: "SIGKILL",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// CommonFlags defines the flags that are in common for all subcommands.
|
||||
func CommonFlags() []cli.Flag {
|
||||
return []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "verbose,debug",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "file,f",
|
||||
Usage: "Specify an alternate compose file (default: docker-compose.yml)",
|
||||
Value: "docker-compose.yml",
|
||||
EnvVar: "COMPOSE_FILE",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "project-name,p",
|
||||
Usage: "Specify an alternate project name (default: directory name)",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Populate updates the specified project context based on command line arguments and subcommands.
|
||||
func Populate(context *project.Context, c *cli.Context) {
|
||||
context.ComposeFile = c.GlobalString("file")
|
||||
context.ProjectName = c.GlobalString("project-name")
|
||||
|
||||
if c.Command.Name == "logs" {
|
||||
context.Log = true
|
||||
} else if c.Command.Name == "up" {
|
||||
context.Log = !c.Bool("d")
|
||||
context.NoRecreate = c.Bool("no-recreate")
|
||||
context.ForceRecreate = c.Bool("force-recreate")
|
||||
} else if c.Command.Name == "stop" || c.Command.Name == "restart" || c.Command.Name == "scale" {
|
||||
context.Timeout = uint(c.Int("timeout"))
|
||||
} else if c.Command.Name == "kill" {
|
||||
context.Signal = c.Int("signal")
|
||||
} else if c.Command.Name == "rm" {
|
||||
context.Volume = c.Bool("v")
|
||||
}
|
||||
}
|
37
vendor/github.com/docker/libcompose/cli/command/help.go
generated
vendored
Normal file
37
vendor/github.com/docker/libcompose/cli/command/help.go
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"github.com/codegangsta/cli"
|
||||
"os"
|
||||
"path"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cli.AppHelpTemplate = `Usage: {{.Name}} {{if .Flags}}[OPTIONS] {{end}}COMMAND [arg...]
|
||||
|
||||
{{.Usage}}
|
||||
|
||||
Version: {{.Version}}{{if or .Author .Email}}
|
||||
|
||||
Author:{{if .Author}}
|
||||
{{.Author}}{{if .Email}} - <{{.Email}}>{{end}}{{else}}
|
||||
{{.Email}}{{end}}{{end}}
|
||||
{{if .Flags}}
|
||||
Options:
|
||||
{{range .Flags}}{{.}}
|
||||
{{end}}{{end}}
|
||||
Commands:
|
||||
{{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
|
||||
{{end}}
|
||||
Run '{{.Name}} COMMAND --help' for more information on a command.
|
||||
`
|
||||
cli.CommandHelpTemplate = `Usage: ` + path.Base(os.Args[0]) + ` {{.Name}}{{if .Flags}} [OPTIONS]
|
||||
|
||||
{{.Usage}}
|
||||
|
||||
Options:
|
||||
{{range .Flags}}{{.}}
|
||||
{{end}}{{end}}
|
||||
`
|
||||
|
||||
}
|
58
vendor/github.com/docker/libcompose/cli/docker/app/commands.go
generated
vendored
Normal file
58
vendor/github.com/docker/libcompose/cli/docker/app/commands.go
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/docker/libcompose/docker"
|
||||
)
|
||||
|
||||
// DockerClientFlags defines the flags that are specific to the docker client,
|
||||
// like configdir or tls related flags.
|
||||
func DockerClientFlags() []cli.Flag {
|
||||
return []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "tls",
|
||||
Usage: "Use TLS; implied by --tlsverify",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "tlsverify",
|
||||
Usage: "Use TLS and verify the remote",
|
||||
EnvVar: "DOCKER_TLS_VERIFY",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "tlscacert",
|
||||
Usage: "Trust certs signed only by this CA",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "tlscert",
|
||||
Usage: "Path to TLS certificate file",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "tlskey",
|
||||
Usage: "Path to TLS key file",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "configdir",
|
||||
Usage: "Path to docker config dir, default ${HOME}/.docker",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Populate updates the specified docker context based on command line arguments and subcommands.
|
||||
func Populate(context *docker.Context, c *cli.Context) {
|
||||
context.ConfigDir = c.String("configdir")
|
||||
|
||||
opts := docker.ClientOpts{}
|
||||
opts.TLS = c.GlobalBool("tls")
|
||||
opts.TLSVerify = c.GlobalBool("tlsverify")
|
||||
opts.TLSOptions.CAFile = c.GlobalString("tlscacert")
|
||||
opts.TLSOptions.CertFile = c.GlobalString("tlscert")
|
||||
opts.TLSOptions.KeyFile = c.GlobalString("tlskey")
|
||||
|
||||
clientFactory, err := docker.NewDefaultClientFactory(opts)
|
||||
if err != nil {
|
||||
logrus.Fatalf("Failed to construct Docker client: %v", err)
|
||||
}
|
||||
|
||||
context.ClientFactory = clientFactory
|
||||
}
|
23
vendor/github.com/docker/libcompose/cli/docker/app/factory.go
generated
vendored
Normal file
23
vendor/github.com/docker/libcompose/cli/docker/app/factory.go
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/docker/libcompose/cli/command"
|
||||
"github.com/docker/libcompose/cli/logger"
|
||||
"github.com/docker/libcompose/docker"
|
||||
"github.com/docker/libcompose/project"
|
||||
)
|
||||
|
||||
// ProjectFactory is a struct that hold the app.ProjectFactory implementation.
|
||||
type ProjectFactory struct {
|
||||
}
|
||||
|
||||
// Create implements ProjectFactory.Create using docker client.
|
||||
func (p *ProjectFactory) Create(c *cli.Context) (*project.Project, error) {
|
||||
context := &docker.Context{}
|
||||
context.LoggerFactory = logger.NewColorLoggerFactory()
|
||||
Populate(context, c)
|
||||
command.Populate(&context.Context, c)
|
||||
|
||||
return docker.NewProject(context)
|
||||
}
|
76
vendor/github.com/docker/libcompose/cli/logger/color_logger.go
generated
vendored
Normal file
76
vendor/github.com/docker/libcompose/cli/logger/color_logger.go
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/docker/libcompose/logger"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
)
|
||||
|
||||
// ColorLoggerFactory implements logger.Factory interface using ColorLogger.
|
||||
type ColorLoggerFactory struct {
|
||||
maxLength int
|
||||
tty bool
|
||||
}
|
||||
|
||||
// ColorLogger implements logger.Logger interface with color support.
|
||||
type ColorLogger struct {
|
||||
name string
|
||||
colorPrefix string
|
||||
factory *ColorLoggerFactory
|
||||
}
|
||||
|
||||
// NewColorLoggerFactory creates a new ColorLoggerFactory.
|
||||
func NewColorLoggerFactory() *ColorLoggerFactory {
|
||||
return &ColorLoggerFactory{
|
||||
tty: terminal.IsTerminal(int(os.Stdout.Fd())),
|
||||
}
|
||||
}
|
||||
|
||||
// Create implements logger.Factory.Create.
|
||||
func (c *ColorLoggerFactory) Create(name string) logger.Logger {
|
||||
if c.maxLength < len(name) {
|
||||
c.maxLength = len(name)
|
||||
}
|
||||
|
||||
return &ColorLogger{
|
||||
name: name,
|
||||
factory: c,
|
||||
colorPrefix: <-colorPrefix,
|
||||
}
|
||||
}
|
||||
|
||||
// Out implements logger.Logger.Out.
|
||||
func (c *ColorLogger) Out(bytes []byte) {
|
||||
if len(bytes) == 0 {
|
||||
return
|
||||
}
|
||||
logFmt, name := c.getLogFmt()
|
||||
message := fmt.Sprintf(logFmt, name, string(bytes))
|
||||
fmt.Print(message)
|
||||
}
|
||||
|
||||
// Err implements logger.Logger.Err.
|
||||
func (c *ColorLogger) Err(bytes []byte) {
|
||||
if len(bytes) == 0 {
|
||||
return
|
||||
}
|
||||
logFmt, name := c.getLogFmt()
|
||||
message := fmt.Sprintf(logFmt, name, string(bytes))
|
||||
fmt.Fprint(os.Stderr, message)
|
||||
}
|
||||
|
||||
func (c *ColorLogger) getLogFmt() (string, string) {
|
||||
pad := c.factory.maxLength
|
||||
|
||||
logFmt := "%s | %s"
|
||||
if c.factory.tty {
|
||||
logFmt = c.colorPrefix + " %s"
|
||||
}
|
||||
|
||||
name := fmt.Sprintf("%-"+strconv.Itoa(pad)+"s", c.name)
|
||||
|
||||
return logFmt, name
|
||||
}
|
34
vendor/github.com/docker/libcompose/cli/logger/colors.go
generated
vendored
Normal file
34
vendor/github.com/docker/libcompose/cli/logger/colors.go
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
package logger
|
||||
|
||||
import "fmt"
|
||||
|
||||
var (
|
||||
colorPrefix = make(chan string)
|
||||
)
|
||||
|
||||
func generateColors() {
|
||||
i := 0
|
||||
colorOrder := []string{
|
||||
"36", // cyan
|
||||
"33", // yellow
|
||||
"32", // green
|
||||
"35", // magenta
|
||||
"31", // red
|
||||
"34", // blue
|
||||
"36;1", // intense cyan
|
||||
"33;1", // intense yellow
|
||||
"32;1", // intense green
|
||||
"35;1", // intense magenta
|
||||
"31;1", // intense red
|
||||
"34;1", // intense blue
|
||||
}
|
||||
|
||||
for {
|
||||
colorPrefix <- fmt.Sprintf("\033[%sm%%s |\033[0m", colorOrder[i])
|
||||
i = (i + 1) % len(colorOrder)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
go generateColors()
|
||||
}
|
41
vendor/github.com/docker/libcompose/cli/main/main.go
generated
vendored
Normal file
41
vendor/github.com/docker/libcompose/cli/main/main.go
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
cliApp "github.com/docker/libcompose/cli/app"
|
||||
"github.com/docker/libcompose/cli/command"
|
||||
dockerApp "github.com/docker/libcompose/cli/docker/app"
|
||||
"github.com/docker/libcompose/version"
|
||||
)
|
||||
|
||||
func main() {
|
||||
factory := &dockerApp.ProjectFactory{}
|
||||
|
||||
app := cli.NewApp()
|
||||
app.Name = "libcompose-cli"
|
||||
app.Usage = "Command line interface for libcompose."
|
||||
app.Version = version.VERSION + " (" + version.GITCOMMIT + ")"
|
||||
app.Author = "Docker Compose Contributors"
|
||||
app.Email = "https://github.com/docker/libcompose"
|
||||
app.Before = cliApp.BeforeApp
|
||||
app.Flags = append(command.CommonFlags(), dockerApp.DockerClientFlags()...)
|
||||
app.Commands = []cli.Command{
|
||||
command.BuildCommand(factory),
|
||||
command.CreateCommand(factory),
|
||||
command.UpCommand(factory),
|
||||
command.StartCommand(factory),
|
||||
command.LogsCommand(factory),
|
||||
command.RestartCommand(factory),
|
||||
command.StopCommand(factory),
|
||||
command.ScaleCommand(factory),
|
||||
command.RmCommand(factory),
|
||||
command.PullCommand(factory),
|
||||
command.KillCommand(factory),
|
||||
command.PortCommand(factory),
|
||||
command.PsCommand(factory),
|
||||
}
|
||||
|
||||
app.Run(os.Args)
|
||||
}
|
Reference in New Issue
Block a user