(commentable Commentable, opts *CommentableOptions)
| 259 | } |
| 260 | |
| 261 | func deleteComment(commentable Commentable, opts *CommentableOptions) error { |
| 262 | comments := commentable.CurrentUserComments() |
| 263 | if len(comments) == 0 { |
| 264 | return errNoUserComments |
| 265 | } |
| 266 | |
| 267 | lastComment := comments[len(comments)-1] |
| 268 | |
| 269 | cs := opts.IO.ColorScheme() |
| 270 | |
| 271 | if opts.Interactive && !opts.DeleteLastConfirmed { |
| 272 | // This is not an ideal way of truncating a random string that may |
| 273 | // contain emojis or other kind of wide chars. |
| 274 | truncated := lastComment.Body |
| 275 | if len(lastComment.Body) > 40 { |
| 276 | truncated = lastComment.Body[:40] + "..." |
| 277 | } |
| 278 | |
| 279 | fmt.Fprintf(opts.IO.Out, "%s Deleted comments cannot be recovered.\n", cs.WarningIcon()) |
| 280 | ok, err := opts.ConfirmDeleteLastComment(truncated) |
| 281 | if err != nil { |
| 282 | return err |
| 283 | } |
| 284 | if !ok { |
| 285 | return errDeleteNotConfirmed |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | httpClient, err := opts.HttpClient() |
| 290 | if err != nil { |
| 291 | return err |
| 292 | } |
| 293 | |
| 294 | apiClient := api.NewClientFromHTTP(httpClient) |
| 295 | params := api.CommentDeleteInput{CommentId: lastComment.Identifier()} |
| 296 | deletionErr := api.CommentDelete(apiClient, opts.Host, params) |
| 297 | if deletionErr != nil { |
| 298 | return deletionErr |
| 299 | } |
| 300 | |
| 301 | if !opts.Quiet { |
| 302 | fmt.Fprintln(opts.IO.ErrOut, "Comment deleted") |
| 303 | } |
| 304 | |
| 305 | return nil |
| 306 | } |
| 307 | |
| 308 | func CommentableConfirmSubmitSurvey(p Prompt) func() (bool, error) { |
| 309 | return func() (bool, error) { |
no test coverage detected