MCPcopy Create free account
hub / github.com/cli/cli / Login

Function Login

pkg/cmd/auth/shared/login_flow.go:55–238  ·  view source on GitHub ↗
(opts *LoginOptions)

Source from the content-addressed store, hash-verified

53}
54
55func Login(opts *LoginOptions) error {
56 cfg := opts.Config
57 hostname := opts.Hostname
58 httpClient := opts.HTTPClient
59 cs := opts.IO.ColorScheme()
60
61 gitProtocol := strings.ToLower(opts.GitProtocol)
62 if opts.Interactive && gitProtocol == "" {
63 options := []string{
64 "HTTPS",
65 "SSH",
66 }
67 result, err := opts.Prompter.Select(
68 "What is your preferred protocol for Git operations on this host?",
69 options[0],
70 options)
71 if err != nil {
72 return err
73 }
74 proto := options[result]
75 gitProtocol = strings.ToLower(proto)
76 }
77
78 var additionalScopes []string
79
80 if opts.Interactive && gitProtocol == "https" {
81 if err := opts.CredentialFlow.Prompt(hostname); err != nil {
82 return err
83 }
84 additionalScopes = append(additionalScopes, opts.CredentialFlow.Scopes()...)
85 }
86
87 var keyToUpload string
88 keyTitle := defaultSSHKeyTitle
89 if opts.Interactive && !opts.SkipSSHKeyPrompt && gitProtocol == "ssh" {
90 pubKeys, err := opts.sshContext.LocalPublicKeys()
91 if err != nil {
92 return err
93 }
94
95 if len(pubKeys) > 0 {
96 options := append(pubKeys, "Skip")
97 keyChoice, err := opts.Prompter.Select(
98 "Upload your SSH public key to your GitHub account?",
99 options[0],
100 options)
101 if err != nil {
102 return err
103 }
104 if keyChoice < len(pubKeys) {
105 keyToUpload = pubKeys[keyChoice]
106 }
107 } else if opts.sshContext.HasKeygen() {
108 sshChoice, err := opts.Prompter.Confirm("Generate a new SSH key to add to your GitHub account?", true)
109 if err != nil {
110 return err
111 }
112

Callers 3

loginRunFunction · 0.92
TestLoginFunction · 0.85

Calls 15

AuthFlowFunction · 0.92
scopesSentenceFunction · 0.85
HasMinimumScopesFunction · 0.85
GetCurrentLoginFunction · 0.85
sshKeyUploadFunction · 0.85
ColorSchemeMethod · 0.80
ScopesMethod · 0.80
LocalPublicKeysMethod · 0.80
HasKeygenMethod · 0.80
GenerateSSHKeyMethod · 0.80
SuccessIconMethod · 0.80
ContainsMethod · 0.80

Tested by 2

TestLoginFunction · 0.68