2013-01-19 19:07:19 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2013-04-10 06:24:15 -04:00
|
|
|
"fmt"
|
2014-02-01 06:38:39 -05:00
|
|
|
"os"
|
|
|
|
|
2015-03-26 18:22:04 -04:00
|
|
|
"github.com/Sirupsen/logrus"
|
2014-07-24 18:19:50 -04:00
|
|
|
"github.com/docker/docker/api/client"
|
2015-02-04 16:22:38 -05:00
|
|
|
"github.com/docker/docker/autogen/dockerversion"
|
2015-05-05 00:18:28 -04:00
|
|
|
"github.com/docker/docker/cli"
|
2014-07-24 18:19:50 -04:00
|
|
|
flag "github.com/docker/docker/pkg/mflag"
|
2014-10-30 08:48:30 -04:00
|
|
|
"github.com/docker/docker/pkg/reexec"
|
2015-01-23 20:33:49 -05:00
|
|
|
"github.com/docker/docker/pkg/term"
|
2015-05-28 20:59:07 -04:00
|
|
|
"github.com/docker/docker/utils"
|
2013-01-24 02:14:46 -05:00
|
|
|
)
|
|
|
|
|
2013-01-19 19:07:19 -05:00
|
|
|
func main() {
|
2015-03-19 21:07:56 -04:00
|
|
|
if reexec.Init() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-03-05 19:41:48 -05:00
|
|
|
// Set terminal emulation based on platform as required.
|
2015-03-22 12:55:21 -04:00
|
|
|
stdin, stdout, stderr := term.StdStreams()
|
2015-03-05 19:41:48 -05:00
|
|
|
|
2015-05-05 00:18:28 -04:00
|
|
|
logrus.SetOutput(stderr)
|
2015-03-05 19:41:48 -05:00
|
|
|
|
2015-05-05 00:18:28 -04:00
|
|
|
flag.Merge(flag.CommandLine, clientFlags.FlagSet, commonFlags.FlagSet)
|
2013-10-04 22:25:15 -04:00
|
|
|
|
2015-05-05 00:18:28 -04:00
|
|
|
flag.Usage = func() {
|
2015-08-10 10:07:50 -04:00
|
|
|
fmt.Fprint(os.Stdout, "Usage: docker [OPTIONS] COMMAND [arg...]\n"+daemonUsage+" docker [ --help | -v | --version ]\n\n")
|
2015-05-05 00:18:28 -04:00
|
|
|
fmt.Fprint(os.Stdout, "A self-sufficient runtime for containers.\n\nOptions:\n")
|
2014-10-01 09:07:24 -04:00
|
|
|
|
2015-05-05 00:18:28 -04:00
|
|
|
flag.CommandLine.SetOutput(os.Stdout)
|
|
|
|
flag.PrintDefaults()
|
2015-04-28 11:00:18 -04:00
|
|
|
|
2015-05-05 00:18:28 -04:00
|
|
|
help := "\nCommands:\n"
|
2014-10-01 09:07:24 -04:00
|
|
|
|
2015-05-05 00:18:28 -04:00
|
|
|
for _, cmd := range dockerCommands {
|
|
|
|
help += fmt.Sprintf(" %-10.10s%s\n", cmd.name, cmd.description)
|
2014-02-17 14:35:26 -05:00
|
|
|
}
|
2015-01-21 11:14:30 -05:00
|
|
|
|
2015-05-05 00:18:28 -04:00
|
|
|
help += "\nRun 'docker COMMAND --help' for more information on a command."
|
|
|
|
fmt.Fprintf(os.Stdout, "%s\n", help)
|
2015-05-07 12:49:07 -04:00
|
|
|
}
|
|
|
|
|
2015-05-05 00:18:28 -04:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if *flVersion {
|
|
|
|
showVersion()
|
2014-08-01 13:34:06 -04:00
|
|
|
return
|
2014-06-27 09:55:20 -04:00
|
|
|
}
|
|
|
|
|
2015-05-05 00:18:28 -04:00
|
|
|
clientCli := client.NewDockerCli(stdin, stdout, stderr, clientFlags)
|
|
|
|
// TODO: remove once `-d` is retired
|
|
|
|
handleGlobalDaemonFlag()
|
2015-05-07 12:49:07 -04:00
|
|
|
|
2015-05-05 00:18:28 -04:00
|
|
|
if *flHelp {
|
|
|
|
// if global flag --help is present, regardless of what other options and commands there are,
|
|
|
|
// just print the usage.
|
|
|
|
flag.Usage()
|
|
|
|
return
|
2014-08-01 13:34:06 -04:00
|
|
|
}
|
2014-03-19 18:03:11 -04:00
|
|
|
|
2015-05-05 00:18:28 -04:00
|
|
|
c := cli.New(clientCli, daemonCli)
|
|
|
|
if err := c.Run(flag.Args()...); err != nil {
|
|
|
|
if sterr, ok := err.(cli.StatusError); ok {
|
2014-08-01 13:34:06 -04:00
|
|
|
if sterr.Status != "" {
|
2015-05-05 00:18:28 -04:00
|
|
|
fmt.Fprintln(os.Stderr, sterr.Status)
|
2015-05-09 14:33:06 -04:00
|
|
|
os.Exit(1)
|
2013-09-09 17:26:35 -04:00
|
|
|
}
|
2014-08-01 13:34:06 -04:00
|
|
|
os.Exit(sterr.StatusCode)
|
2013-03-13 03:29:40 -04:00
|
|
|
}
|
2015-05-05 00:18:28 -04:00
|
|
|
fmt.Fprintln(os.Stderr, err)
|
2015-05-09 14:33:06 -04:00
|
|
|
os.Exit(1)
|
2013-03-13 03:29:40 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-06 23:51:12 -04:00
|
|
|
func showVersion() {
|
2015-05-28 20:59:07 -04:00
|
|
|
if utils.ExperimentalBuild() {
|
|
|
|
fmt.Printf("Docker version %s, build %s, experimental\n", dockerversion.VERSION, dockerversion.GITCOMMIT)
|
|
|
|
} else {
|
|
|
|
fmt.Printf("Docker version %s, build %s\n", dockerversion.VERSION, dockerversion.GITCOMMIT)
|
|
|
|
}
|
2013-08-06 23:51:12 -04:00
|
|
|
}
|