MCPcopy Index your code
hub / github.com/cli/cli / runAdd

Function runAdd

pkg/cmd/ssh-key/add/add.go:60–107  ·  view source on GitHub ↗
(opts *AddOptions)

Source from the content-addressed store, hash-verified

58}
59
60func runAdd(opts *AddOptions) error {
61 httpClient, err := opts.HTTPClient()
62 if err != nil {
63 return err
64 }
65
66 var keyReader io.Reader
67 if opts.KeyFile == "-" {
68 keyReader = opts.IO.In
69 defer opts.IO.In.Close()
70 } else {
71 f, err := os.Open(opts.KeyFile)
72 if err != nil {
73 return err
74 }
75 defer f.Close()
76 keyReader = f
77 }
78
79 cfg, err := opts.Config()
80 if err != nil {
81 return err
82 }
83
84 hostname, _ := cfg.Authentication().DefaultHost()
85
86 var uploaded bool
87
88 if opts.Type == shared.SigningKey {
89 uploaded, err = SSHSigningKeyUpload(httpClient, hostname, keyReader, opts.Title)
90 } else {
91 uploaded, err = SSHKeyUpload(httpClient, hostname, keyReader, opts.Title)
92 }
93
94 if err != nil {
95 return err
96 }
97
98 cs := opts.IO.ColorScheme()
99
100 if uploaded {
101 fmt.Fprintf(opts.IO.ErrOut, "%s Public key added to your account\n", cs.SuccessIcon())
102 } else {
103 fmt.Fprintf(opts.IO.ErrOut, "%s Public key already exists on your account\n", cs.SuccessIcon())
104 }
105
106 return nil
107}

Callers 2

Test_runAddFunction · 0.70
NewCmdAddFunction · 0.70

Calls 9

SSHSigningKeyUploadFunction · 0.85
SSHKeyUploadFunction · 0.85
OpenMethod · 0.80
ColorSchemeMethod · 0.80
SuccessIconMethod · 0.80
CloseMethod · 0.65
ConfigMethod · 0.65
DefaultHostMethod · 0.65
AuthenticationMethod · 0.65

Tested by 1

Test_runAddFunction · 0.56