github.com/pritambaral/docker@v1.4.2-0.20150120174542-b2fe1b3dd952/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 (debug, info, warn, error, fatal)")
    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  	flHelp        = flag.Bool([]string{"h", "-help"}, false, "Print usage")
    40  	flTlsVerify   = flag.Bool([]string{"-tlsverify"}, dockerTlsVerify, "Use TLS and verify the remote (daemon: verify client, client: verify daemon)")
    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 init() {
    51  	// placeholder for trust key flag
    52  	trustKeyDefault := filepath.Join(dockerCertPath, defaultTrustKeyFile)
    53  	flTrustKey = &trustKeyDefault
    54  
    55  	flCa = flag.String([]string{"-tlscacert"}, filepath.Join(dockerCertPath, defaultCaFile), "Trust only remotes providing a certificate signed by the CA given here")
    56  	flCert = flag.String([]string{"-tlscert"}, filepath.Join(dockerCertPath, defaultCertFile), "Path to TLS certificate file")
    57  	flKey = flag.String([]string{"-tlskey"}, filepath.Join(dockerCertPath, defaultKeyFile), "Path to TLS key file")
    58  	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.")
    59  
    60  	flag.Usage = func() {
    61  		fmt.Fprint(os.Stdout, "Usage: docker [OPTIONS] COMMAND [arg...]\n\nA self-sufficient runtime for linux containers.\n\nOptions:\n")
    62  
    63  		flag.CommandLine.SetOutput(os.Stdout)
    64  		flag.PrintDefaults()
    65  
    66  		help := "\nCommands:\n"
    67  
    68  		for _, command := range [][]string{
    69  			{"attach", "Attach to a running container"},
    70  			{"build", "Build an image from a Dockerfile"},
    71  			{"commit", "Create a new image from a container's changes"},
    72  			{"cp", "Copy files/folders from a container's filesystem to the host path"},
    73  			{"create", "Create a new container"},
    74  			{"diff", "Inspect changes on a container's filesystem"},
    75  			{"events", "Get real time events from the server"},
    76  			{"exec", "Run a command in a running container"},
    77  			{"export", "Stream the contents of a container as a tar archive"},
    78  			{"history", "Show the history of an image"},
    79  			{"images", "List images"},
    80  			{"import", "Create a new filesystem image from the contents of a tarball"},
    81  			{"info", "Display system-wide information"},
    82  			{"inspect", "Return low-level information on a container"},
    83  			{"kill", "Kill a running container"},
    84  			{"load", "Load an image from a tar archive"},
    85  			{"login", "Register or log in to a Docker registry server"},
    86  			{"logout", "Log out from a Docker registry server"},
    87  			{"logs", "Fetch the logs of a container"},
    88  			{"port", "Lookup the public-facing port that is NAT-ed to PRIVATE_PORT"},
    89  			{"pause", "Pause all processes within a container"},
    90  			{"ps", "List containers"},
    91  			{"pull", "Pull an image or a repository from a Docker registry server"},
    92  			{"push", "Push an image or a repository to a Docker registry server"},
    93  			{"rename", "Rename an existing container"},
    94  			{"restart", "Restart a running container"},
    95  			{"rm", "Remove one or more containers"},
    96  			{"rmi", "Remove one or more images"},
    97  			{"run", "Run a command in a new container"},
    98  			{"save", "Save an image to a tar archive"},
    99  			{"search", "Search for an image on the Docker Hub"},
   100  			{"start", "Start a stopped container"},
   101  			{"stop", "Stop a running container"},
   102  			{"tag", "Tag an image into a repository"},
   103  			{"top", "Lookup the running processes of a container"},
   104  			{"unpause", "Unpause a paused container"},
   105  			{"version", "Show the Docker version information"},
   106  			{"wait", "Block until a container stops, then print its exit code"},
   107  		} {
   108  			help += fmt.Sprintf("    %-10.10s%s\n", command[0], command[1])
   109  		}
   110  		help += "\nRun 'docker COMMAND --help' for more information on a command."
   111  		fmt.Fprintf(os.Stdout, "%s\n", help)
   112  	}
   113  }