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

Function Login

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

Source from the content-addressed store, hash-verified

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

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