(cmd *cobra.Command, args []string)
| 56 | } |
| 57 | |
| 58 | func (c *boxCommand) run(cmd *cobra.Command, args []string) error { |
| 59 | if err := requireAuth(); err != nil { |
| 60 | return err |
| 61 | } |
| 62 | |
| 63 | ctx := cmd.Context() |
| 64 | resp, err := resolveBox(ctx, args[0]) |
| 65 | if err != nil { |
| 66 | return err |
| 67 | } |
| 68 | |
| 69 | postings, finalNextURL, err := paginateBoxPostings(ctx, resp, c.limit, c.all, fetchNextBoxPage) |
| 70 | if err != nil { |
| 71 | return err |
| 72 | } |
| 73 | hasMore := finalNextURL != "" |
| 74 | |
| 75 | total := len(postings) |
| 76 | if c.limit > 0 && !c.all && len(postings) > c.limit { |
| 77 | postings = postings[:c.limit] |
| 78 | // Clear next_history_url when client-side truncation drops postings, |
| 79 | // so JSON consumers don't skip the truncated items. |
| 80 | resp.NextHistoryUrl = "" |
| 81 | } else { |
| 82 | resp.NextHistoryUrl = finalNextURL |
| 83 | } |
| 84 | notice := boxTruncationNotice(len(postings), total, hasMore, c.all) |
| 85 | |
| 86 | if writer.IsStyled() { |
| 87 | fmt.Fprintf(cmd.OutOrStdout(), "Box: %s (%s)\n\n", resp.Name, resp.Kind) |
| 88 | |
| 89 | table := newTable(cmd.OutOrStdout()) |
| 90 | table.addRow([]string{"Thread", "From", "Summary", "Date"}) |
| 91 | for _, p := range postings { |
| 92 | displayID := resolvePostingTopicID(p) |
| 93 | table.addRow([]string{fmt.Sprintf("%d", displayID), p.Creator.Name, truncate(p.Summary, 60), formatDate(p.CreatedAt)}) |
| 94 | } |
| 95 | table.print() |
| 96 | if notice != "" { |
| 97 | fmt.Fprintln(cmd.OutOrStdout(), notice) |
| 98 | } |
| 99 | return nil |
| 100 | } |
| 101 | |
| 102 | resp.Postings = postings |
| 103 | return writeOK(resp, |
| 104 | output.WithSummary(fmt.Sprintf("%d postings in %s", len(postings), resp.Name)), |
| 105 | output.WithNotice(notice), |
| 106 | output.WithBreadcrumbs( |
| 107 | output.Breadcrumb{ |
| 108 | Action: "read", |
| 109 | Command: "hey threads <id>", |
| 110 | Description: "Read an email thread", |
| 111 | }, |
| 112 | output.Breadcrumb{ |
| 113 | Action: "compose", |
| 114 | Command: "hey compose --to <email> --subject <subject>", |
| 115 | Description: "Compose a new message", |
nothing calls this directly
no test coverage detected