github.com/fntlnz/docker@v1.9.0-rc3/docker/docker.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 7 "github.com/Sirupsen/logrus" 8 "github.com/docker/docker/api/client" 9 "github.com/docker/docker/autogen/dockerversion" 10 "github.com/docker/docker/cli" 11 flag "github.com/docker/docker/pkg/mflag" 12 "github.com/docker/docker/pkg/reexec" 13 "github.com/docker/docker/pkg/term" 14 "github.com/docker/docker/utils" 15 ) 16 17 func main() { 18 if reexec.Init() { 19 return 20 } 21 22 // Set terminal emulation based on platform as required. 23 stdin, stdout, stderr := term.StdStreams() 24 25 logrus.SetOutput(stderr) 26 27 flag.Merge(flag.CommandLine, clientFlags.FlagSet, commonFlags.FlagSet) 28 29 flag.Usage = func() { 30 fmt.Fprint(os.Stdout, "Usage: docker [OPTIONS] COMMAND [arg...]\n"+daemonUsage+" docker [ --help | -v | --version ]\n\n") 31 fmt.Fprint(os.Stdout, "A self-sufficient runtime for containers.\n\nOptions:\n") 32 33 flag.CommandLine.SetOutput(os.Stdout) 34 flag.PrintDefaults() 35 36 help := "\nCommands:\n" 37 38 for _, cmd := range dockerCommands { 39 help += fmt.Sprintf(" %-10.10s%s\n", cmd.Name, cmd.Description) 40 } 41 42 help += "\nRun 'docker COMMAND --help' for more information on a command." 43 fmt.Fprintf(os.Stdout, "%s\n", help) 44 } 45 46 flag.Parse() 47 48 if *flVersion { 49 showVersion() 50 return 51 } 52 53 if *flHelp { 54 // if global flag --help is present, regardless of what other options and commands there are, 55 // just print the usage. 56 flag.Usage() 57 return 58 } 59 60 // TODO: remove once `-d` is retired 61 handleGlobalDaemonFlag() 62 clientCli := client.NewDockerCli(stdin, stdout, stderr, clientFlags) 63 64 c := cli.New(clientCli, daemonCli) 65 if err := c.Run(flag.Args()...); err != nil { 66 if sterr, ok := err.(cli.StatusError); ok { 67 if sterr.Status != "" { 68 fmt.Fprintln(os.Stderr, sterr.Status) 69 os.Exit(1) 70 } 71 os.Exit(sterr.StatusCode) 72 } 73 fmt.Fprintln(os.Stderr, err) 74 os.Exit(1) 75 } 76 } 77 78 func showVersion() { 79 if utils.ExperimentalBuild() { 80 fmt.Printf("Docker version %s, build %s, experimental\n", dockerversion.VERSION, dockerversion.GITCOMMIT) 81 } else { 82 fmt.Printf("Docker version %s, build %s\n", dockerversion.VERSION, dockerversion.GITCOMMIT) 83 } 84 }