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

Function Login

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

Source from the content-addressed store, hash-verified

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

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