(cmd *cobra.Command, args []string)
| 44 | recordingsCommand.cmd.Flags().BoolVar(&recordingsCommand.all, "all", false, "Fetch all results (override --limit)") |
| 45 | |
| 46 | return recordingsCommand |
| 47 | } |
| 48 | |
| 49 | func (c *recordingsCommand) run(cmd *cobra.Command, args []string) error { |
| 50 | if err := requireAuth(); err != nil { |
| 51 | return err |
| 52 | } |
| 53 | |
| 54 | calendarID, err := strconv.ParseInt(args[0], 10, 64) |
| 55 | if err != nil { |
| 56 | return apierr.ErrUsage(fmt.Sprintf("invalid calendar ID: %s", args[0])) |
| 57 | } |
| 58 | |
| 59 | startsOn := c.startsOn |
| 60 | if startsOn == "" { |
| 61 | startsOn = time.Now().Format(dateLayout) |
| 62 | } |
| 63 | start, err := parseDateArg("starts-on date", startsOn) |
| 64 | if err != nil { |
| 65 | return err |
| 66 | } |
| 67 | |
| 68 | endsOn := c.endsOn |
| 69 | if endsOn == "" { |
| 70 | endsOn = start.AddDate(0, 0, 30).Format(dateLayout) |
| 71 | } |
| 72 | end, err := parseDateArg("ends-on date", endsOn) |
| 73 | if err != nil { |
| 74 | return err |
| 75 | } |
| 76 | if end.Before(start) { |
| 77 | return apierr.ErrUsage(fmt.Sprintf("ends-on %s is before starts-on %s", endsOn, startsOn)) |
| 78 | } |
| 79 | |
| 80 | ctx := cmd.Context() |
| 81 | resp, err := sdk.Calendars().GetRecordings(ctx, calendarID, &generated.GetCalendarRecordingsParams{ |
| 82 | StartsOn: &startsOn, |
| 83 | EndsOn: &endsOn, |
| 84 | }) |
| 85 | if err != nil { |
| 86 | return apierr.FromSDK(err) |
| 87 | } |
| 88 | |
| 89 | if resp == nil { |
| 90 | resp = &generated.CalendarRecordingsResponse{} |
| 91 | } |
| 92 | var total, shown int |
| 93 | for _, recordings := range *resp { |
| 94 | total += len(recordings) |
| 95 | } |
| 96 | if c.limit > 0 && !c.all { |
| 97 | for key, recordings := range *resp { |
| 98 | if len(recordings) > c.limit { |
| 99 | (*resp)[key] = recordings[:c.limit] |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | for _, recordings := range *resp { |
nothing calls this directly
no test coverage detected