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

Function NewCmdLogin

pkg/cmd/auth/login/login.go:57–198  ·  view source on GitHub ↗
(f *cmdutil.Factory, telemetry ghtelemetry.InvocationRecorder, runF func(*LoginOptions) error)

Source from the content-addressed store, hash-verified

55}
56
57func NewCmdLogin(f *cmdutil.Factory, telemetry ghtelemetry.InvocationRecorder, runF func(*LoginOptions) error) *cobra.Command {
58 opts := &LoginOptions{
59 IO: f.IOStreams,
60 Config: f.Config,
61 HttpClient: f.HttpClient,
62 PlainHttpClient: f.PlainHttpClient,
63 GitClient: f.GitClient,
64 Prompter: f.Prompter,
65 Browser: f.Browser,
66 Telemetry: telemetry,
67 }
68
69 var tokenStdin bool
70
71 cmd := &cobra.Command{
72 Use: "login",
73 Args: cobra.ExactArgs(0),
74 Short: "Log in to a GitHub account",
75 Long: heredoc.Docf(`
76 Authenticate with a GitHub host.
77
78 The default hostname is %[1]sgithub.com%[1]s. This can be overridden using the %[1]s--hostname%[1]s
79 flag.
80
81 The default authentication mode is a web-based browser flow. After completion, an
82 authentication token will be stored securely in the system credential store.
83 If a credential store is not found or there is an issue using it gh will fallback
84 to writing the token to a plain text file. See %[1]sgh auth status%[1]s for its
85 stored location.
86
87 Alternatively, use %[1]s--with-token%[1]s to pass in a personal access token (classic) on standard input.
88 The minimum required scopes for the token are: %[1]srepo%[1]s, %[1]sread:org%[1]s, and %[1]sgist%[1]s.
89 Take care when passing a fine-grained personal access token to %[1]s--with-token%[1]s
90 as the inherent scoping to certain resources may cause confusing behaviour when interacting with other
91 resources. Favour setting %[1]sGH_TOKEN%[1]s for fine-grained personal access token usage.
92
93 Alternatively, gh will use the authentication token found in environment variables.
94 This method is most suitable for "headless" use of gh such as in automation. See
95 %[1]sgh help environment%[1]s for more info.
96
97 To use gh in GitHub Actions, add %[1]sGH_TOKEN: ${{ github.token }}%[1]s to %[1]senv%[1]s.
98
99 The git protocol to use for git operations on this host can be set with %[1]s--git-protocol%[1]s,
100 or during the interactive prompting. Although login is for a single account on a host, setting
101 the git protocol will take effect for all users on the host.
102
103 Specifying %[1]sssh%[1]s for the git protocol will detect existing SSH keys to upload,
104 prompting to create and upload a new key if one is not found. This can be skipped with
105 %[1]s--skip-ssh-key%[1]s flag.
106
107 Use %[1]s--expiring%[1]s to prefer expiring credentials that gh refreshes automatically.
108 This is a preference, not a guarantee: whether expiring tokens are issued depends on the
109 host and the OAuth app configuration. A host without support issues a non-expiring token
110 instead, and a host configured for them may issue expiring tokens even without the flag.
111 Enable the %[1]sexpiring_credentials%[1]s configuration to prefer expiring credentials
112 without passing %[1]s--expiring%[1]s every time, and pass %[1]s--expiring=false%[1]s to request a
113 non-expiring token even when that configuration is enabled.
114 When using expiring credentials for git operations, git 2.46 or newer is recommended so

Callers 1

Test_NewCmdLoginFunction · 0.85

Calls 11

FlagErrorfFunction · 0.92
HostnameValidatorFunction · 0.92
NilBoolFlagFunction · 0.92
StringEnumFlagFunction · 0.92
loginRunFunction · 0.85
CanPromptMethod · 0.80
ChangedMethod · 0.80
SetSampleRateMethod · 0.65
CloseMethod · 0.65
ErrorfMethod · 0.65
DefaultHostMethod · 0.65

Tested by 1

Test_NewCmdLoginFunction · 0.68