mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
96ce3a194a
This patch creates a new cli package that allows to combine both client and daemon commands (there is only one daemon command: docker daemon). The `-d` and `--daemon` top-level flags are deprecated and a special message is added to prompt the user to use `docker daemon`. Providing top-level daemon-specific flags for client commands result in an error message prompting the user to use `docker daemon`. This patch does not break any old but correct usages. This also makes `-d` and `--daemon` flags, as well as the `daemon` command illegal in client-only binaries. Signed-off-by: Tibor Vass <tibor@docker.com>
88 lines
2.2 KiB
Go
88 lines
2.2 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"sort"
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
"github.com/docker/docker/api/client"
|
|
"github.com/docker/docker/autogen/dockerversion"
|
|
"github.com/docker/docker/cli"
|
|
flag "github.com/docker/docker/pkg/mflag"
|
|
"github.com/docker/docker/pkg/reexec"
|
|
"github.com/docker/docker/pkg/term"
|
|
"github.com/docker/docker/utils"
|
|
)
|
|
|
|
func main() {
|
|
if reexec.Init() {
|
|
return
|
|
}
|
|
|
|
// Set terminal emulation based on platform as required.
|
|
stdin, stdout, stderr := term.StdStreams()
|
|
|
|
logrus.SetOutput(stderr)
|
|
|
|
flag.Merge(flag.CommandLine, clientFlags.FlagSet, commonFlags.FlagSet)
|
|
|
|
flag.Usage = func() {
|
|
fmt.Fprint(os.Stdout, "Usage: docker [OPTIONS] COMMAND [arg...]\n"+daemonUsage+" docker [ -h | --help | -v | --version ]\n\n")
|
|
fmt.Fprint(os.Stdout, "A self-sufficient runtime for containers.\n\nOptions:\n")
|
|
|
|
flag.CommandLine.SetOutput(os.Stdout)
|
|
flag.PrintDefaults()
|
|
|
|
help := "\nCommands:\n"
|
|
|
|
// TODO(tiborvass): no need to sort if we ensure dockerCommands is sorted
|
|
sort.Sort(byName(dockerCommands))
|
|
|
|
for _, cmd := range dockerCommands {
|
|
help += fmt.Sprintf(" %-10.10s%s\n", cmd.name, cmd.description)
|
|
}
|
|
|
|
help += "\nRun 'docker COMMAND --help' for more information on a command."
|
|
fmt.Fprintf(os.Stdout, "%s\n", help)
|
|
}
|
|
|
|
flag.Parse()
|
|
|
|
if *flVersion {
|
|
showVersion()
|
|
return
|
|
}
|
|
|
|
clientCli := client.NewDockerCli(stdin, stdout, stderr, clientFlags)
|
|
// TODO: remove once `-d` is retired
|
|
handleGlobalDaemonFlag()
|
|
|
|
if *flHelp {
|
|
// if global flag --help is present, regardless of what other options and commands there are,
|
|
// just print the usage.
|
|
flag.Usage()
|
|
return
|
|
}
|
|
|
|
c := cli.New(clientCli, daemonCli)
|
|
if err := c.Run(flag.Args()...); err != nil {
|
|
if sterr, ok := err.(cli.StatusError); ok {
|
|
if sterr.Status != "" {
|
|
fmt.Fprintln(os.Stderr, sterr.Status)
|
|
os.Exit(1)
|
|
}
|
|
os.Exit(sterr.StatusCode)
|
|
}
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func showVersion() {
|
|
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)
|
|
}
|
|
}
|