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