| 20 | } |
| 21 | |
| 22 | func NewCmdConfigGet(f *cmdutil.Factory, runF func(*GetOptions) error) *cobra.Command { |
| 23 | opts := &GetOptions{ |
| 24 | IO: f.IOStreams, |
| 25 | } |
| 26 | |
| 27 | cmd := &cobra.Command{ |
| 28 | Use: "get <key>", |
| 29 | Short: "Print the value of a given configuration key", |
| 30 | Example: heredoc.Doc(` |
| 31 | $ gh config get git_protocol |
| 32 | `), |
| 33 | Args: cobra.ExactArgs(1), |
| 34 | RunE: func(cmd *cobra.Command, args []string) error { |
| 35 | config, err := f.Config() |
| 36 | if err != nil { |
| 37 | return err |
| 38 | } |
| 39 | opts.Config = config |
| 40 | opts.Key = args[0] |
| 41 | |
| 42 | if runF != nil { |
| 43 | return runF(opts) |
| 44 | } |
| 45 | |
| 46 | return getRun(opts) |
| 47 | }, |
| 48 | } |
| 49 | |
| 50 | cmd.Flags().StringVarP(&opts.Hostname, "host", "h", "", "Get per-host setting") |
| 51 | |
| 52 | return cmd |
| 53 | } |
| 54 | |
| 55 | func getRun(opts *GetOptions) error { |
| 56 | // search keyring storage when fetching the `oauth_token` value |