-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoutput.go
More file actions
159 lines (137 loc) · 3.79 KB
/
Copy pathoutput.go
File metadata and controls
159 lines (137 loc) · 3.79 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package contacts
import (
"context"
"fmt"
"github.com/open-cli-collective/google-readonly/internal/contacts"
"github.com/open-cli-collective/google-readonly/internal/output"
)
// ClientFactory is the function used to create Contacts clients.
// Override in tests to inject mocks.
var ClientFactory = func() (contacts.ContactsClientInterface, error) {
return contacts.NewClient(context.Background())
}
// newContactsClient creates a new contacts client
func newContactsClient() (contacts.ContactsClientInterface, error) {
return ClientFactory()
}
// printJSON outputs data as indented JSON
func printJSON(data any) error {
return output.JSONStdout(data)
}
// printContact prints a single contact in text format
func printContact(contact *contacts.Contact, showDetails bool) {
fmt.Printf("ID: %s\n", contact.ResourceName)
fmt.Printf("Name: %s\n", contact.GetDisplayName())
if email := contact.GetPrimaryEmail(); email != "" {
fmt.Printf("Email: %s\n", email)
}
if phone := contact.GetPrimaryPhone(); phone != "" {
fmt.Printf("Phone: %s\n", phone)
}
if org := contact.GetOrganization(); org != "" {
fmt.Printf("Organization: %s\n", org)
}
if showDetails {
// Show all emails
if len(contact.Emails) > 1 {
fmt.Println("All Emails:")
for _, e := range contact.Emails {
primary := ""
if e.Primary {
primary = " (primary)"
}
typeStr := ""
if e.Type != "" {
typeStr = fmt.Sprintf(" [%s]", e.Type)
}
fmt.Printf(" - %s%s%s\n", e.Value, typeStr, primary)
}
}
// Show all phones
if len(contact.Phones) > 1 {
fmt.Println("All Phones:")
for _, p := range contact.Phones {
typeStr := ""
if p.Type != "" {
typeStr = fmt.Sprintf(" [%s]", p.Type)
}
fmt.Printf(" - %s%s\n", p.Value, typeStr)
}
}
// Show all organizations
if len(contact.Organizations) > 0 {
fmt.Println("Organizations:")
for _, o := range contact.Organizations {
if o.Name != "" {
fmt.Printf(" - %s", o.Name)
if o.Title != "" {
fmt.Printf(" (%s)", o.Title)
}
if o.Department != "" {
fmt.Printf(" - %s", o.Department)
}
fmt.Println()
} else if o.Title != "" {
fmt.Printf(" - %s\n", o.Title)
}
}
}
// Show addresses
if len(contact.Addresses) > 0 {
fmt.Println("Addresses:")
for _, a := range contact.Addresses {
typeStr := ""
if a.Type != "" {
typeStr = fmt.Sprintf("[%s] ", a.Type)
}
fmt.Printf(" - %s%s\n", typeStr, a.FormattedValue)
}
}
// Show URLs
if len(contact.URLs) > 0 {
fmt.Println("URLs:")
for _, u := range contact.URLs {
typeStr := ""
if u.Type != "" {
typeStr = fmt.Sprintf("[%s] ", u.Type)
}
fmt.Printf(" - %s%s\n", typeStr, u.Value)
}
}
// Show birthday
if contact.Birthday != "" {
fmt.Printf("Birthday: %s\n", contact.Birthday)
}
// Show biography
if contact.Biography != "" {
fmt.Println()
fmt.Println("--- Biography ---")
fmt.Println(contact.Biography)
}
}
}
// printContactSummary prints a brief contact summary for list views
func printContactSummary(contact *contacts.Contact) {
fmt.Printf("ID: %s\n", contact.ResourceName)
fmt.Printf("Name: %s\n", contact.GetDisplayName())
if email := contact.GetPrimaryEmail(); email != "" {
fmt.Printf("Email: %s\n", email)
}
if phone := contact.GetPrimaryPhone(); phone != "" {
fmt.Printf("Phone: %s\n", phone)
}
if org := contact.GetOrganization(); org != "" {
fmt.Printf("Organization: %s\n", org)
}
fmt.Println("---")
}
// printContactGroup prints a contact group
func printContactGroup(group *contacts.ContactGroup) {
fmt.Printf("ID: %s\n", group.ResourceName)
fmt.Printf("Name: %s\n", group.Name)
if group.GroupType != "" {
fmt.Printf("Type: %s\n", group.GroupType)
}
fmt.Printf("Members: %d\n", group.MemberCount)
fmt.Println("---")
}