(f *cmdutil.Factory, runF func(*AddOptions) error)
| 24 | } |
| 25 | |
| 26 | func NewCmdAdd(f *cmdutil.Factory, runF func(*AddOptions) error) *cobra.Command { |
| 27 | opts := &AddOptions{ |
| 28 | HTTPClient: f.HttpClient, |
| 29 | Config: f.Config, |
| 30 | IO: f.IOStreams, |
| 31 | } |
| 32 | |
| 33 | cmd := &cobra.Command{ |
| 34 | Use: "add [<key-file>]", |
| 35 | Short: "Add an SSH key to your GitHub account", |
| 36 | Args: cobra.MaximumNArgs(1), |
| 37 | RunE: func(cmd *cobra.Command, args []string) error { |
| 38 | if len(args) == 0 { |
| 39 | if opts.IO.IsStdoutTTY() && opts.IO.IsStdinTTY() { |
| 40 | return cmdutil.FlagErrorf("public key file missing") |
| 41 | } |
| 42 | opts.KeyFile = "-" |
| 43 | } else { |
| 44 | opts.KeyFile = args[0] |
| 45 | } |
| 46 | |
| 47 | if runF != nil { |
| 48 | return runF(opts) |
| 49 | } |
| 50 | return runAdd(opts) |
| 51 | }, |
| 52 | } |
| 53 | |
| 54 | typeEnums := []string{shared.AuthenticationKey, shared.SigningKey} |
| 55 | cmdutil.StringEnumFlag(cmd, &opts.Type, "type", "", shared.AuthenticationKey, typeEnums, "Type of the ssh key") |
| 56 | cmd.Flags().StringVarP(&opts.Title, "title", "t", "", "Title for the new key") |
| 57 | return cmd |
| 58 | } |
| 59 | |
| 60 | func runAdd(opts *AddOptions) error { |
| 61 | httpClient, err := opts.HTTPClient() |
nothing calls this directly
no test coverage detected