MCPcopy Create free account
hub / github.com/basecamp/hey-cli / run

Method run

internal/cmd/drafts.go:39–82  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

37}
38
39func (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}

Callers

nothing calls this directly

Calls 12

TruncationNoticeFunction · 0.92
WithSummaryFunction · 0.92
WithNoticeFunction · 0.92
requireAuthFunction · 0.85
convertSDKErrorFunction · 0.85
newTableFunction · 0.85
truncateFunction · 0.85
formatDateFunction · 0.85
writeOKFunction · 0.85
IsStyledMethod · 0.80
addRowMethod · 0.80
printMethod · 0.80

Tested by

no test coverage detected