MCPcopy
hub / github.com/cli/cli / deleteRun

Function deleteRun

pkg/cmd/gpg-key/delete/delete.go:57–103  ·  view source on GitHub ↗
(opts *DeleteOptions)

Source from the content-addressed store, hash-verified

55}
56
57func deleteRun(opts *DeleteOptions) error {
58 httpClient, err := opts.HttpClient()
59 if err != nil {
60 return err
61 }
62
63 cfg, err := opts.Config()
64 if err != nil {
65 return err
66 }
67
68 host, _ := cfg.Authentication().DefaultHost()
69 gpgKeys, err := getGPGKeys(httpClient, host)
70 if err != nil {
71 return err
72 }
73
74 id := ""
75 for _, gpgKey := range gpgKeys {
76 if gpgKey.KeyID == opts.KeyID {
77 id = strconv.FormatInt(gpgKey.ID, 10)
78 break
79 }
80 }
81
82 if id == "" {
83 return fmt.Errorf("unable to delete GPG key %s: either the GPG key is not found or it is not owned by you", opts.KeyID)
84 }
85
86 if !opts.Confirmed {
87 if err := opts.Prompter.ConfirmDeletion(opts.KeyID); err != nil {
88 return err
89 }
90 }
91
92 err = deleteGPGKey(httpClient, host, id)
93 if err != nil {
94 return err
95 }
96
97 if opts.IO.IsStdoutTTY() {
98 cs := opts.IO.ColorScheme()
99 fmt.Fprintf(opts.IO.Out, "%s GPG key %s deleted from your account\n", cs.SuccessIcon(), opts.KeyID)
100 }
101
102 return nil
103}

Callers 2

NewCmdDeleteFunction · 0.70
Test_deleteRunFunction · 0.70

Calls 10

getGPGKeysFunction · 0.85
deleteGPGKeyFunction · 0.85
IsStdoutTTYMethod · 0.80
ColorSchemeMethod · 0.80
SuccessIconMethod · 0.80
ConfigMethod · 0.65
DefaultHostMethod · 0.65
AuthenticationMethod · 0.65
ErrorfMethod · 0.65
ConfirmDeletionMethod · 0.65

Tested by 1

Test_deleteRunFunction · 0.56