(cmd *cobra.Command, args []string)
| 37 | } |
| 38 | |
| 39 | func (c *draftsCommand) run(cmd *cobra.Command, args []string) error { |
| 40 | if err := requireAuth(); err != nil { |
| 41 | return err |
| 42 | } |
| 43 | |
| 44 | ctx := cmd.Context() |
| 45 | result, err := sdk.Entries().ListDrafts(ctx, nil) |
| 46 | if err != nil { |
| 47 | return convertSDKError(err) |
| 48 | } |
| 49 | |
| 50 | var drafts []generated.DraftMessage |
| 51 | if result != nil { |
| 52 | drafts = *result |
| 53 | } |
| 54 | total := len(drafts) |
| 55 | if c.limit > 0 && !c.all && len(drafts) > c.limit { |
| 56 | drafts = drafts[:c.limit] |
| 57 | } |
| 58 | notice := output.TruncationNotice(len(drafts), total) |
| 59 | |
| 60 | if writer.IsStyled() { |
| 61 | if len(drafts) == 0 { |
| 62 | fmt.Fprintln(cmd.OutOrStdout(), "No drafts.") |
| 63 | return nil |
| 64 | } |
| 65 | |
| 66 | table := newTable(cmd.OutOrStdout()) |
| 67 | table.addRow([]string{"ID", "Summary", "Subject", "Date"}) |
| 68 | for _, d := range drafts { |
| 69 | table.addRow([]string{fmt.Sprintf("%d", d.Id), truncate(d.Summary, 60), d.Subject, formatDate(d.UpdatedAt)}) |
| 70 | } |
| 71 | table.print() |
| 72 | if notice != "" { |
| 73 | fmt.Fprintln(cmd.OutOrStdout(), notice) |
| 74 | } |
| 75 | return nil |
| 76 | } |
| 77 | |
| 78 | return writeOK(drafts, |
| 79 | output.WithSummary(fmt.Sprintf("%d drafts", len(drafts))), |
| 80 | output.WithNotice(notice), |
| 81 | ) |
| 82 | } |
nothing calls this directly
no test coverage detected