(cmd *cobra.Command, args []string)
| 58 | } |
| 59 | |
| 60 | func (c *journalListCommand) run(cmd *cobra.Command, args []string) error { |
| 61 | if err := requireAuth(); err != nil { |
| 62 | return err |
| 63 | } |
| 64 | |
| 65 | ctx := cmd.Context() |
| 66 | resp, err := listPersonalRecordings(ctx) |
| 67 | if err != nil { |
| 68 | return err |
| 69 | } |
| 70 | |
| 71 | entries := filterRecordingsByType(resp, "Calendar::JournalEntry") |
| 72 | |
| 73 | total := len(entries) |
| 74 | if c.limit > 0 && !c.all && len(entries) > c.limit { |
| 75 | entries = entries[:c.limit] |
| 76 | } |
| 77 | notice := output.TruncationNotice(len(entries), total) |
| 78 | |
| 79 | if writer.IsStyled() { |
| 80 | if len(entries) == 0 { |
| 81 | fmt.Fprintln(cmd.OutOrStdout(), "No journal entries.") |
| 82 | return nil |
| 83 | } |
| 84 | |
| 85 | table := newTable(cmd.OutOrStdout()) |
| 86 | table.addRow([]string{"ID", "Date", "Preview"}) |
| 87 | for _, e := range entries { |
| 88 | table.addRow([]string{fmt.Sprintf("%d", e.Id), formatDate(e.StartsAt), truncate(e.Content, 60)}) |
| 89 | } |
| 90 | table.print() |
| 91 | if notice != "" { |
| 92 | fmt.Fprintln(cmd.OutOrStdout(), notice) |
| 93 | } |
| 94 | return nil |
| 95 | } |
| 96 | |
| 97 | return writeOK(entries, |
| 98 | output.WithSummary(fmt.Sprintf("%d journal entries", len(entries))), |
| 99 | output.WithNotice(notice), |
| 100 | output.WithBreadcrumbs( |
| 101 | output.Breadcrumb{ |
| 102 | Action: "read", |
| 103 | Command: "hey journal read [date]", |
| 104 | Description: "Read a journal entry", |
| 105 | }, |
| 106 | output.Breadcrumb{ |
| 107 | Action: "write", |
| 108 | Command: "hey journal write '...'", |
| 109 | Description: "Write a journal entry", |
| 110 | }, |
| 111 | ), |
| 112 | ) |
| 113 | } |
| 114 | |
| 115 | // read |
| 116 |
nothing calls this directly
no test coverage detected