diff --git a/commands.go b/commands.go index 8c2875370f..3a1bf7f1d5 100644 --- a/commands.go +++ b/commands.go @@ -405,20 +405,21 @@ func (srv *Server) CmdPush(stdin io.ReadCloser, stdout io.Writer, args ...string if err := cmd.Parse(args); err != nil { return nil } - if cmd.NArg() == 0 { + if cmd.NArg() == 0 || *user == "" { cmd.Usage() return nil } + if srv.runtime.authConfig == nil { + return fmt.Errorf("Please login prior to push. ('docker login')") + } + // Try to get the image // FIXME: Handle lookup // FIXME: Also push the tags in case of ./docker push myrepo:mytag // img, err := srv.runtime.LookupImage(cmd.Arg(0)) img, err := srv.runtime.graph.Get(cmd.Arg(0)) if err != nil { - if *user == "" { - return fmt.Errorf("Not logged in and no user specified\n") - } // If it fails, try to get the repository if repo, exists := srv.runtime.repositories.Repositories[cmd.Arg(0)]; exists { fmt.Fprintf(stdout, "Pushing %s (%d images) on %s...\n", cmd.Arg(0), len(repo), *user+"/"+cmd.Arg(0)) @@ -447,11 +448,15 @@ func (srv *Server) CmdPull(stdin io.ReadCloser, stdout io.Writer, args ...string if err := cmd.Parse(args); err != nil { return nil } - if cmd.NArg() == 0 { + if cmd.NArg() == 0 || *user == "" { cmd.Usage() return nil } + if srv.runtime.authConfig == nil { + return fmt.Errorf("Please login prior to push. ('docker login')") + } + if srv.runtime.graph.LookupRemoteImage(cmd.Arg(0), srv.runtime.authConfig) { fmt.Fprintf(stdout, "Pulling %s...\n", cmd.Arg(0)) if err := srv.runtime.graph.PullImage(cmd.Arg(0), srv.runtime.authConfig); err != nil { @@ -460,9 +465,6 @@ func (srv *Server) CmdPull(stdin io.ReadCloser, stdout io.Writer, args ...string fmt.Fprintf(stdout, "Pulled\n") return nil } - if *user == "" { - return fmt.Errorf("Not loggin and no user specified\n") - } // FIXME: Allow pull repo:tag fmt.Fprintf(stdout, "Pulling %s from %s...\n", cmd.Arg(0), *user+"/"+cmd.Arg(0)) if err := srv.runtime.graph.PullRepository(*user, cmd.Arg(0), "", srv.runtime.repositories, srv.runtime.authConfig); err != nil {