MCPcopy
hub / github.com/cli/cli / getRun

Function getRun

pkg/cmd/config/get/get.go:55–76  ·  view source on GitHub ↗
(opts *GetOptions)

Source from the content-addressed store, hash-verified

53}
54
55func getRun(opts *GetOptions) error {
56 // search keyring storage when fetching the `oauth_token` value
57 if opts.Hostname != "" && opts.Key == "oauth_token" {
58 token, _ := opts.Config.Authentication().ActiveToken(opts.Hostname)
59 if token == "" {
60 return errors.New(`could not find key "oauth_token"`)
61 }
62 fmt.Fprintf(opts.IO.Out, "%s\n", token)
63 return nil
64 }
65
66 optionalEntry := opts.Config.GetOrDefault(opts.Hostname, opts.Key)
67 if optionalEntry.IsNone() {
68 return nonExistentKeyError{key: opts.Key}
69 }
70
71 val := optionalEntry.Unwrap().Value
72 if val != "" {
73 fmt.Fprintf(opts.IO.Out, "%s\n", val)
74 }
75 return nil
76}
77
78type nonExistentKeyError struct {
79 key string

Callers 2

Test_getRunFunction · 0.70
NewCmdConfigGetFunction · 0.70

Calls 5

IsNoneMethod · 0.80
ActiveTokenMethod · 0.65
AuthenticationMethod · 0.65
GetOrDefaultMethod · 0.65
UnwrapMethod · 0.45

Tested by 1

Test_getRunFunction · 0.56