MCPcopy Index your code
hub / github.com/docker/cli / newLoginCommand

Function newLoginCommand

cli/command/registry/login.go:38–69  ·  view source on GitHub ↗

newLoginCommand creates a new `docker login` command

(dockerCLI command.Cli)

Source from the content-addressed store, hash-verified

36
37// newLoginCommand creates a new `docker login` command
38func newLoginCommand(dockerCLI command.Cli) *cobra.Command {
39 var opts loginOptions
40
41 cmd := &cobra.Command{
42 Use: "login [OPTIONS] [SERVER]",
43 Short: "Authenticate to a registry",
44 Long: "Authenticate to a registry.\nDefaults to Docker Hub if no server is specified.",
45 Args: cli.RequiresMaxArgs(1),
46 RunE: func(cmd *cobra.Command, args []string) error {
47 if len(args) > 0 {
48 opts.serverAddress = args[0]
49 }
50 if err := verifyLoginFlags(cmd.Flags(), opts); err != nil {
51 return err
52 }
53 return runLogin(cmd.Context(), dockerCLI, opts)
54 },
55 Annotations: map[string]string{
56 "category-top": "8",
57 },
58 ValidArgsFunction: cobra.NoFileCompletions,
59 DisableFlagsInUseLine: true,
60 }
61
62 flags := cmd.Flags()
63
64 flags.StringVarP(&opts.user, "username", "u", "", "Username")
65 flags.StringVarP(&opts.password, "password", "p", "", `Password or Personal Access Token (PAT), or "-" to read from stdin`)
66 flags.BoolVar(&opts.passwordStdin, "password-stdin", false, "Take the Password or Personal Access Token (PAT) from stdin")
67
68 return cmd
69}
70
71// verifyLoginFlags validates flags set on the command.
72//

Callers 2

TestLoginValidateFlagsFunction · 0.85

Calls 2

verifyLoginFlagsFunction · 0.85
runLoginFunction · 0.85

Tested by 2

TestLoginValidateFlagsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…