-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoutput.go
More file actions
104 lines (88 loc) · 2.64 KB
/
Copy pathoutput.go
File metadata and controls
104 lines (88 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package calendar
import (
"context"
"fmt"
"github.com/open-cli-collective/google-readonly/internal/calendar"
"github.com/open-cli-collective/google-readonly/internal/output"
)
// ClientFactory is the function used to create Calendar clients.
// Override in tests to inject mocks.
var ClientFactory = func() (calendar.CalendarClientInterface, error) {
return calendar.NewClient(context.Background())
}
// newCalendarClient creates a new calendar client
func newCalendarClient() (calendar.CalendarClientInterface, error) {
return ClientFactory()
}
// printJSON outputs data as indented JSON
func printJSON(data any) error {
return output.JSONStdout(data)
}
// printEvent prints a single event in text format
func printEvent(event *calendar.Event, showDescription bool) {
fmt.Printf("ID: %s\n", event.ID)
fmt.Printf("Summary: %s\n", event.Summary)
fmt.Printf("When: %s\n", event.FormatTimeRange())
if event.Location != "" {
fmt.Printf("Location: %s\n", event.Location)
}
if event.HangoutLink != "" {
fmt.Printf("Meet: %s\n", event.HangoutLink)
}
if event.Organizer != nil {
if event.Organizer.DisplayName != "" {
fmt.Printf("Organizer: %s <%s>\n", event.Organizer.DisplayName, event.Organizer.Email)
} else {
fmt.Printf("Organizer: %s\n", event.Organizer.Email)
}
}
if len(event.Attendees) > 0 {
fmt.Printf("Attendees: %d\n", len(event.Attendees))
for _, a := range event.Attendees {
status := ""
if a.Status != "" {
status = fmt.Sprintf(" (%s)", a.Status)
}
if a.DisplayName != "" {
fmt.Printf(" - %s <%s>%s\n", a.DisplayName, a.Email, status)
} else {
fmt.Printf(" - %s%s\n", a.Email, status)
}
}
}
if showDescription && event.Description != "" {
fmt.Println()
fmt.Println("--- Description ---")
fmt.Println(event.Description)
}
}
// printEventSummary prints a brief event summary for list views
func printEventSummary(event *calendar.Event) {
fmt.Printf("ID: %s\n", event.ID)
fmt.Printf("Summary: %s\n", event.Summary)
fmt.Printf("When: %s\n", event.FormatTimeRange())
if event.Location != "" {
fmt.Printf("Location: %s\n", event.Location)
}
if event.HangoutLink != "" {
fmt.Printf("Meet: %s\n", event.HangoutLink)
}
fmt.Println("---")
}
// printCalendar prints a calendar entry
func printCalendar(cal *calendar.CalendarInfo) {
primary := ""
if cal.Primary {
primary = " (primary)"
}
fmt.Printf("ID: %s%s\n", cal.ID, primary)
fmt.Printf("Name: %s\n", cal.Summary)
if cal.Description != "" {
fmt.Printf("Description: %s\n", cal.Description)
}
fmt.Printf("Access: %s\n", cal.AccessRole)
if cal.TimeZone != "" {
fmt.Printf("Timezone: %s\n", cal.TimeZone)
}
fmt.Println("---")
}