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