Merge pull request #7124 from cli/config-get-token-fix

config get: support getting oauth_token from keyring
This commit is contained in:
Mislav Marohnić 2023-03-09 15:43:31 +00:00 committed by GitHub
commit 71d9e0eb40
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,7 @@
package get
import (
"errors"
"fmt"
"github.com/MakeNowJust/heredoc"
@ -53,6 +54,16 @@ func NewCmdConfigGet(f *cmdutil.Factory, runF func(*GetOptions) error) *cobra.Co
}
func getRun(opts *GetOptions) error {
// search keyring storage when fetching the `oauth_token` value
if opts.Hostname != "" && opts.Key == "oauth_token" {
token, _ := opts.Config.Authentication().Token(opts.Hostname)
if token == "" {
return errors.New(`could not find key "oauth_token"`)
}
fmt.Fprintf(opts.IO.Out, "%s\n", token)
return nil
}
val, err := opts.Config.GetOrDefault(opts.Hostname, opts.Key)
if err != nil {
return err