github.com/squaremo/docker@v1.3.2-0.20150516120342-42cfc9554972/api/client/logout.go (about) 1 package client 2 3 import ( 4 "fmt" 5 6 flag "github.com/docker/docker/pkg/mflag" 7 "github.com/docker/docker/registry" 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", "[SERVER]", "Log out from a Docker registry, if no server is\nspecified \""+registry.IndexServerAddress()+"\" is the default.", true) 17 cmd.Require(flag.Max, 1) 18 19 cmd.ParseFlags(args, false) 20 serverAddress := registry.IndexServerAddress() 21 if len(cmd.Args()) > 0 { 22 serverAddress = cmd.Arg(0) 23 } 24 25 if _, ok := cli.configFile.AuthConfigs[serverAddress]; !ok { 26 fmt.Fprintf(cli.out, "Not logged in to %s\n", serverAddress) 27 } else { 28 fmt.Fprintf(cli.out, "Remove login credentials for %s\n", serverAddress) 29 delete(cli.configFile.AuthConfigs, serverAddress) 30 31 if err := cli.configFile.Save(); err != nil { 32 return fmt.Errorf("Failed to save docker config: %v", err) 33 } 34 } 35 return nil 36 }