| 53 | } |
| 54 | |
| 55 | func 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 | |
| 78 | type nonExistentKeyError struct { |
| 79 | key string |