github.com/titanous/docker@v1.4.1/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  	flag "github.com/docker/docker/pkg/mflag"
    11  )
    12  
    13  var (
    14  	dockerCertPath  = os.Getenv("DOCKER_CERT_PATH")
    15  	dockerTlsVerify = os.Getenv("DOCKER_TLS_VERIFY") != ""
    16  )
    17  
    18  func init() {
    19  	if dockerCertPath == "" {
    20  		dockerCertPath = filepath.Join(getHomeDir(), ".docker")
    21  	}
    22  }
    23  
    24  func getHomeDir() string {
    25  	if runtime.GOOS == "windows" {
    26  		return os.Getenv("USERPROFILE")
    27  	}
    28  	return os.Getenv("HOME")
    29  }
    30  
    31  var (
    32  	flVersion     = flag.Bool([]string{"v", "-version"}, false, "Print version information and quit")
    33  	flDaemon      = flag.Bool([]string{"d", "-daemon"}, false, "Enable daemon mode")
    34  	flDebug       = flag.Bool([]string{"D", "-debug"}, false, "Enable debug mode")
    35  	flSocketGroup = flag.String([]string{"G", "-group"}, "docker", "Group to assign the unix socket specified by -H when running in daemon mode\nuse '' (the empty string) to disable setting of a group")
    36  	flLogLevel    = flag.String([]string{"l", "-log-level"}, "info", "Set the logging level")
    37  	flEnableCors  = flag.Bool([]string{"#api-enable-cors", "-api-enable-cors"}, false, "Enable CORS headers in the remote API")
    38  	flTls         = flag.Bool([]string{"-tls"}, false, "Use TLS; implied by --tlsverify flag")
    39  	flTlsVerify   = flag.Bool([]string{"-tlsverify"}, dockerTlsVerify, "Use TLS and verify the remote (daemon: verify client, client: verify daemon)")
    40  
    41  	// these are initialized in init() below since their default values depend on dockerCertPath which isn't fully initialized until init() runs
    42  	flTrustKey *string
    43  	flCa       *string
    44  	flCert     *string
    45  	flKey      *string
    46  	flHosts    []string
    47  )
    48  
    49  func init() {
    50  	// placeholder for trust key flag
    51  	trustKeyDefault := filepath.Join(dockerCertPath, defaultTrustKeyFile)
    52  	flTrustKey = &trustKeyDefault
    53  
    54  	flCa = flag.String([]string{"-tlscacert"}, filepath.Join(dockerCertPath, defaultCaFile), "Trust only remotes providing a certificate signed by the CA given here")
    55  	flCert = flag.String([]string{"-tlscert"}, filepath.Join(dockerCertPath, defaultCertFile), "Path to TLS certificate file")
    56  	flKey = flag.String([]string{"-tlskey"}, filepath.Join(dockerCertPath, defaultKeyFile), "Path to TLS key file")
    57  	opts.HostListVar(&flHosts, []string{"H", "-host"}, "The socket(s) to bind to in daemon mode or connect to in client mode, specified using one or more tcp://host:port, unix:///path/to/socket, fd://* or fd://socketfd.")
    58  
    59  	flag.Usage = func() {
    60  		fmt.Fprint(os.Stderr, "Usage: docker [OPTIONS] COMMAND [arg...]\n\nA self-sufficient runtime for linux containers.\n\nOptions:\n")
    61  
    62  		flag.PrintDefaults()
    63  
    64  		help := "\nCommands:\n"
    65  
    66  		for _, command := range [][]string{
    67  			{"attach", "Attach to a running container"},
    68  			{"build", "Build an image from a Dockerfile"},
    69  			{"commit", "Create a new image from a container's changes"},
    70  			{"cp", "Copy files/folders from a container's filesystem to the host path"},
    71  			{"create", "Create a new container"},
    72  			{"diff", "Inspect changes on a container's filesystem"},
    73  			{"events", "Get real time events from the server"},
    74  			{"exec", "Run a command in a running container"},
    75  			{"export", "Stream the contents of a container as a tar archive"},
    76  			{"history", "Show the history of an image"},
    77  			{"images", "List images"},
    78  			{"import", "Create a new filesystem image from the contents of a tarball"},
    79  			{"info", "Display system-wide information"},
    80  			{"inspect", "Return low-level information on a container"},
    81  			{"kill", "Kill a running container"},
    82  			{"load", "Load an image from a tar archive"},
    83  			{"login", "Register or log in to a Docker registry server"},
    84  			{"logout", "Log out from a Docker registry server"},
    85  			{"logs", "Fetch the logs of a container"},
    86  			{"port", "Lookup the public-facing port that is NAT-ed to PRIVATE_PORT"},
    87  			{"pause", "Pause all processes within a container"},
    88  			{"ps", "List containers"},
    89  			{"pull", "Pull an image or a repository from a Docker registry server"},
    90  			{"push", "Push an image or a repository to a Docker registry server"},
    91  			{"restart", "Restart a running container"},
    92  			{"rm", "Remove one or more containers"},
    93  			{"rmi", "Remove one or more images"},
    94  			{"run", "Run a command in a new container"},
    95  			{"save", "Save an image to a tar archive"},
    96  			{"search", "Search for an image on the Docker Hub"},
    97  			{"start", "Start a stopped container"},
    98  			{"stop", "Stop a running container"},
    99  			{"tag", "Tag an image into a repository"},
   100  			{"top", "Lookup the running processes of a container"},
   101  			{"unpause", "Unpause a paused container"},
   102  			{"version", "Show the Docker version information"},
   103  			{"wait", "Block until a container stops, then print its exit code"},
   104  		} {
   105  			help += fmt.Sprintf("    %-10.10s%s\n", command[0], command[1])
   106  		}
   107  		help += "\nRun 'docker COMMAND --help' for more information on a command."
   108  		fmt.Fprintf(os.Stderr, "%s\n", help)
   109  	}
   110  }