(commentable Commentable, opts *CommentableOptions)
| 358 | } |
| 359 | |
| 360 | func deleteComment(commentable Commentable, opts *CommentableOptions) error { |
| 361 | comments := commentable.CurrentUserComments() |
| 362 | if len(comments) == 0 { |
| 363 | return errNoUserComments |
| 364 | } |
| 365 | |
| 366 | lastComment := comments[len(comments)-1] |
| 367 | |
| 368 | cs := opts.IO.ColorScheme() |
| 369 | |
| 370 | if opts.Interactive && !opts.DeleteLastConfirmed { |
| 371 | // This is not an ideal way of truncating a random string that may |
| 372 | // contain emojis or other kind of wide chars. |
| 373 | truncated := lastComment.Body |
| 374 | if len(lastComment.Body) > 40 { |
| 375 | truncated = lastComment.Body[:40] + "..." |
| 376 | } |
| 377 | |
| 378 | fmt.Fprintf(opts.IO.Out, "%s Deleted comments cannot be recovered.\n", cs.WarningIcon()) |
| 379 | ok, err := opts.ConfirmDeleteLastComment(truncated) |
| 380 | if err != nil { |
| 381 | return err |
| 382 | } |
| 383 | if !ok { |
| 384 | return errDeleteNotConfirmed |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | httpClient, err := opts.HttpClient() |
| 389 | if err != nil { |
| 390 | return err |
| 391 | } |
| 392 | |
| 393 | apiClient := api.NewClientFromHTTP(httpClient) |
| 394 | params := api.CommentDeleteInput{CommentId: lastComment.Identifier()} |
| 395 | deletionErr := api.CommentDelete(apiClient, opts.Host, params) |
| 396 | if deletionErr != nil { |
| 397 | return deletionErr |
| 398 | } |
| 399 | |
| 400 | if !opts.Quiet { |
| 401 | fmt.Fprintln(opts.IO.ErrOut, "Comment deleted") |
| 402 | } |
| 403 | |
| 404 | return nil |
| 405 | } |
| 406 | |
| 407 | func CommentableConfirmSubmitSurvey(p Prompt) func() (bool, error) { |
| 408 | return func() (bool, error) { |
no test coverage detected