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

Function NewCmdRefresh

pkg/cmd/auth/refresh/refresh.go:44–126  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*RefreshOptions) error)

Source from the content-addressed store, hash-verified

42}
43
44func NewCmdRefresh(f *cmdutil.Factory, runF func(*RefreshOptions) error) *cobra.Command {
45 opts := &RefreshOptions{
46 IO: f.IOStreams,
47 Config: f.Config,
48 AuthFlow: func(httpClient *http.Client, io *iostreams.IOStreams, hostname string, scopes []string, interactive bool, clipboard bool) (token, username, error) {
49 t, u, err := authflow.AuthFlow(httpClient, hostname, io, "", scopes, interactive, f.Browser, clipboard)
50 return token(t), username(u), err
51 },
52 PlainHttpClient: f.PlainHttpClient,
53 GitClient: f.GitClient,
54 Prompter: f.Prompter,
55 }
56
57 cmd := &cobra.Command{
58 Use: "refresh",
59 Args: cobra.ExactArgs(0),
60 Short: "Refresh stored authentication credentials",
61 Long: heredoc.Docf(`
62 Expand or fix the permission scopes for stored credentials for active account.
63
64 The %[1]s--scopes%[1]s flag accepts a comma separated list of scopes you want
65 your gh credentials to have. If no scopes are provided, the command
66 maintains previously added scopes.
67
68 The %[1]s--remove-scopes%[1]s flag accepts a comma separated list of scopes you
69 want to remove from your gh credentials. Scope removal is idempotent.
70 The minimum set of scopes (%[1]srepo%[1]s, %[1]sread:org%[1]s, and %[1]sgist%[1]s) cannot be removed.
71
72 The %[1]s--reset-scopes%[1]s flag resets the scopes for your gh credentials to
73 the default set of scopes for your auth flow.
74
75 If you have multiple accounts in %[1]sgh auth status%[1]s and want to refresh the credentials for an
76 inactive account, you will have to use %[1]sgh auth switch%[1]s to that account first before using
77 this command, and then switch back when you are done.
78
79 For more information on OAuth scopes, see
80 <https://docs.github.com/en/developers/apps/building-oauth-apps/scopes-for-oauth-apps/>.
81 `, "`"),
82 Example: heredoc.Doc(`
83 # Open a browser to add write:org and read:public_key scopes
84 $ gh auth refresh --scopes write:org,read:public_key
85
86 # Open a browser to ensure your authentication credentials have the correct minimum scopes
87 $ gh auth refresh
88
89 # Open a browser to idempotently remove the delete_repo scope
90 $ gh auth refresh --remove-scopes delete_repo
91
92 # Open a browser to re-authenticate with the default minimum scopes
93 $ gh auth refresh --reset-scopes
94
95 # Open a browser to re-authenticate and copy one-time OAuth code to clipboard
96 $ gh auth refresh --clipboard
97 `),
98 RunE: func(cmd *cobra.Command, args []string) error {
99 opts.Interactive = opts.IO.CanPrompt()
100
101 if !opts.Interactive && opts.Hostname == "" {

Callers 1

Test_NewCmdRefreshFunction · 0.85

Calls 6

AuthFlowFunction · 0.92
FlagErrorfFunction · 0.92
tokenTypeAlias · 0.85
usernameTypeAlias · 0.85
refreshRunFunction · 0.85
CanPromptMethod · 0.80

Tested by 1

Test_NewCmdRefreshFunction · 0.68