github.com/sevki/docker@v1.7.1/docker/flags.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 "runtime" 8 "sort" 9 10 "github.com/docker/docker/opts" 11 "github.com/docker/docker/pkg/homedir" 12 flag "github.com/docker/docker/pkg/mflag" 13 ) 14 15 type command struct { 16 name string 17 description string 18 } 19 20 type byName []command 21 22 func (a byName) Len() int { return len(a) } 23 func (a byName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 24 func (a byName) Less(i, j int) bool { return a[i].name < a[j].name } 25 26 var ( 27 dockerCertPath = os.Getenv("DOCKER_CERT_PATH") 28 dockerTlsVerify = os.Getenv("DOCKER_TLS_VERIFY") != "" 29 30 dockerCommands = []command{ 31 {"attach", "Attach to a running container"}, 32 {"build", "Build an image from a Dockerfile"}, 33 {"commit", "Create a new image from a container's changes"}, 34 {"cp", "Copy files/folders from a container's filesystem to the host path"}, 35 {"create", "Create a new container"}, 36 {"diff", "Inspect changes on a container's filesystem"}, 37 {"events", "Get real time events from the server"}, 38 {"exec", "Run a command in a running container"}, 39 {"export", "Stream the contents of a container as a tar archive"}, 40 {"history", "Show the history of an image"}, 41 {"images", "List images"}, 42 {"import", "Create a new filesystem image from the contents of a tarball"}, 43 {"info", "Display system-wide information"}, 44 {"inspect", "Return low-level information on a container or image"}, 45 {"kill", "Kill a running container"}, 46 {"load", "Load an image from a tar archive"}, 47 {"login", "Register or log in to a Docker registry server"}, 48 {"logout", "Log out from a Docker registry server"}, 49 {"logs", "Fetch the logs of a container"}, 50 {"port", "Lookup the public-facing port that is NAT-ed to PRIVATE_PORT"}, 51 {"pause", "Pause all processes within a container"}, 52 {"ps", "List containers"}, 53 {"pull", "Pull an image or a repository from a Docker registry server"}, 54 {"push", "Push an image or a repository to a Docker registry server"}, 55 {"rename", "Rename an existing container"}, 56 {"restart", "Restart a running container"}, 57 {"rm", "Remove one or more containers"}, 58 {"rmi", "Remove one or more images"}, 59 {"run", "Run a command in a new container"}, 60 {"save", "Save an image to a tar archive"}, 61 {"search", "Search for an image on the Docker Hub"}, 62 {"start", "Start a stopped container"}, 63 {"stats", "Display a stream of a containers' resource usage statistics"}, 64 {"stop", "Stop a running container"}, 65 {"tag", "Tag an image into a repository"}, 66 {"top", "Lookup the running processes of a container"}, 67 {"unpause", "Unpause a paused container"}, 68 {"version", "Show the Docker version information"}, 69 {"wait", "Block until a container stops, then print its exit code"}, 70 } 71 ) 72 73 func init() { 74 if dockerCertPath == "" { 75 dockerCertPath = filepath.Join(homedir.Get(), ".docker") 76 } 77 } 78 79 func getDaemonConfDir() string { 80 // TODO: update for Windows daemon 81 if runtime.GOOS == "windows" { 82 return filepath.Join(homedir.Get(), ".docker") 83 } 84 return "/etc/docker" 85 } 86 87 var ( 88 flVersion = flag.Bool([]string{"v", "-version"}, false, "Print version information and quit") 89 flDaemon = flag.Bool([]string{"d", "-daemon"}, false, "Enable daemon mode") 90 flDebug = flag.Bool([]string{"D", "-debug"}, false, "Enable debug mode") 91 flLogLevel = flag.String([]string{"l", "-log-level"}, "info", "Set the logging level") 92 flTls = flag.Bool([]string{"-tls"}, false, "Use TLS; implied by --tlsverify") 93 flHelp = flag.Bool([]string{"h", "-help"}, false, "Print usage") 94 flTlsVerify = flag.Bool([]string{"-tlsverify"}, dockerTlsVerify, "Use TLS and verify the remote") 95 96 // these are initialized in init() below since their default values depend on dockerCertPath which isn't fully initialized until init() runs 97 flTrustKey *string 98 flCa *string 99 flCert *string 100 flKey *string 101 flHosts []string 102 ) 103 104 func setDefaultConfFlag(flag *string, def string) { 105 if *flag == "" { 106 if *flDaemon { 107 *flag = filepath.Join(getDaemonConfDir(), def) 108 } else { 109 *flag = filepath.Join(homedir.Get(), ".docker", def) 110 } 111 } 112 } 113 114 func init() { 115 var placeholderTrustKey string 116 // TODO use flag flag.String([]string{"i", "-identity"}, "", "Path to libtrust key file") 117 flTrustKey = &placeholderTrustKey 118 119 flCa = flag.String([]string{"-tlscacert"}, filepath.Join(dockerCertPath, defaultCaFile), "Trust certs signed only by this CA") 120 flCert = flag.String([]string{"-tlscert"}, filepath.Join(dockerCertPath, defaultCertFile), "Path to TLS certificate file") 121 flKey = flag.String([]string{"-tlskey"}, filepath.Join(dockerCertPath, defaultKeyFile), "Path to TLS key file") 122 opts.HostListVar(&flHosts, []string{"H", "-host"}, "Daemon socket(s) to connect to") 123 124 flag.Usage = func() { 125 fmt.Fprint(os.Stdout, "Usage: docker [OPTIONS] COMMAND [arg...]\n\nA self-sufficient runtime for linux containers.\n\nOptions:\n") 126 127 flag.CommandLine.SetOutput(os.Stdout) 128 flag.PrintDefaults() 129 130 help := "\nCommands:\n" 131 132 sort.Sort(byName(dockerCommands)) 133 134 for _, cmd := range dockerCommands { 135 help += fmt.Sprintf(" %-10.10s%s\n", cmd.name, cmd.description) 136 } 137 138 help += "\nRun 'docker COMMAND --help' for more information on a command." 139 fmt.Fprintf(os.Stdout, "%s\n", help) 140 } 141 }