gws-cli 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,291 @@
1
+ """Contacts CLI commands."""
2
+
3
+ import typer
4
+ from typing import Annotated, Optional
5
+
6
+ from gws.commands._account import account_callback
7
+ from gws.services.contacts import ContactsService
8
+
9
+ app = typer.Typer(
10
+ name="contacts",
11
+ help="Google Contacts operations.",
12
+ no_args_is_help=True,
13
+ callback=account_callback,
14
+ )
15
+
16
+
17
+ @app.command("list")
18
+ def list_contacts(
19
+ max_results: Annotated[
20
+ int,
21
+ typer.Option("--max", "-n", help="Maximum contacts to return."),
22
+ ] = 10,
23
+ query: Annotated[
24
+ Optional[str],
25
+ typer.Option("--query", "-q", help="Search query."),
26
+ ] = None,
27
+ ) -> None:
28
+ """List contacts."""
29
+ service = ContactsService()
30
+ service.list_contacts(max_results=max_results, query=query)
31
+
32
+
33
+ @app.command("get")
34
+ def get_contact(
35
+ resource_name: Annotated[str, typer.Argument(help="Contact resource name (e.g., people/c123).")],
36
+ ) -> None:
37
+ """Get a specific contact."""
38
+ service = ContactsService()
39
+ service.get_contact(resource_name=resource_name)
40
+
41
+
42
+ @app.command("create")
43
+ def create_contact(
44
+ given_name: Annotated[str, typer.Argument(help="First name.")],
45
+ family_name: Annotated[
46
+ Optional[str],
47
+ typer.Option("--family", "-f", help="Last name."),
48
+ ] = None,
49
+ email: Annotated[
50
+ Optional[str],
51
+ typer.Option("--email", "-e", help="Email address."),
52
+ ] = None,
53
+ phone: Annotated[
54
+ Optional[str],
55
+ typer.Option("--phone", "-p", help="Phone number."),
56
+ ] = None,
57
+ organization: Annotated[
58
+ Optional[str],
59
+ typer.Option("--org", "-o", help="Organization name."),
60
+ ] = None,
61
+ title: Annotated[
62
+ Optional[str],
63
+ typer.Option("--title", "-t", help="Job title."),
64
+ ] = None,
65
+ ) -> None:
66
+ """Create a new contact."""
67
+ service = ContactsService()
68
+ service.create_contact(
69
+ given_name=given_name,
70
+ family_name=family_name,
71
+ email=email,
72
+ phone=phone,
73
+ organization=organization,
74
+ title=title,
75
+ )
76
+
77
+
78
+ @app.command("update")
79
+ def update_contact(
80
+ resource_name: Annotated[str, typer.Argument(help="Contact resource name.")],
81
+ given_name: Annotated[
82
+ Optional[str],
83
+ typer.Option("--given", "-g", help="New first name."),
84
+ ] = None,
85
+ family_name: Annotated[
86
+ Optional[str],
87
+ typer.Option("--family", "-f", help="New last name."),
88
+ ] = None,
89
+ email: Annotated[
90
+ Optional[str],
91
+ typer.Option("--email", "-e", help="New email address."),
92
+ ] = None,
93
+ phone: Annotated[
94
+ Optional[str],
95
+ typer.Option("--phone", "-p", help="New phone number."),
96
+ ] = None,
97
+ ) -> None:
98
+ """Update an existing contact."""
99
+ service = ContactsService()
100
+ service.update_contact(
101
+ resource_name=resource_name,
102
+ given_name=given_name,
103
+ family_name=family_name,
104
+ email=email,
105
+ phone=phone,
106
+ )
107
+
108
+
109
+ @app.command("delete")
110
+ def delete_contact(
111
+ resource_name: Annotated[str, typer.Argument(help="Contact resource name to delete.")],
112
+ ) -> None:
113
+ """Delete a contact."""
114
+ service = ContactsService()
115
+ service.delete_contact(resource_name=resource_name)
116
+
117
+
118
+ # ===== Contact Groups =====
119
+
120
+
121
+ @app.command("groups")
122
+ def list_groups(
123
+ max_results: Annotated[
124
+ int,
125
+ typer.Option("--max", "-n", help="Maximum groups to return."),
126
+ ] = 50,
127
+ ) -> None:
128
+ """List all contact groups."""
129
+ service = ContactsService()
130
+ service.list_groups(max_results=max_results)
131
+
132
+
133
+ @app.command("get-group")
134
+ def get_group(
135
+ resource_name: Annotated[str, typer.Argument(help="Group resource name (e.g., contactGroups/abc123).")],
136
+ no_members: Annotated[
137
+ bool,
138
+ typer.Option("--no-members", help="Don't include member list."),
139
+ ] = False,
140
+ ) -> None:
141
+ """Get a contact group with its members."""
142
+ service = ContactsService()
143
+ service.get_group(resource_name=resource_name, include_members=not no_members)
144
+
145
+
146
+ @app.command("create-group")
147
+ def create_group(
148
+ name: Annotated[str, typer.Argument(help="Name for the new group.")],
149
+ ) -> None:
150
+ """Create a new contact group."""
151
+ service = ContactsService()
152
+ service.create_group(name=name)
153
+
154
+
155
+ @app.command("update-group")
156
+ def update_group(
157
+ resource_name: Annotated[str, typer.Argument(help="Group resource name.")],
158
+ name: Annotated[str, typer.Argument(help="New name for the group.")],
159
+ ) -> None:
160
+ """Rename a contact group."""
161
+ service = ContactsService()
162
+ service.update_group(resource_name=resource_name, name=name)
163
+
164
+
165
+ @app.command("delete-group")
166
+ def delete_group(
167
+ resource_name: Annotated[str, typer.Argument(help="Group resource name to delete.")],
168
+ delete_contacts: Annotated[
169
+ bool,
170
+ typer.Option("--delete-contacts", help="Also delete contacts in the group."),
171
+ ] = False,
172
+ ) -> None:
173
+ """Delete a contact group."""
174
+ service = ContactsService()
175
+ service.delete_group(resource_name=resource_name, delete_contacts=delete_contacts)
176
+
177
+
178
+ @app.command("add-to-group")
179
+ def add_to_group(
180
+ group_resource_name: Annotated[str, typer.Argument(help="Group resource name.")],
181
+ contacts: Annotated[str, typer.Argument(help="Comma-separated contact resource names to add.")],
182
+ ) -> None:
183
+ """Add contacts to a group."""
184
+ contact_list = [c.strip() for c in contacts.split(",")]
185
+ service = ContactsService()
186
+ service.add_to_group(
187
+ group_resource_name=group_resource_name,
188
+ contact_resource_names=contact_list,
189
+ )
190
+
191
+
192
+ @app.command("remove-from-group")
193
+ def remove_from_group(
194
+ group_resource_name: Annotated[str, typer.Argument(help="Group resource name.")],
195
+ contacts: Annotated[str, typer.Argument(help="Comma-separated contact resource names to remove.")],
196
+ ) -> None:
197
+ """Remove contacts from a group."""
198
+ contact_list = [c.strip() for c in contacts.split(",")]
199
+ service = ContactsService()
200
+ service.remove_from_group(
201
+ group_resource_name=group_resource_name,
202
+ contact_resource_names=contact_list,
203
+ )
204
+
205
+
206
+ # ===== Contact Photos =====
207
+
208
+
209
+ @app.command("get-photo")
210
+ def get_photo(
211
+ resource_name: Annotated[str, typer.Argument(help="Contact resource name.")],
212
+ ) -> None:
213
+ """Get a contact's photo URL."""
214
+ service = ContactsService()
215
+ service.get_contact_photo(resource_name=resource_name)
216
+
217
+
218
+ @app.command("set-photo")
219
+ def set_photo(
220
+ resource_name: Annotated[str, typer.Argument(help="Contact resource name.")],
221
+ photo_path: Annotated[str, typer.Argument(help="Path to photo file (JPEG or PNG, max 2MB).")],
222
+ ) -> None:
223
+ """Set a contact's photo from a local file."""
224
+ service = ContactsService()
225
+ service.update_contact_photo(resource_name=resource_name, photo_path=photo_path)
226
+
227
+
228
+ @app.command("delete-photo")
229
+ def delete_photo(
230
+ resource_name: Annotated[str, typer.Argument(help="Contact resource name.")],
231
+ ) -> None:
232
+ """Delete a contact's photo."""
233
+ service = ContactsService()
234
+ service.delete_contact_photo(resource_name=resource_name)
235
+
236
+
237
+ # ===== Directory (Google Workspace domain) =====
238
+
239
+
240
+ @app.command("search-directory")
241
+ def search_directory(
242
+ query: Annotated[str, typer.Argument(help="Search query string.")],
243
+ max_results: Annotated[
244
+ int,
245
+ typer.Option("--max", "-m", help="Maximum number of results."),
246
+ ] = 10,
247
+ fields: Annotated[
248
+ str,
249
+ typer.Option("--fields", "-f", help="Comma-separated fields to return."),
250
+ ] = "names,emailAddresses,organizations",
251
+ ) -> None:
252
+ """Search for people in the Google Workspace directory."""
253
+ service = ContactsService()
254
+ service.search_directory(query=query, max_results=max_results, read_mask=fields)
255
+
256
+
257
+ @app.command("list-directory")
258
+ def list_directory(
259
+ max_results: Annotated[
260
+ int,
261
+ typer.Option("--max", "-m", help="Maximum results per page."),
262
+ ] = 100,
263
+ fields: Annotated[
264
+ str,
265
+ typer.Option("--fields", "-f", help="Comma-separated fields to return."),
266
+ ] = "names,emailAddresses,organizations",
267
+ page_token: Annotated[
268
+ Optional[str],
269
+ typer.Option("--page-token", help="Token for pagination."),
270
+ ] = None,
271
+ ) -> None:
272
+ """List all people in the Google Workspace directory."""
273
+ service = ContactsService()
274
+ service.list_directory(max_results=max_results, read_mask=fields, page_token=page_token)
275
+
276
+
277
+ # ===== Batch Operations =====
278
+
279
+
280
+ @app.command("batch-get")
281
+ def batch_get_contacts(
282
+ resource_names: Annotated[str, typer.Argument(help="Comma-separated resource names.")],
283
+ fields: Annotated[
284
+ str,
285
+ typer.Option("--fields", "-f", help="Comma-separated fields to return."),
286
+ ] = "names,emailAddresses,phoneNumbers,organizations",
287
+ ) -> None:
288
+ """Get multiple contacts in a single request."""
289
+ names = [n.strip() for n in resource_names.split(",")]
290
+ service = ContactsService()
291
+ service.batch_get_contacts(resource_names=names, read_mask=fields)
@@ -0,0 +1,122 @@
1
+ """Document conversion CLI commands."""
2
+
3
+ import typer
4
+ from typing import Annotated, Optional
5
+
6
+ from gws.commands._account import account_callback
7
+ from gws.services.convert import ConvertService
8
+
9
+ app = typer.Typer(
10
+ name="convert",
11
+ help="Document conversion (Markdown to Google formats).",
12
+ no_args_is_help=True,
13
+ callback=account_callback,
14
+ )
15
+
16
+
17
+ @app.command("md-to-doc")
18
+ def md_to_doc(
19
+ input_path: Annotated[str, typer.Argument(help="Path to Markdown file.")],
20
+ title: Annotated[
21
+ Optional[str],
22
+ typer.Option("--title", "-t", help="Document title (default: filename)."),
23
+ ] = None,
24
+ folder_id: Annotated[
25
+ Optional[str],
26
+ typer.Option("--folder", "-f", help="Folder ID to create document in."),
27
+ ] = None,
28
+ render_diagrams: Annotated[
29
+ bool,
30
+ typer.Option("--render-diagrams", "-d", help="Render Mermaid/PlantUML diagrams via Kroki API."),
31
+ ] = False,
32
+ mermaid_theme: Annotated[
33
+ str,
34
+ typer.Option("--mermaid-theme", "-m", help="Mermaid diagram theme: default, neutral, dark, forest."),
35
+ ] = "default",
36
+ pageless: Annotated[
37
+ bool,
38
+ typer.Option("--pageless/--no-pageless", help="Create in pageless mode (default: pageless)."),
39
+ ] = True,
40
+ ) -> None:
41
+ """Convert Markdown file to Google Doc.
42
+
43
+ Uses Google's native Markdown import for high-fidelity conversion.
44
+ Supports headers, lists, code blocks, links, and basic formatting.
45
+
46
+ With --render-diagrams, Mermaid, PlantUML, GraphViz and other diagram
47
+ types are rendered to images via Kroki API and embedded in the document.
48
+
49
+ Documents are created in pageless mode by default. Use --no-pageless
50
+ for traditional page-based documents.
51
+ """
52
+ service = ConvertService()
53
+ service.md_to_doc(
54
+ input_path=input_path,
55
+ title=title,
56
+ folder_id=folder_id,
57
+ render_diagrams=render_diagrams,
58
+ mermaid_theme=mermaid_theme,
59
+ pageless=pageless,
60
+ )
61
+
62
+
63
+ @app.command("md-to-pdf")
64
+ def md_to_pdf(
65
+ input_path: Annotated[str, typer.Argument(help="Path to Markdown file.")],
66
+ output_path: Annotated[str, typer.Argument(help="Path for output PDF file.")],
67
+ title: Annotated[
68
+ Optional[str],
69
+ typer.Option("--title", "-t", help="Temporary doc title."),
70
+ ] = None,
71
+ render_diagrams: Annotated[
72
+ bool,
73
+ typer.Option("--render-diagrams", "-d", help="Render Mermaid/PlantUML diagrams via Kroki API."),
74
+ ] = False,
75
+ mermaid_theme: Annotated[
76
+ str,
77
+ typer.Option("--mermaid-theme", "-m", help="Mermaid diagram theme: default, neutral, dark, forest."),
78
+ ] = "default",
79
+ ) -> None:
80
+ """Convert Markdown file to PDF.
81
+
82
+ Creates a temporary Google Doc, exports as PDF, then deletes the doc.
83
+
84
+ With --render-diagrams, Mermaid, PlantUML, GraphViz and other diagram
85
+ types are rendered to images via Kroki API and embedded in the PDF.
86
+ """
87
+ service = ConvertService()
88
+ service.md_to_pdf(
89
+ input_path=input_path,
90
+ output_path=output_path,
91
+ title=title,
92
+ render_diagrams=render_diagrams,
93
+ mermaid_theme=mermaid_theme,
94
+ )
95
+
96
+
97
+ @app.command("md-to-slides")
98
+ def md_to_slides(
99
+ input_path: Annotated[str, typer.Argument(help="Path to Markdown file.")],
100
+ title: Annotated[
101
+ Optional[str],
102
+ typer.Option("--title", "-t", help="Presentation title (default: filename)."),
103
+ ] = None,
104
+ folder_id: Annotated[
105
+ Optional[str],
106
+ typer.Option("--folder", "-f", help="Folder ID to create presentation in."),
107
+ ] = None,
108
+ ) -> None:
109
+ """Convert Markdown file to Google Slides.
110
+
111
+ Parsing rules:
112
+ - # Heading → New slide with title
113
+ - ## Subheading → Subtitle
114
+ - Bullet lists (- or *) → Slide bullet points
115
+ - --- → Force slide break
116
+ """
117
+ service = ConvertService()
118
+ service.md_to_slides(
119
+ input_path=input_path,
120
+ title=title,
121
+ folder_id=folder_id,
122
+ )