github.com/hamo/docker@v1.11.1/api/client/logout.go (about)

     1  package client
     2  
     3  import (
     4  	"fmt"
     5  
     6  	Cli "github.com/docker/docker/cli"
     7  	flag "github.com/docker/docker/pkg/mflag"
     8  )
     9  
    10  // CmdLogout logs a user out from a Docker registry.
    11  //
    12  // If no server is specified, the user will be logged out from the registry's index server.
    13  //
    14  // Usage: docker logout [SERVER]
    15  func (cli *DockerCli) CmdLogout(args ...string) error {
    16  	cmd := Cli.Subcmd("logout", []string{"[SERVER]"}, Cli.DockerCommands["logout"].Description+".\nIf no server is specified, the default is defined by the daemon.", true)
    17  	cmd.Require(flag.Max, 1)
    18  
    19  	cmd.ParseFlags(args, true)
    20  
    21  	var serverAddress string
    22  	if len(cmd.Args()) > 0 {
    23  		serverAddress = cmd.Arg(0)
    24  	} else {
    25  		serverAddress = cli.electAuthServer()
    26  	}
    27  
    28  	// check if we're logged in based on the records in the config file
    29  	// which means it couldn't have user/pass cause they may be in the creds store
    30  	if _, ok := cli.configFile.AuthConfigs[serverAddress]; !ok {
    31  		fmt.Fprintf(cli.out, "Not logged in to %s\n", serverAddress)
    32  		return nil
    33  	}
    34  
    35  	fmt.Fprintf(cli.out, "Remove login credentials for %s\n", serverAddress)
    36  	if err := eraseCredentials(cli.configFile, serverAddress); err != nil {
    37  		fmt.Fprintf(cli.out, "WARNING: could not erase credentials: %v\n", err)
    38  	}
    39  
    40  	return nil
    41  }