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.
gws/commands/docs.py ADDED
@@ -0,0 +1,1432 @@
1
+ """Docs CLI commands."""
2
+
3
+ import sys
4
+ import typer
5
+ from typing import Annotated, Optional
6
+
7
+ from gws.commands._account import account_callback
8
+ from gws.exceptions import ExitCode
9
+ from gws.output import output_error
10
+ from gws.services.docs import DocsService
11
+
12
+ app = typer.Typer(
13
+ name="docs",
14
+ help="Google Docs document operations.",
15
+ no_args_is_help=True,
16
+ callback=account_callback,
17
+ )
18
+
19
+
20
+ @app.command("list-tabs")
21
+ def list_tabs(
22
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
23
+ ) -> None:
24
+ """List all tabs in a document."""
25
+ service = DocsService()
26
+ service.list_tabs(document_id=document_id)
27
+
28
+
29
+ @app.command("create-tab")
30
+ def create_tab(
31
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
32
+ title: Annotated[str, typer.Argument(help="Title for the new tab.")],
33
+ index: Annotated[
34
+ Optional[int],
35
+ typer.Option("--index", "-i", help="Position for the tab (0-based)."),
36
+ ] = None,
37
+ ) -> None:
38
+ """Create a new tab in the document."""
39
+ service = DocsService()
40
+ service.create_tab(document_id=document_id, title=title, index=index)
41
+
42
+
43
+ @app.command("delete-tab")
44
+ def delete_tab(
45
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
46
+ tab_id: Annotated[str, typer.Argument(help="Tab ID to delete.")],
47
+ ) -> None:
48
+ """Delete a tab from the document.
49
+
50
+ Note: Cannot delete the last remaining tab.
51
+ """
52
+ service = DocsService()
53
+ service.delete_tab(document_id=document_id, tab_id=tab_id)
54
+
55
+
56
+ @app.command("rename-tab")
57
+ def rename_tab(
58
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
59
+ tab_id: Annotated[str, typer.Argument(help="Tab ID to rename.")],
60
+ title: Annotated[str, typer.Argument(help="New title for the tab.")],
61
+ ) -> None:
62
+ """Rename a tab."""
63
+ service = DocsService()
64
+ service.rename_tab(document_id=document_id, tab_id=tab_id, title=title)
65
+
66
+
67
+ @app.command("reorder-tab")
68
+ def reorder_tab(
69
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
70
+ tab_id: Annotated[str, typer.Argument(help="Tab ID to move.")],
71
+ index: Annotated[int, typer.Argument(help="New position (0-based).")],
72
+ ) -> None:
73
+ """Move a tab to a new position."""
74
+ service = DocsService()
75
+ service.reorder_tab(document_id=document_id, tab_id=tab_id, new_index=index)
76
+
77
+
78
+ @app.command("read")
79
+ def read_document(
80
+ document_id: Annotated[str, typer.Argument(help="Document ID to read.")],
81
+ tab_id: Annotated[
82
+ Optional[str],
83
+ typer.Option("--tab", "-t", help="Tab ID to read from."),
84
+ ] = None,
85
+ ) -> None:
86
+ """Read document content as plain text."""
87
+ service = DocsService()
88
+ service.read(document_id=document_id, tab_id=tab_id)
89
+
90
+
91
+ @app.command("structure")
92
+ def get_structure(
93
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
94
+ tab_id: Annotated[
95
+ Optional[str],
96
+ typer.Option("--tab", "-t", help="Tab ID to get structure from."),
97
+ ] = None,
98
+ ) -> None:
99
+ """Get document heading structure."""
100
+ service = DocsService()
101
+ service.structure(document_id=document_id, tab_id=tab_id)
102
+
103
+
104
+ @app.command("export")
105
+ def export_document(
106
+ document_id: Annotated[str, typer.Argument(help="Document ID to export.")],
107
+ output_path: Annotated[str, typer.Argument(help="Local path to save the exported file.")],
108
+ fmt: Annotated[
109
+ str,
110
+ typer.Option("--format", "-f", help="Export format: markdown, pdf, docx, txt, html, rtf, epub, odt."),
111
+ ] = "markdown",
112
+ ) -> None:
113
+ """Export a document to markdown, PDF, DOCX, or other formats.
114
+
115
+ Formats: markdown (md), pdf, docx, txt (text), html, rtf, epub, odt.
116
+ You can also pass a raw MIME type (e.g., application/pdf).
117
+
118
+ Examples:
119
+ gws-cli docs export DOC_ID report.md
120
+ gws-cli docs export DOC_ID report.pdf --format pdf
121
+ gws-cli docs export DOC_ID report.docx --format docx
122
+ """
123
+ service = DocsService()
124
+ service.export(document_id=document_id, output_path=output_path, fmt=fmt)
125
+
126
+
127
+ @app.command("create")
128
+ def create_document(
129
+ title: Annotated[str, typer.Argument(help="Document title.")],
130
+ content: Annotated[
131
+ Optional[str],
132
+ typer.Option("--content", "-c", help="Initial content."),
133
+ ] = None,
134
+ folder_id: Annotated[
135
+ Optional[str],
136
+ typer.Option("--folder", "-f", help="Folder ID to create document in."),
137
+ ] = None,
138
+ stdin: Annotated[
139
+ bool,
140
+ typer.Option("--stdin", help="Read content from stdin."),
141
+ ] = False,
142
+ ) -> None:
143
+ """Create a new document."""
144
+ if stdin:
145
+ content = sys.stdin.read()
146
+
147
+ service = DocsService()
148
+ service.create(title=title, content=content, folder_id=folder_id)
149
+
150
+
151
+ @app.command("insert")
152
+ def insert_text(
153
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
154
+ text: Annotated[str, typer.Argument(help="Text to insert.")],
155
+ index: Annotated[
156
+ int,
157
+ typer.Option("--index", "-i", help="Index to insert at (default: 1)."),
158
+ ] = 1,
159
+ tab_id: Annotated[
160
+ Optional[str],
161
+ typer.Option("--tab", "-t", help="Tab ID to insert into."),
162
+ ] = None,
163
+ ) -> None:
164
+ """Insert text at a specific index."""
165
+ service = DocsService()
166
+ service.insert(document_id=document_id, text=text, index=index, tab_id=tab_id)
167
+
168
+
169
+ @app.command("append")
170
+ def append_text(
171
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
172
+ text: Annotated[
173
+ Optional[str],
174
+ typer.Argument(help="Text to append."),
175
+ ] = None,
176
+ stdin: Annotated[
177
+ bool,
178
+ typer.Option("--stdin", help="Read text from stdin."),
179
+ ] = False,
180
+ tab_id: Annotated[
181
+ Optional[str],
182
+ typer.Option("--tab", "-t", help="Tab ID to append to."),
183
+ ] = None,
184
+ ) -> None:
185
+ """Append text to the end of the document (or tab)."""
186
+ if stdin:
187
+ text = sys.stdin.read()
188
+ elif text is None:
189
+ output_error(
190
+ error_code="INVALID_ARGS",
191
+ operation="docs.append",
192
+ message="Either provide text argument or use --stdin",
193
+ )
194
+ raise typer.Exit(ExitCode.INVALID_ARGS)
195
+
196
+ service = DocsService()
197
+ service.append(document_id=document_id, text=text, tab_id=tab_id)
198
+
199
+
200
+ @app.command("insert-markdown")
201
+ def insert_markdown(
202
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
203
+ markdown: Annotated[
204
+ Optional[str],
205
+ typer.Argument(help="Markdown content to insert."),
206
+ ] = None,
207
+ index: Annotated[
208
+ int,
209
+ typer.Option("--index", "-i", help="Character index for insertion."),
210
+ ] = 1,
211
+ tab_id: Annotated[
212
+ Optional[str],
213
+ typer.Option("--tab", "-t", help="Tab ID for documents with tabs."),
214
+ ] = None,
215
+ stdin: Annotated[
216
+ bool,
217
+ typer.Option("--stdin", "-s", help="Read markdown content from stdin."),
218
+ ] = False,
219
+ file: Annotated[
220
+ Optional[str],
221
+ typer.Option("--file", "-f", help="Read markdown from file path."),
222
+ ] = None,
223
+ ) -> None:
224
+ """Insert markdown content with automatic formatting conversion.
225
+
226
+ Google converts the markdown to formatted text (bold, italic, links, etc.).
227
+
228
+ Examples:
229
+ gws-cli docs insert-markdown DOC_ID "# Heading\\n\\n**Bold** text"
230
+ gws-cli docs insert-markdown DOC_ID --file notes.md
231
+ cat notes.md | gws-cli docs insert-markdown DOC_ID --stdin
232
+ """
233
+ # Determine the source of markdown content
234
+ if stdin:
235
+ markdown_content = sys.stdin.read()
236
+ elif file:
237
+ from pathlib import Path
238
+ path = Path(file)
239
+ if not path.exists():
240
+ output_error(
241
+ error_code="INVALID_ARGS",
242
+ operation="docs.insert_markdown",
243
+ message=f"File not found: {file}",
244
+ )
245
+ raise typer.Exit(ExitCode.INVALID_ARGS)
246
+ markdown_content = path.read_text(encoding="utf-8")
247
+ elif markdown:
248
+ markdown_content = markdown
249
+ else:
250
+ output_error(
251
+ error_code="INVALID_ARGS",
252
+ operation="docs.insert_markdown",
253
+ message="Provide markdown argument, --file, or --stdin",
254
+ )
255
+ raise typer.Exit(ExitCode.INVALID_ARGS)
256
+
257
+ service = DocsService()
258
+ service.insert_markdown(
259
+ document_id=document_id,
260
+ markdown_content=markdown_content,
261
+ index=index,
262
+ tab_id=tab_id,
263
+ )
264
+
265
+
266
+ @app.command("replace")
267
+ def replace_text(
268
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
269
+ find: Annotated[str, typer.Argument(help="Text to find.")],
270
+ replace_with: Annotated[str, typer.Argument(help="Replacement text.")],
271
+ match_case: Annotated[
272
+ bool,
273
+ typer.Option("--match-case", "-m", help="Case-sensitive matching."),
274
+ ] = False,
275
+ tab_id: Annotated[
276
+ Optional[str],
277
+ typer.Option("--tab", "-t", help="Tab ID to restrict replacement to."),
278
+ ] = None,
279
+ ) -> None:
280
+ """Replace text throughout the document (or specific tab)."""
281
+ service = DocsService()
282
+ service.replace(
283
+ document_id=document_id,
284
+ find=find,
285
+ replace_with=replace_with,
286
+ match_case=match_case,
287
+ tab_id=tab_id,
288
+ )
289
+
290
+
291
+ @app.command("format")
292
+ def format_text(
293
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
294
+ start_index: Annotated[int, typer.Argument(help="Start index.")],
295
+ end_index: Annotated[int, typer.Argument(help="End index.")],
296
+ bold: Annotated[
297
+ Optional[bool],
298
+ typer.Option("--bold/--no-bold", "-b", help="Bold formatting."),
299
+ ] = None,
300
+ italic: Annotated[
301
+ Optional[bool],
302
+ typer.Option("--italic/--no-italic", "-i", help="Italic formatting."),
303
+ ] = None,
304
+ underline: Annotated[
305
+ Optional[bool],
306
+ typer.Option("--underline/--no-underline", "-u", help="Underline formatting."),
307
+ ] = None,
308
+ font_size: Annotated[
309
+ Optional[int],
310
+ typer.Option("--font-size", "-s", help="Font size in points."),
311
+ ] = None,
312
+ color: Annotated[
313
+ Optional[str],
314
+ typer.Option("--color", help="Text color (hex, e.g., #FF0000)."),
315
+ ] = None,
316
+ tab_id: Annotated[
317
+ Optional[str],
318
+ typer.Option("--tab", "-t", help="Tab ID."),
319
+ ] = None,
320
+ ) -> None:
321
+ """Apply formatting to a text range."""
322
+ service = DocsService()
323
+ service.format_text(
324
+ document_id=document_id,
325
+ start_index=start_index,
326
+ end_index=end_index,
327
+ bold=bold,
328
+ italic=italic,
329
+ underline=underline,
330
+ font_size=font_size,
331
+ foreground_color=color,
332
+ tab_id=tab_id,
333
+ )
334
+
335
+
336
+ @app.command("delete")
337
+ def delete_content(
338
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
339
+ start_index: Annotated[int, typer.Argument(help="Start index.")],
340
+ end_index: Annotated[int, typer.Argument(help="End index.")],
341
+ tab_id: Annotated[
342
+ Optional[str],
343
+ typer.Option("--tab", "-t", help="Tab ID."),
344
+ ] = None,
345
+ ) -> None:
346
+ """Delete content in a range."""
347
+ service = DocsService()
348
+ service.delete_content(
349
+ document_id=document_id,
350
+ start_index=start_index,
351
+ end_index=end_index,
352
+ tab_id=tab_id,
353
+ )
354
+
355
+
356
+ @app.command("page-break")
357
+ def insert_page_break(
358
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
359
+ index: Annotated[int, typer.Argument(help="Index to insert page break.")],
360
+ tab_id: Annotated[
361
+ Optional[str],
362
+ typer.Option("--tab", "-t", help="Tab ID."),
363
+ ] = None,
364
+ ) -> None:
365
+ """Insert a page break at the specified index."""
366
+ service = DocsService()
367
+ service.insert_page_break(document_id=document_id, index=index, tab_id=tab_id)
368
+
369
+
370
+ @app.command("insert-image")
371
+ def insert_image(
372
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
373
+ image_url: Annotated[str, typer.Argument(help="Image URL (must be publicly accessible).")],
374
+ index: Annotated[
375
+ Optional[int],
376
+ typer.Option("--index", "-i", help="Index to insert at (default: end)."),
377
+ ] = None,
378
+ width: Annotated[
379
+ Optional[float],
380
+ typer.Option("--width", "-w", help="Width in points."),
381
+ ] = None,
382
+ height: Annotated[
383
+ Optional[float],
384
+ typer.Option("--height", "-h", help="Height in points."),
385
+ ] = None,
386
+ tab_id: Annotated[
387
+ Optional[str],
388
+ typer.Option("--tab", "-t", help="Tab ID."),
389
+ ] = None,
390
+ ) -> None:
391
+ """Insert an image from a URL."""
392
+ service = DocsService()
393
+ service.insert_image(
394
+ document_id=document_id,
395
+ image_url=image_url,
396
+ index=index,
397
+ width=width,
398
+ height=height,
399
+ tab_id=tab_id,
400
+ )
401
+
402
+
403
+ # =============================================================================
404
+ # TABLE COMMANDS
405
+ # =============================================================================
406
+
407
+
408
+ @app.command("list-tables")
409
+ def list_tables(
410
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
411
+ ) -> None:
412
+ """List all tables in the document."""
413
+ service = DocsService()
414
+ service.list_tables(document_id=document_id)
415
+
416
+
417
+ @app.command("insert-table")
418
+ def insert_table(
419
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
420
+ rows: Annotated[int, typer.Argument(help="Number of rows.")],
421
+ columns: Annotated[int, typer.Argument(help="Number of columns.")],
422
+ index: Annotated[
423
+ Optional[int],
424
+ typer.Option("--index", "-i", help="Insert position (default: end)."),
425
+ ] = None,
426
+ ) -> None:
427
+ """Insert a table into the document."""
428
+ service = DocsService()
429
+ service.insert_table(
430
+ document_id=document_id,
431
+ rows=rows,
432
+ columns=columns,
433
+ index=index,
434
+ )
435
+
436
+
437
+ @app.command("insert-table-row")
438
+ def insert_table_row(
439
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
440
+ table_index: Annotated[int, typer.Argument(help="Table index (0-based).")],
441
+ row_index: Annotated[int, typer.Argument(help="Row index to insert at.")],
442
+ above: Annotated[
443
+ bool,
444
+ typer.Option("--above", help="Insert above instead of below."),
445
+ ] = False,
446
+ ) -> None:
447
+ """Insert a row into a table."""
448
+ service = DocsService()
449
+ service.insert_table_row(
450
+ document_id=document_id,
451
+ table_index=table_index,
452
+ row_index=row_index,
453
+ insert_below=not above,
454
+ )
455
+
456
+
457
+ @app.command("insert-table-column")
458
+ def insert_table_column(
459
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
460
+ table_index: Annotated[int, typer.Argument(help="Table index (0-based).")],
461
+ column_index: Annotated[int, typer.Argument(help="Column index to insert at.")],
462
+ left: Annotated[
463
+ bool,
464
+ typer.Option("--left", help="Insert left instead of right."),
465
+ ] = False,
466
+ ) -> None:
467
+ """Insert a column into a table."""
468
+ service = DocsService()
469
+ service.insert_table_column(
470
+ document_id=document_id,
471
+ table_index=table_index,
472
+ column_index=column_index,
473
+ insert_right=not left,
474
+ )
475
+
476
+
477
+ @app.command("delete-table-row")
478
+ def delete_table_row(
479
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
480
+ table_index: Annotated[int, typer.Argument(help="Table index (0-based).")],
481
+ row_index: Annotated[int, typer.Argument(help="Row index to delete.")],
482
+ ) -> None:
483
+ """Delete a row from a table."""
484
+ service = DocsService()
485
+ service.delete_table_row(
486
+ document_id=document_id,
487
+ table_index=table_index,
488
+ row_index=row_index,
489
+ )
490
+
491
+
492
+ @app.command("delete-table-column")
493
+ def delete_table_column(
494
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
495
+ table_index: Annotated[int, typer.Argument(help="Table index (0-based).")],
496
+ column_index: Annotated[int, typer.Argument(help="Column index to delete.")],
497
+ ) -> None:
498
+ """Delete a column from a table."""
499
+ service = DocsService()
500
+ service.delete_table_column(
501
+ document_id=document_id,
502
+ table_index=table_index,
503
+ column_index=column_index,
504
+ )
505
+
506
+
507
+ @app.command("merge-cells")
508
+ def merge_cells(
509
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
510
+ table_index: Annotated[int, typer.Argument(help="Table index (0-based).")],
511
+ start_row: Annotated[int, typer.Argument(help="Start row index.")],
512
+ start_column: Annotated[int, typer.Argument(help="Start column index.")],
513
+ end_row: Annotated[int, typer.Argument(help="End row index.")],
514
+ end_column: Annotated[int, typer.Argument(help="End column index.")],
515
+ ) -> None:
516
+ """Merge cells in a table."""
517
+ service = DocsService()
518
+ service.merge_table_cells(
519
+ document_id=document_id,
520
+ table_index=table_index,
521
+ start_row=start_row,
522
+ start_column=start_column,
523
+ end_row=end_row,
524
+ end_column=end_column,
525
+ )
526
+
527
+
528
+ @app.command("unmerge-cells")
529
+ def unmerge_cells(
530
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
531
+ table_index: Annotated[int, typer.Argument(help="Table index (0-based).")],
532
+ start_row: Annotated[int, typer.Argument(help="Start row index.")],
533
+ start_column: Annotated[int, typer.Argument(help="Start column index.")],
534
+ end_row: Annotated[int, typer.Argument(help="End row index.")],
535
+ end_column: Annotated[int, typer.Argument(help="End column index.")],
536
+ ) -> None:
537
+ """Unmerge previously merged cells in a table."""
538
+ service = DocsService()
539
+ service.unmerge_table_cells(
540
+ document_id=document_id,
541
+ table_index=table_index,
542
+ start_row=start_row,
543
+ start_column=start_column,
544
+ end_row=end_row,
545
+ end_column=end_column,
546
+ )
547
+
548
+
549
+ @app.command("style-table-cell")
550
+ def style_table_cell(
551
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
552
+ table_index: Annotated[int, typer.Argument(help="Table index (0-based).")],
553
+ start_row: Annotated[int, typer.Argument(help="Start row index.")],
554
+ start_column: Annotated[int, typer.Argument(help="Start column index.")],
555
+ end_row: Annotated[
556
+ Optional[int],
557
+ typer.Option("--end-row", help="End row index (default: same as start)."),
558
+ ] = None,
559
+ end_column: Annotated[
560
+ Optional[int],
561
+ typer.Option("--end-column", help="End column index (default: same as start)."),
562
+ ] = None,
563
+ bg_color: Annotated[
564
+ Optional[str],
565
+ typer.Option("--bg-color", help="Background color (hex, e.g., #FFFF00)."),
566
+ ] = None,
567
+ border_color: Annotated[
568
+ Optional[str],
569
+ typer.Option("--border-color", help="Border color (hex)."),
570
+ ] = None,
571
+ border_width: Annotated[
572
+ Optional[float],
573
+ typer.Option("--border-width", help="Border width in points."),
574
+ ] = None,
575
+ padding: Annotated[
576
+ Optional[float],
577
+ typer.Option("--padding", help="Padding for all sides in points."),
578
+ ] = None,
579
+ ) -> None:
580
+ """Style table cells (background, borders, padding)."""
581
+ service = DocsService()
582
+ service.style_table_cell(
583
+ document_id=document_id,
584
+ table_index=table_index,
585
+ start_row=start_row,
586
+ start_column=start_column,
587
+ end_row=end_row,
588
+ end_column=end_column,
589
+ background_color=bg_color,
590
+ border_color=border_color,
591
+ border_width=border_width,
592
+ padding_top=padding,
593
+ padding_bottom=padding,
594
+ padding_left=padding,
595
+ padding_right=padding,
596
+ )
597
+
598
+
599
+ @app.command("set-column-width")
600
+ def set_column_width(
601
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
602
+ table_index: Annotated[int, typer.Argument(help="Table index (0-based).")],
603
+ column_index: Annotated[int, typer.Argument(help="Column index.")],
604
+ width: Annotated[float, typer.Argument(help="Width in points.")],
605
+ ) -> None:
606
+ """Set the width of a table column."""
607
+ service = DocsService()
608
+ service.set_column_width(
609
+ document_id=document_id,
610
+ table_index=table_index,
611
+ column_index=column_index,
612
+ width=width,
613
+ )
614
+
615
+
616
+ @app.command("set-table-column-widths")
617
+ def set_table_column_widths(
618
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
619
+ table_index: Annotated[int, typer.Argument(help="Table index (0-based).")],
620
+ column_widths: Annotated[
621
+ str,
622
+ typer.Argument(
623
+ help='JSON mapping column index to width in points. Example: \'{"0":70,"1":90,"2":170}\''
624
+ ),
625
+ ],
626
+ ) -> None:
627
+ """Set widths for multiple table columns in a single API call."""
628
+ import json
629
+
630
+ try:
631
+ widths_dict = json.loads(column_widths)
632
+ # Convert string keys to int (JSON keys are always strings)
633
+ widths_dict = {int(k): float(v) for k, v in widths_dict.items()}
634
+ except (json.JSONDecodeError, ValueError) as e:
635
+ output_error(
636
+ error_code="INVALID_ARGS",
637
+ operation="docs.set_table_column_widths",
638
+ message=f"Invalid JSON for column_widths: {e}",
639
+ )
640
+ raise typer.Exit(ExitCode.INVALID_ARGS)
641
+
642
+ service = DocsService()
643
+ service.set_table_column_widths(
644
+ document_id=document_id,
645
+ table_index=table_index,
646
+ column_widths=widths_dict,
647
+ )
648
+
649
+
650
+ @app.command("pin-table-header")
651
+ def pin_table_header(
652
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
653
+ table_index: Annotated[int, typer.Argument(help="Table index (0-based).")],
654
+ rows: Annotated[
655
+ int,
656
+ typer.Option("--rows", "-r", help="Number of rows to pin as header."),
657
+ ] = 1,
658
+ ) -> None:
659
+ """Pin header rows in a table (they repeat on each page)."""
660
+ service = DocsService()
661
+ service.pin_table_header(
662
+ document_id=document_id,
663
+ table_index=table_index,
664
+ rows_to_pin=rows,
665
+ )
666
+
667
+
668
+ # =============================================================================
669
+ # PARAGRAPH STYLE COMMANDS
670
+ # =============================================================================
671
+
672
+
673
+ @app.command("format-paragraph")
674
+ def format_paragraph(
675
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
676
+ start_index: Annotated[int, typer.Argument(help="Start index.")],
677
+ end_index: Annotated[int, typer.Argument(help="End index.")],
678
+ alignment: Annotated[
679
+ Optional[str],
680
+ typer.Option("--align", "-a", help="Alignment: START, CENTER, END, JUSTIFIED."),
681
+ ] = None,
682
+ style: Annotated[
683
+ Optional[str],
684
+ typer.Option("--style", "-s", help="Named style: TITLE, HEADING_1, etc."),
685
+ ] = None,
686
+ line_spacing: Annotated[
687
+ Optional[float],
688
+ typer.Option("--line-spacing", help="Line spacing (100=single, 200=double)."),
689
+ ] = None,
690
+ space_above: Annotated[
691
+ Optional[float],
692
+ typer.Option("--space-above", help="Space above paragraph in points."),
693
+ ] = None,
694
+ space_below: Annotated[
695
+ Optional[float],
696
+ typer.Option("--space-below", help="Space below paragraph in points."),
697
+ ] = None,
698
+ indent_first: Annotated[
699
+ Optional[float],
700
+ typer.Option("--indent-first", help="First line indent in points."),
701
+ ] = None,
702
+ indent_left: Annotated[
703
+ Optional[float],
704
+ typer.Option("--indent-left", help="Left indent in points."),
705
+ ] = None,
706
+ indent_right: Annotated[
707
+ Optional[float],
708
+ typer.Option("--indent-right", help="Right indent in points."),
709
+ ] = None,
710
+ shading: Annotated[
711
+ Optional[str],
712
+ typer.Option("--shading", help="Background color (hex, e.g., #FFFFCC)."),
713
+ ] = None,
714
+ keep_together: Annotated[
715
+ Optional[bool],
716
+ typer.Option("--keep-together/--no-keep-together", help="Keep lines together."),
717
+ ] = None,
718
+ keep_with_next: Annotated[
719
+ Optional[bool],
720
+ typer.Option("--keep-with-next/--no-keep-with-next", help="Keep with next paragraph."),
721
+ ] = None,
722
+ ) -> None:
723
+ """Apply paragraph formatting (alignment, spacing, indentation, style)."""
724
+ service = DocsService()
725
+ service.format_paragraph(
726
+ document_id=document_id,
727
+ start_index=start_index,
728
+ end_index=end_index,
729
+ alignment=alignment,
730
+ named_style=style,
731
+ line_spacing=line_spacing,
732
+ space_above=space_above,
733
+ space_below=space_below,
734
+ indent_first_line=indent_first,
735
+ indent_start=indent_left,
736
+ indent_end=indent_right,
737
+ keep_lines_together=keep_together,
738
+ keep_with_next=keep_with_next,
739
+ shading_color=shading,
740
+ )
741
+
742
+
743
+ @app.command("paragraph-border")
744
+ def paragraph_border(
745
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
746
+ start_index: Annotated[int, typer.Argument(help="Start index.")],
747
+ end_index: Annotated[int, typer.Argument(help="End index.")],
748
+ color: Annotated[
749
+ str,
750
+ typer.Option("--color", "-c", help="Border color (hex)."),
751
+ ] = "#000000",
752
+ width: Annotated[
753
+ float,
754
+ typer.Option("--width", "-w", help="Border width in points."),
755
+ ] = 1.0,
756
+ top: Annotated[bool, typer.Option("--top", help="Add top border.")] = False,
757
+ bottom: Annotated[bool, typer.Option("--bottom", help="Add bottom border.")] = False,
758
+ left: Annotated[bool, typer.Option("--left", help="Add left border.")] = False,
759
+ right: Annotated[bool, typer.Option("--right", help="Add right border.")] = False,
760
+ between: Annotated[bool, typer.Option("--between", help="Add border between paragraphs.")] = False,
761
+ all_sides: Annotated[bool, typer.Option("--all", help="Add borders on all sides.")] = False,
762
+ ) -> None:
763
+ """Add borders to paragraphs."""
764
+ service = DocsService()
765
+ service.set_paragraph_border(
766
+ document_id=document_id,
767
+ start_index=start_index,
768
+ end_index=end_index,
769
+ color=color,
770
+ width=width,
771
+ top=top or all_sides,
772
+ bottom=bottom or all_sides,
773
+ left=left or all_sides,
774
+ right=right or all_sides,
775
+ between=between,
776
+ )
777
+
778
+
779
+ # =============================================================================
780
+ # EXTENDED TEXT STYLE COMMANDS (Phase 3)
781
+ # =============================================================================
782
+
783
+
784
+ @app.command("format-text-extended")
785
+ def format_text_extended(
786
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
787
+ start_index: Annotated[int, typer.Argument(help="Start index.")],
788
+ end_index: Annotated[int, typer.Argument(help="End index.")],
789
+ bold: Annotated[
790
+ Optional[bool],
791
+ typer.Option("--bold/--no-bold", "-b", help="Bold formatting."),
792
+ ] = None,
793
+ italic: Annotated[
794
+ Optional[bool],
795
+ typer.Option("--italic/--no-italic", "-i", help="Italic formatting."),
796
+ ] = None,
797
+ underline: Annotated[
798
+ Optional[bool],
799
+ typer.Option("--underline/--no-underline", "-u", help="Underline."),
800
+ ] = None,
801
+ strikethrough: Annotated[
802
+ Optional[bool],
803
+ typer.Option("--strikethrough/--no-strikethrough", help="Strikethrough."),
804
+ ] = None,
805
+ small_caps: Annotated[
806
+ Optional[bool],
807
+ typer.Option("--small-caps/--no-small-caps", help="Small caps."),
808
+ ] = None,
809
+ font: Annotated[
810
+ Optional[str],
811
+ typer.Option("--font", "-f", help="Font family (e.g., 'Arial', 'Times New Roman')."),
812
+ ] = None,
813
+ weight: Annotated[
814
+ Optional[int],
815
+ typer.Option("--weight", help="Font weight (100-900, 400=normal, 700=bold)."),
816
+ ] = None,
817
+ size: Annotated[
818
+ Optional[int],
819
+ typer.Option("--size", "-s", help="Font size in points."),
820
+ ] = None,
821
+ color: Annotated[
822
+ Optional[str],
823
+ typer.Option("--color", "-c", help="Text color (hex, e.g., #FF0000)."),
824
+ ] = None,
825
+ bg_color: Annotated[
826
+ Optional[str],
827
+ typer.Option("--bg-color", help="Background/highlight color (hex)."),
828
+ ] = None,
829
+ superscript: Annotated[
830
+ bool,
831
+ typer.Option("--superscript", help="Apply superscript."),
832
+ ] = False,
833
+ subscript: Annotated[
834
+ bool,
835
+ typer.Option("--subscript", help="Apply subscript."),
836
+ ] = False,
837
+ link: Annotated[
838
+ Optional[str],
839
+ typer.Option("--link", help="Add hyperlink URL."),
840
+ ] = None,
841
+ ) -> None:
842
+ """Apply extended text formatting (fonts, colors, effects)."""
843
+ baseline = None
844
+ if superscript:
845
+ baseline = "SUPERSCRIPT"
846
+ elif subscript:
847
+ baseline = "SUBSCRIPT"
848
+
849
+ service = DocsService()
850
+ service.format_text_extended(
851
+ document_id=document_id,
852
+ start_index=start_index,
853
+ end_index=end_index,
854
+ bold=bold,
855
+ italic=italic,
856
+ underline=underline,
857
+ strikethrough=strikethrough,
858
+ small_caps=small_caps,
859
+ font_family=font,
860
+ font_weight=weight,
861
+ font_size=size,
862
+ foreground_color=color,
863
+ background_color=bg_color,
864
+ baseline_offset=baseline,
865
+ link_url=link,
866
+ )
867
+
868
+
869
+ @app.command("insert-link")
870
+ def insert_link(
871
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
872
+ start_index: Annotated[int, typer.Argument(help="Start index of text to link.")],
873
+ end_index: Annotated[int, typer.Argument(help="End index of text to link.")],
874
+ url: Annotated[str, typer.Argument(help="URL to link to.")],
875
+ ) -> None:
876
+ """Add a hyperlink to existing text."""
877
+ service = DocsService()
878
+ service.insert_link(
879
+ document_id=document_id,
880
+ start_index=start_index,
881
+ end_index=end_index,
882
+ url=url,
883
+ )
884
+
885
+
886
+ # =============================================================================
887
+ # HEADER/FOOTER COMMANDS (Phase 4)
888
+ # =============================================================================
889
+
890
+
891
+ @app.command("create-header")
892
+ def create_header(
893
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
894
+ header_type: Annotated[
895
+ str,
896
+ typer.Option("--type", "-t", help="Header type: DEFAULT or FIRST_PAGE_HEADER."),
897
+ ] = "DEFAULT",
898
+ ) -> None:
899
+ """Create a document header."""
900
+ service = DocsService()
901
+ service.create_header(document_id=document_id, header_type=header_type)
902
+
903
+
904
+ @app.command("create-footer")
905
+ def create_footer(
906
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
907
+ footer_type: Annotated[
908
+ str,
909
+ typer.Option("--type", "-t", help="Footer type: DEFAULT or FIRST_PAGE_FOOTER."),
910
+ ] = "DEFAULT",
911
+ ) -> None:
912
+ """Create a document footer."""
913
+ service = DocsService()
914
+ service.create_footer(document_id=document_id, footer_type=footer_type)
915
+
916
+
917
+ @app.command("delete-header")
918
+ def delete_header(
919
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
920
+ header_id: Annotated[str, typer.Argument(help="Header ID to delete.")],
921
+ ) -> None:
922
+ """Delete a document header."""
923
+ service = DocsService()
924
+ service.delete_header(document_id=document_id, header_id=header_id)
925
+
926
+
927
+ @app.command("delete-footer")
928
+ def delete_footer(
929
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
930
+ footer_id: Annotated[str, typer.Argument(help="Footer ID to delete.")],
931
+ ) -> None:
932
+ """Delete a document footer."""
933
+ service = DocsService()
934
+ service.delete_footer(document_id=document_id, footer_id=footer_id)
935
+
936
+
937
+ @app.command("list-headers-footers")
938
+ def list_headers_footers(
939
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
940
+ ) -> None:
941
+ """List all headers and footers in the document."""
942
+ service = DocsService()
943
+ service.get_headers_footers(document_id=document_id)
944
+
945
+
946
+ @app.command("insert-segment-text")
947
+ def insert_segment_text(
948
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
949
+ segment_id: Annotated[str, typer.Argument(help="Header or footer segment ID.")],
950
+ text: Annotated[str, typer.Argument(help="Text to insert.")],
951
+ index: Annotated[
952
+ int,
953
+ typer.Option("--index", "-i", help="Insert position within segment."),
954
+ ] = 0,
955
+ ) -> None:
956
+ """Insert text into a header or footer."""
957
+ service = DocsService()
958
+ service.insert_text_in_segment(
959
+ document_id=document_id,
960
+ segment_id=segment_id,
961
+ text=text,
962
+ index=index,
963
+ )
964
+
965
+
966
+ # =============================================================================
967
+ # LIST/BULLET COMMANDS (Phase 5)
968
+ # =============================================================================
969
+
970
+
971
+ @app.command("create-bullets")
972
+ def create_bullets(
973
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
974
+ start_index: Annotated[int, typer.Argument(help="Start index.")],
975
+ end_index: Annotated[int, typer.Argument(help="End index.")],
976
+ preset: Annotated[
977
+ str,
978
+ typer.Option("--preset", "-p", help="Bullet style preset."),
979
+ ] = "BULLET_DISC_CIRCLE_SQUARE",
980
+ ) -> None:
981
+ """Create a bulleted list from paragraphs.
982
+
983
+ Presets: BULLET_DISC_CIRCLE_SQUARE, BULLET_DIAMONDX_ARROW3D_SQUARE,
984
+ BULLET_CHECKBOX, BULLET_ARROW_DIAMOND_DISC, BULLET_STAR_CIRCLE_SQUARE
985
+ """
986
+ service = DocsService()
987
+ service.create_bullets(
988
+ document_id=document_id,
989
+ start_index=start_index,
990
+ end_index=end_index,
991
+ preset=preset,
992
+ )
993
+
994
+
995
+ @app.command("create-numbered")
996
+ def create_numbered_list(
997
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
998
+ start_index: Annotated[int, typer.Argument(help="Start index.")],
999
+ end_index: Annotated[int, typer.Argument(help="End index.")],
1000
+ preset: Annotated[
1001
+ str,
1002
+ typer.Option("--preset", "-p", help="Numbering style preset."),
1003
+ ] = "NUMBERED_DECIMAL_NESTED",
1004
+ ) -> None:
1005
+ """Create a numbered list from paragraphs.
1006
+
1007
+ Presets: NUMBERED_DECIMAL_NESTED, NUMBERED_DECIMAL_ALPHA_ROMAN,
1008
+ NUMBERED_UPPERALPHA_ALPHA_ROMAN, NUMBERED_UPPERROMAN_UPPERALPHA_DECIMAL
1009
+ """
1010
+ service = DocsService()
1011
+ service.create_numbered_list(
1012
+ document_id=document_id,
1013
+ start_index=start_index,
1014
+ end_index=end_index,
1015
+ preset=preset,
1016
+ )
1017
+
1018
+
1019
+ @app.command("remove-bullets")
1020
+ def remove_bullets(
1021
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
1022
+ start_index: Annotated[int, typer.Argument(help="Start index.")],
1023
+ end_index: Annotated[int, typer.Argument(help="End index.")],
1024
+ ) -> None:
1025
+ """Remove bullets or numbering from paragraphs."""
1026
+ service = DocsService()
1027
+ service.remove_bullets(
1028
+ document_id=document_id,
1029
+ start_index=start_index,
1030
+ end_index=end_index,
1031
+ )
1032
+
1033
+
1034
+ # =============================================================================
1035
+ # SECTION AND DOCUMENT STYLE COMMANDS (Phase 6)
1036
+ # =============================================================================
1037
+
1038
+
1039
+ @app.command("insert-section-break")
1040
+ def insert_section_break(
1041
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
1042
+ index: Annotated[int, typer.Argument(help="Index to insert break.")],
1043
+ break_type: Annotated[
1044
+ str,
1045
+ typer.Option("--type", "-t", help="Break type: NEXT_PAGE or CONTINUOUS."),
1046
+ ] = "NEXT_PAGE",
1047
+ ) -> None:
1048
+ """Insert a section break."""
1049
+ service = DocsService()
1050
+ service.insert_section_break(
1051
+ document_id=document_id,
1052
+ index=index,
1053
+ break_type=break_type,
1054
+ )
1055
+
1056
+
1057
+ @app.command("document-style")
1058
+ def document_style(
1059
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
1060
+ margin_top: Annotated[
1061
+ Optional[float],
1062
+ typer.Option("--margin-top", help="Top margin in points."),
1063
+ ] = None,
1064
+ margin_bottom: Annotated[
1065
+ Optional[float],
1066
+ typer.Option("--margin-bottom", help="Bottom margin in points."),
1067
+ ] = None,
1068
+ margin_left: Annotated[
1069
+ Optional[float],
1070
+ typer.Option("--margin-left", help="Left margin in points."),
1071
+ ] = None,
1072
+ margin_right: Annotated[
1073
+ Optional[float],
1074
+ typer.Option("--margin-right", help="Right margin in points."),
1075
+ ] = None,
1076
+ page_width: Annotated[
1077
+ Optional[float],
1078
+ typer.Option("--page-width", help="Page width in points (612=Letter, 595=A4)."),
1079
+ ] = None,
1080
+ page_height: Annotated[
1081
+ Optional[float],
1082
+ typer.Option("--page-height", help="Page height in points (792=Letter, 842=A4)."),
1083
+ ] = None,
1084
+ use_first_page_header_footer: Annotated[
1085
+ Optional[bool],
1086
+ typer.Option("--first-page-diff/--no-first-page-diff",
1087
+ help="Use different header/footer on first page."),
1088
+ ] = None,
1089
+ ) -> None:
1090
+ """Update document-level style (margins, page size).
1091
+
1092
+ Measurements in points (72 points = 1 inch).
1093
+ Letter: 612x792 points, A4: 595x842 points.
1094
+ """
1095
+ service = DocsService()
1096
+ service.update_document_style(
1097
+ document_id=document_id,
1098
+ margin_top=margin_top,
1099
+ margin_bottom=margin_bottom,
1100
+ margin_left=margin_left,
1101
+ margin_right=margin_right,
1102
+ page_width=page_width,
1103
+ page_height=page_height,
1104
+ use_first_page_header_footer=use_first_page_header_footer,
1105
+ )
1106
+
1107
+
1108
+ # =============================================================================
1109
+ # PAGE FORMAT COMMANDS (Pageless Mode)
1110
+ # =============================================================================
1111
+
1112
+
1113
+ @app.command("get-page-format")
1114
+ def get_page_format(
1115
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
1116
+ ) -> None:
1117
+ """Get the document's page format (PAGES or PAGELESS)."""
1118
+ service = DocsService()
1119
+ service.get_page_format(document_id=document_id)
1120
+
1121
+
1122
+ @app.command("set-page-format")
1123
+ def set_page_format(
1124
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
1125
+ mode: Annotated[
1126
+ str,
1127
+ typer.Argument(help="Page format: 'pages' (traditional) or 'pageless' (continuous)."),
1128
+ ],
1129
+ ) -> None:
1130
+ """Set the document's page format to PAGES or PAGELESS.
1131
+
1132
+ PAGELESS mode removes page breaks for continuous scrolling.
1133
+ Note: Headers, footers, and page numbers are hidden in pageless mode.
1134
+ """
1135
+ service = DocsService()
1136
+ service.set_page_format(document_id=document_id, mode=mode)
1137
+
1138
+
1139
+ # =============================================================================
1140
+ # NAMED RANGE COMMANDS (Phase 7)
1141
+ # =============================================================================
1142
+
1143
+
1144
+ @app.command("create-named-range")
1145
+ def create_named_range(
1146
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
1147
+ name: Annotated[str, typer.Argument(help="Name for the range (must be unique).")],
1148
+ start_index: Annotated[int, typer.Argument(help="Start character index.")],
1149
+ end_index: Annotated[int, typer.Argument(help="End character index.")],
1150
+ ) -> None:
1151
+ """Create a named range (bookmark) in the document."""
1152
+ service = DocsService()
1153
+ service.create_named_range(
1154
+ document_id=document_id,
1155
+ name=name,
1156
+ start_index=start_index,
1157
+ end_index=end_index,
1158
+ )
1159
+
1160
+
1161
+ @app.command("delete-named-range")
1162
+ def delete_named_range(
1163
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
1164
+ name: Annotated[
1165
+ Optional[str],
1166
+ typer.Option("--name", "-n", help="Name of the range to delete."),
1167
+ ] = None,
1168
+ range_id: Annotated[
1169
+ Optional[str],
1170
+ typer.Option("--id", "-i", help="ID of the range to delete."),
1171
+ ] = None,
1172
+ ) -> None:
1173
+ """Delete a named range by name or ID."""
1174
+ service = DocsService()
1175
+ service.delete_named_range(
1176
+ document_id=document_id,
1177
+ name=name,
1178
+ named_range_id=range_id,
1179
+ )
1180
+
1181
+
1182
+ @app.command("list-named-ranges")
1183
+ def list_named_ranges(
1184
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
1185
+ ) -> None:
1186
+ """List all named ranges (bookmarks) in the document."""
1187
+ service = DocsService()
1188
+ service.list_named_ranges(document_id=document_id)
1189
+
1190
+
1191
+ # =============================================================================
1192
+ # FOOTNOTE COMMANDS (Phase 7)
1193
+ # =============================================================================
1194
+
1195
+
1196
+ @app.command("insert-footnote")
1197
+ def insert_footnote(
1198
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
1199
+ index: Annotated[int, typer.Argument(help="Character index to insert footnote reference.")],
1200
+ ) -> None:
1201
+ """Insert a footnote reference at the specified index.
1202
+
1203
+ After creation, use insert-segment-text with the footnote ID to add footnote content.
1204
+ """
1205
+ service = DocsService()
1206
+ service.insert_footnote(document_id=document_id, index=index)
1207
+
1208
+
1209
+ @app.command("list-footnotes")
1210
+ def list_footnotes(
1211
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
1212
+ ) -> None:
1213
+ """List all footnotes in the document."""
1214
+ service = DocsService()
1215
+ service.list_footnotes(document_id=document_id)
1216
+
1217
+
1218
+ # =============================================================================
1219
+ # SUGGESTION COMMANDS (Phase 8)
1220
+ # =============================================================================
1221
+
1222
+
1223
+ @app.command("suggestions")
1224
+ def get_suggestions(
1225
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
1226
+ ) -> None:
1227
+ """Get all pending suggestions (tracked changes) in the document.
1228
+
1229
+ Returns suggestions including insertions, deletions, and style changes
1230
+ made while in "Suggesting" mode in Google Docs. Use the suggestion_id
1231
+ with accept-suggestion or reject-suggestion commands.
1232
+ """
1233
+ service = DocsService()
1234
+ service.get_suggestions(document_id=document_id)
1235
+
1236
+
1237
+ @app.command("document-mode")
1238
+ def get_document_mode(
1239
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
1240
+ ) -> None:
1241
+ """Check if document has pending suggestions.
1242
+
1243
+ Returns information about whether the document has pending tracked changes
1244
+ and a count of unique suggestions.
1245
+ """
1246
+ service = DocsService()
1247
+ service.get_document_mode(document_id=document_id)
1248
+
1249
+
1250
+ @app.command("accept-suggestion")
1251
+ def accept_suggestion(
1252
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
1253
+ suggestion_id: Annotated[str, typer.Argument(help="Suggestion ID to accept.")],
1254
+ ) -> None:
1255
+ """Accept a suggestion (tracked change) in the document.
1256
+
1257
+ The suggestion_id can be obtained from the 'suggestions' command.
1258
+ """
1259
+ service = DocsService()
1260
+ service.accept_suggestion(document_id=document_id, suggestion_id=suggestion_id)
1261
+
1262
+
1263
+ @app.command("reject-suggestion")
1264
+ def reject_suggestion(
1265
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
1266
+ suggestion_id: Annotated[str, typer.Argument(help="Suggestion ID to reject.")],
1267
+ ) -> None:
1268
+ """Reject a suggestion (tracked change) in the document.
1269
+
1270
+ The suggestion_id can be obtained from the 'suggestions' command.
1271
+ """
1272
+ service = DocsService()
1273
+ service.reject_suggestion(document_id=document_id, suggestion_id=suggestion_id)
1274
+
1275
+
1276
+ @app.command("accept-all-suggestions")
1277
+ def accept_all_suggestions(
1278
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
1279
+ ) -> None:
1280
+ """Accept all pending suggestions in the document."""
1281
+ service = DocsService()
1282
+ service.accept_all_suggestions(document_id=document_id)
1283
+
1284
+
1285
+ @app.command("reject-all-suggestions")
1286
+ def reject_all_suggestions(
1287
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
1288
+ ) -> None:
1289
+ """Reject all pending suggestions in the document."""
1290
+ service = DocsService()
1291
+ service.reject_all_suggestions(document_id=document_id)
1292
+
1293
+
1294
+ @app.command("find-text")
1295
+ def find_text(
1296
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
1297
+ search_text: Annotated[str, typer.Argument(help="Text to search for.")],
1298
+ tab_id: Annotated[
1299
+ Optional[str],
1300
+ typer.Option("--tab", "-t", help="Tab ID to search in."),
1301
+ ] = None,
1302
+ occurrence: Annotated[
1303
+ int,
1304
+ typer.Option("--occurrence", "-n", help="Which occurrence (1-based)."),
1305
+ ] = 1,
1306
+ ) -> None:
1307
+ """Find text in document and return its position.
1308
+
1309
+ Returns the character index where the text starts, useful for
1310
+ precise insertions. Use --occurrence to target specific matches.
1311
+
1312
+ Example: uv run gws-cli docs find-text DOC_ID "Section Title"
1313
+ """
1314
+ service = DocsService()
1315
+ service.find_text(
1316
+ document_id=document_id,
1317
+ search_text=search_text,
1318
+ tab_id=tab_id,
1319
+ occurrence=occurrence,
1320
+ )
1321
+
1322
+
1323
+ @app.command("insert-image-at-text")
1324
+ def insert_image_at_text(
1325
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
1326
+ image_url: Annotated[str, typer.Argument(help="URL of image to insert.")],
1327
+ after_text: Annotated[str, typer.Argument(help="Insert image after this text.")],
1328
+ width: Annotated[
1329
+ Optional[float],
1330
+ typer.Option("--width", "-w", help="Image width in points."),
1331
+ ] = None,
1332
+ height: Annotated[
1333
+ Optional[float],
1334
+ typer.Option("--height", "-h", help="Image height in points."),
1335
+ ] = None,
1336
+ tab_id: Annotated[
1337
+ Optional[str],
1338
+ typer.Option("--tab", "-t", help="Tab ID."),
1339
+ ] = None,
1340
+ occurrence: Annotated[
1341
+ int,
1342
+ typer.Option("--occurrence", "-n", help="After which occurrence (1-based)."),
1343
+ ] = 1,
1344
+ ) -> None:
1345
+ """Insert an image after specified text.
1346
+
1347
+ This finds the specified text and inserts the image immediately
1348
+ after it, avoiding manual index calculation and paragraph
1349
+ boundary issues.
1350
+
1351
+ Example: uv run gws-cli docs insert-image-at-text DOC_ID "https://..." "Section Title"
1352
+ """
1353
+ service = DocsService()
1354
+ service.insert_image_at_text(
1355
+ document_id=document_id,
1356
+ image_url=image_url,
1357
+ after_text=after_text,
1358
+ width=width,
1359
+ height=height,
1360
+ tab_id=tab_id,
1361
+ occurrence=occurrence,
1362
+ )
1363
+
1364
+
1365
+ # ===== Named Range Content =====
1366
+
1367
+
1368
+ @app.command("replace-named-range")
1369
+ def replace_named_range_content(
1370
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
1371
+ text: Annotated[str, typer.Argument(help="New text to insert.")],
1372
+ name: Annotated[
1373
+ Optional[str],
1374
+ typer.Option("--name", "-n", help="Named range name."),
1375
+ ] = None,
1376
+ range_id: Annotated[
1377
+ Optional[str],
1378
+ typer.Option("--id", "-i", help="Named range ID."),
1379
+ ] = None,
1380
+ ) -> None:
1381
+ """Replace content within a named range."""
1382
+ service = DocsService()
1383
+ service.replace_named_range_content(
1384
+ document_id=document_id,
1385
+ text=text,
1386
+ named_range_name=name,
1387
+ named_range_id=range_id,
1388
+ )
1389
+
1390
+
1391
+ # ===== Image Replacement =====
1392
+
1393
+
1394
+ @app.command("replace-image")
1395
+ def replace_image(
1396
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
1397
+ image_object_id: Annotated[str, typer.Argument(help="Object ID of the image to replace.")],
1398
+ uri: Annotated[str, typer.Argument(help="URL of the new image.")],
1399
+ replace_method: Annotated[
1400
+ str,
1401
+ typer.Option("--method", "-m", help="Replacement method (CENTER_CROP)."),
1402
+ ] = "CENTER_CROP",
1403
+ ) -> None:
1404
+ """Replace an existing image with a new one."""
1405
+ service = DocsService()
1406
+ service.replace_image(
1407
+ document_id=document_id,
1408
+ image_object_id=image_object_id,
1409
+ uri=uri,
1410
+ image_replace_method=replace_method,
1411
+ )
1412
+
1413
+
1414
+ # ===== Positioned Objects =====
1415
+
1416
+
1417
+ @app.command("delete-positioned-object")
1418
+ def delete_positioned_object(
1419
+ document_id: Annotated[str, typer.Argument(help="Document ID.")],
1420
+ object_id: Annotated[str, typer.Argument(help="Positioned object ID to delete.")],
1421
+ tab_id: Annotated[
1422
+ Optional[str],
1423
+ typer.Option("--tab", "-t", help="Tab ID."),
1424
+ ] = None,
1425
+ ) -> None:
1426
+ """Delete a positioned object (floating image, drawing, etc.)."""
1427
+ service = DocsService()
1428
+ service.delete_positioned_object(
1429
+ document_id=document_id,
1430
+ object_id=object_id,
1431
+ tab_id=tab_id,
1432
+ )