| 70 | } |
| 71 | |
| 72 | func deleteRun(opts *deleteOptions) error { |
| 73 | repo, err := opts.BaseRepo() |
| 74 | if err != nil { |
| 75 | return err |
| 76 | } |
| 77 | |
| 78 | out := opts.IO.Out |
| 79 | cs := opts.IO.ColorScheme() |
| 80 | |
| 81 | autolink, err := opts.AutolinkViewClient.View(repo, opts.ID) |
| 82 | |
| 83 | if err != nil { |
| 84 | return fmt.Errorf("%s %w", cs.Red("error deleting autolink:"), err) |
| 85 | } |
| 86 | |
| 87 | if opts.IO.CanPrompt() && !opts.Confirmed { |
| 88 | fmt.Fprintf(out, "Autolink %s has key prefix %s.\n", cs.Cyan(opts.ID), autolink.KeyPrefix) |
| 89 | |
| 90 | err := opts.Prompter.ConfirmDeletion(autolink.KeyPrefix) |
| 91 | |
| 92 | if err != nil { |
| 93 | return err |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | err = opts.AutolinkDeleteClient.Delete(repo, opts.ID) |
| 98 | if err != nil { |
| 99 | return err |
| 100 | } |
| 101 | |
| 102 | if opts.IO.IsStdoutTTY() { |
| 103 | fmt.Fprintf(out, "%s Autolink %s deleted from %s\n", cs.SuccessIcon(), cs.Cyan(opts.ID), cs.Bold(ghrepo.FullName(repo))) |
| 104 | } |
| 105 | |
| 106 | return nil |
| 107 | } |