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

Function NewCmdLogout

pkg/cmd/auth/logout/logout.go:37–100  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*LogoutOptions) error)

Source from the content-addressed store, hash-verified

35}
36
37func NewCmdLogout(f *cmdutil.Factory, runF func(*LogoutOptions) error) *cobra.Command {
38 opts := &LogoutOptions{
39 IO: f.IOStreams,
40 Config: f.Config,
41 GitClient: f.GitClient,
42 Prompter: f.Prompter,
43 OAuthAppHttpClient: f.OAuthAppHttpClient,
44 }
45
46 cmd := &cobra.Command{
47 Use: "logout",
48 Args: cobra.ExactArgs(0),
49 Short: "Log out of a GitHub account",
50 Long: heredoc.Docf(`
51 Remove authentication for a GitHub account.
52
53 By default, this command revokes the selected account's GitHub CLI OAuth
54 token and removes its saved authentication locally. Copies of the same
55 token used elsewhere stop working. Independently issued tokens are not revoked.
56
57 Other token types and unrecognized token formats are removed locally,
58 with a warning that they were not revoked.
59
60 After local logout, saved HTTPS credentials for the host are also removed
61 from Git credential helpers. If cleanup fails, the command prints a warning
62 but still succeeds.
63
64 If revocation fails, including when it cannot be confirmed, local credentials
65 are kept so you can retry. The command exits with an error.
66
67 If a refreshable OAuth token is not found, this command refreshes it once,
68 saves the replacement credentials, and retries revocation.
69 If saving fails, it attempts to revoke the replacement and returns an error
70 requiring you to sign in again.
71
72 Use %[1]s--no-revoke%[1]s for local-only logout, without a network request.
73 This still prints a warning that the token was not revoked.
74 `, "`"),
75 Example: heredoc.Doc(`
76 # Select what host and account to log out of via a prompt
77 $ gh auth logout
78
79 # Log out of a specific host and specific account
80 $ gh auth logout --hostname enterprise.internal --user monalisa
81
82 # Remove local credentials without revoking the token
83 $ gh auth logout --no-revoke
84 `),
85 RunE: func(cmd *cobra.Command, args []string) error {
86 opts.Context = cmd.Context()
87 if runF != nil {
88 return runF(opts)
89 }
90
91 return logoutRun(opts)
92 },
93 }
94

Callers 1

Test_NewCmdLogoutFunction · 0.85

Calls 1

logoutRunFunction · 0.85

Tested by 1

Test_NewCmdLogoutFunction · 0.68