@@ -19,40 +19,34 @@ type RefreshOptions struct {
1919
2020 Hostname string
2121 Scopes []string
22+ AuthFlow func (config.Config , string , []string ) error
2223}
2324
2425func NewCmdRefresh (f * cmdutil.Factory , runF func (* RefreshOptions ) error ) * cobra.Command {
2526 opts := & RefreshOptions {
2627 IO : f .IOStreams ,
2728 Config : f .Config ,
29+ AuthFlow : func (cfg config.Config , hostname string , scopes []string ) error {
30+ _ , err := config .AuthFlowWithConfig (cfg , hostname , "" , scopes )
31+ return err
32+ },
2833 }
2934
3035 cmd := & cobra.Command {
3136 Use : "refresh" ,
3237 Args : cobra .ExactArgs (0 ),
33- Short : "Request new scopes for a token" ,
34- Long : heredoc .Doc (`Expand the permission scopes for a given host's token.
35-
36- This command allows you to add additional scopes to an existing authentication token via a web
37- browser. This enables gh to access more of the GitHub API, which may be required as gh adds
38- features or as you use the gh api command.
39-
40- Unfortunately at this time there is no way to add scopes without a web browser's involvement
41- due to how GitHub authentication works.
42-
43- The --hostname flag allows you to operate on a GitHub host other than github.com.
38+ Short : "Refresh stored authentication credentials" ,
39+ Long : heredoc .Doc (`Expand or fix the permission scopes for stored credentials
4440
45- The --scopes flag accepts a comma separated list of scopes you want to add to a token. If
46- absent, this command ensures that a host's token has the default set of scopes required by gh.
47-
48- Note that if GITHUB_TOKEN is in the current environment, this command will not work.
41+ The --scopes flag accepts a comma separated list of scopes you want your gh credentials to have. If
42+ absent, this command ensures that gh has access to a minimum set of scopes.
4943 ` ),
5044 Example : heredoc .Doc (`
5145 $ gh auth refresh --scopes write:org,read:public_key
5246 # => open a browser to add write:org and read:public_key scopes for use with gh api
5347
5448 $ gh auth refresh
55- # => ensure that the required minimum scopes are enabled for a token and open a browser to add if not
49+ # => open a browser to ensure your authentication credentials have the correct minimum scopes
5650 ` ),
5751 RunE : func (cmd * cobra.Command , args []string ) error {
5852 if runF != nil {
@@ -64,7 +58,7 @@ func NewCmdRefresh(f *cmdutil.Factory, runF func(*RefreshOptions) error) *cobra.
6458 }
6559
6660 cmd .Flags ().StringVarP (& opts .Hostname , "hostname" , "h" , "" , "The GitHub host to use for authentication" )
67- cmd .Flags ().StringSliceVarP (& opts .Scopes , "scopes" , "s" , [] string {} , "Additional scopes to add to a token " )
61+ cmd .Flags ().StringSliceVarP (& opts .Scopes , "scopes" , "s" , nil , "Additional authentication scopes for gh to have " )
6862
6963 return cmd
7064}
@@ -118,10 +112,5 @@ func refreshRun(opts *RefreshOptions) error {
118112 }
119113 }
120114
121- return doAuthFlow (cfg , hostname , opts .Scopes )
122- }
123-
124- var doAuthFlow = func (cfg config.Config , hostname string , scopes []string ) error {
125- _ , err := config .AuthFlowWithConfig (cfg , hostname , "" , scopes )
126- return err
115+ return opts .AuthFlow (cfg , hostname , opts .Scopes )
127116}
0 commit comments