(cmd *cobra.Command, args []string)
| 58 | } |
| 59 | |
| 60 | func (c *todoListCommand) 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 | todos := filterRecordingsByType(resp, "Calendar::Todo") |
| 72 | |
| 73 | total := len(todos) |
| 74 | if c.limit > 0 && !c.all && len(todos) > c.limit { |
| 75 | todos = todos[:c.limit] |
| 76 | } |
| 77 | notice := output.TruncationNotice(len(todos), total) |
| 78 | |
| 79 | if writer.IsStyled() { |
| 80 | if len(todos) == 0 { |
| 81 | fmt.Fprintln(cmd.OutOrStdout(), "No todos.") |
| 82 | return nil |
| 83 | } |
| 84 | |
| 85 | table := newTable(cmd.OutOrStdout()) |
| 86 | table.addRow([]string{"ID", "Title", "Date", "Done"}) |
| 87 | for _, t := range todos { |
| 88 | done := "" |
| 89 | if !t.CompletedAt.IsZero() { |
| 90 | done = "yes" |
| 91 | } |
| 92 | table.addRow([]string{fmt.Sprintf("%d", t.Id), t.Title, formatDate(t.StartsAt), done}) |
| 93 | } |
| 94 | table.print() |
| 95 | if notice != "" { |
| 96 | fmt.Fprintln(cmd.OutOrStdout(), notice) |
| 97 | } |
| 98 | return nil |
| 99 | } |
| 100 | |
| 101 | return writeOK(todos, |
| 102 | output.WithSummary(fmt.Sprintf("%d todos", len(todos))), |
| 103 | output.WithNotice(notice), |
| 104 | output.WithBreadcrumbs( |
| 105 | output.Breadcrumb{ |
| 106 | Action: "add", |
| 107 | Command: "hey todo add '...'", |
| 108 | Description: "Add a new todo", |
| 109 | }, |
| 110 | output.Breadcrumb{ |
| 111 | Action: "complete", |
| 112 | Command: "hey todo complete <id>", |
| 113 | Description: "Mark a todo as complete", |
| 114 | }, |
| 115 | ), |
| 116 | ) |
| 117 | } |
nothing calls this directly
no test coverage detected