-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy paththings.py
More file actions
646 lines (556 loc) · 25.4 KB
/
things.py
File metadata and controls
646 lines (556 loc) · 25.4 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
#!/usr/bin/env python3
"""
Things CLI - Command-line interface for Things 3 using the Things URL scheme
"""
import os
import sys
import json
import subprocess
from urllib.parse import quote, urlencode
from typing import Optional, List, Dict, Any
from datetime import datetime
from enum import Enum
import typer
from rich.console import Console
from rich.table import Table
from rich import print as rprint
app = typer.Typer(
help="Command-line interface for Things 3",
no_args_is_help=True,
)
console = Console()
# ============================================================================
# Enums for parameter validation
# ============================================================================
class When(str, Enum):
"""Valid values for 'when' parameter"""
today = "today"
tomorrow = "tomorrow"
evening = "evening"
anytime = "anytime"
someday = "someday"
class BuiltInList(str, Enum):
"""Built-in list IDs for show command"""
inbox = "inbox"
today = "today"
anytime = "anytime"
upcoming = "upcoming"
someday = "someday"
logbook = "logbook"
tomorrow = "tomorrow"
deadlines = "deadlines"
repeating = "repeating"
all_projects = "all-projects"
logged_projects = "logged-projects"
# ============================================================================
# Helper functions
# ============================================================================
def get_auth_token() -> Optional[str]:
"""Get auth token from environment variable"""
token = os.environ.get("THINGS_TOKEN")
if not token:
console.print("[yellow]Warning: THINGS_TOKEN environment variable not set[/yellow]")
console.print("[yellow]Commands requiring authentication will fail[/yellow]")
return token
def build_url(command: str, params: Dict[str, Any]) -> str:
"""
Build a Things URL with proper encoding
Args:
command: The Things command (add, update, show, etc.)
params: Dictionary of parameters
Returns:
Properly encoded Things URL
"""
# Filter out None values
params = {k: v for k, v in params.items() if v is not None}
# Handle special encoding for certain parameters
encoded_params = {}
for key, value in params.items():
if isinstance(value, bool):
encoded_params[key] = str(value).lower()
elif hasattr(value, '__iter__') and not isinstance(value, str):
# Join lists/iterables with newlines (encoded as %0a)
encoded_params[key] = "\n".join(str(v) for v in value)
else:
encoded_params[key] = str(value)
# Build URL
if encoded_params:
# Use quote_via to ensure spaces are encoded as %20, not +
query_string = urlencode(encoded_params, safe='', quote_via=quote)
url = f"things:///{command}?{query_string}"
else:
url = f"things:///{command}"
return url
def execute_url(url: str, dry_run: bool = False) -> None:
"""
Execute a Things URL by opening it
Args:
url: The Things URL to execute
dry_run: If True, just print the URL without executing
"""
if dry_run:
console.print(f"[cyan]Would execute:[/cyan] {url}")
return
try:
# Use 'open' command on macOS to open the URL
subprocess.run(["open", url], check=True)
console.print("[green]✓ Command sent to Things[/green]")
except subprocess.CalledProcessError as e:
console.print(f"[red]Error executing command: {e}[/red]")
raise typer.Exit(1)
except FileNotFoundError:
console.print("[red]Error: 'open' command not found. Are you on macOS?[/red]")
raise typer.Exit(1)
def parse_date(date_str: str) -> str:
"""
Parse and validate date string
Accepts: yyyy-mm-dd, natural language, or datetime formats
"""
# For now, just return as-is. Things accepts various formats.
# Could add validation here if needed
return date_str
def split_items(items: Optional[str]) -> Optional[List[str]]:
"""Split comma or newline separated items into a list"""
if not items:
return None
# Split by newlines or commas
items_list = [item.strip() for item in items.replace(',', '\n').split('\n')]
return [item for item in items_list if item] # Filter empty strings
# ============================================================================
# Main Commands
# ============================================================================
@app.command()
def add(
title: str = typer.Option(..., "--title", "-t", help="Title of the task"),
notes: Optional[str] = typer.Option(None, "--notes", "-n", help="Notes (max 10,000 chars)"),
when: Optional[When] = typer.Option(None, "--when", "-w", help="When to schedule the task"),
when_date: Optional[str] = typer.Option(None, "--when-date", help="Custom date (yyyy-mm-dd)"),
deadline: Optional[str] = typer.Option(None, "--deadline", "-d", help="Deadline date"),
tags: Optional[str] = typer.Option(None, "--tags", help="Comma-separated tags"),
checklist: Optional[str] = typer.Option(None, "--checklist", "-c", help="Comma-separated checklist items"),
list_name: Optional[str] = typer.Option(None, "--list", "-l", help="Project or area name"),
list_id: Optional[str] = typer.Option(None, "--list-id", help="Project or area ID"),
heading: Optional[str] = typer.Option(None, "--heading", help="Heading name within project"),
heading_id: Optional[str] = typer.Option(None, "--heading-id", help="Heading ID within project"),
completed: bool = typer.Option(False, "--completed", help="Mark as completed"),
canceled: bool = typer.Option(False, "--canceled", help="Mark as canceled"),
reveal: bool = typer.Option(False, "--reveal", "-r", help="Show the task after creation"),
creation_date: Optional[str] = typer.Option(None, "--creation-date", help="Creation date (ISO8601)"),
completion_date: Optional[str] = typer.Option(None, "--completion-date", help="Completion date (ISO8601)"),
dry_run: bool = typer.Option(False, "--dry-run", help="Show URL without executing"),
):
"""Create a new task in Things"""
params = {
"title": title,
"notes": notes,
"when": when.value if when else when_date,
"deadline": deadline,
"tags": tags,
"checklist-items": "\n".join(split_items(checklist)) if checklist else None,
"list": list_name,
"list-id": list_id,
"heading": heading,
"heading-id": heading_id,
"completed": completed if completed else None,
"canceled": canceled if canceled else None,
"reveal": reveal if reveal else None,
"creation-date": creation_date,
"completion-date": completion_date,
}
url = build_url("add", params)
execute_url(url, dry_run)
@app.command("add-project")
def add_project(
title: str = typer.Option(..., "--title", "-t", help="Title of the project"),
notes: Optional[str] = typer.Option(None, "--notes", "-n", help="Notes"),
when: Optional[When] = typer.Option(None, "--when", "-w", help="When to schedule"),
when_date: Optional[str] = typer.Option(None, "--when-date", help="Custom date (yyyy-mm-dd)"),
deadline: Optional[str] = typer.Option(None, "--deadline", "-d", help="Deadline date"),
tags: Optional[str] = typer.Option(None, "--tags", help="Comma-separated tags"),
area: Optional[str] = typer.Option(None, "--area", "-a", help="Area name"),
area_id: Optional[str] = typer.Option(None, "--area-id", help="Area ID"),
todos: Optional[str] = typer.Option(None, "--todos", help="Comma-separated todo items"),
completed: bool = typer.Option(False, "--completed", help="Mark as completed"),
canceled: bool = typer.Option(False, "--canceled", help="Mark as canceled"),
reveal: bool = typer.Option(False, "--reveal", "-r", help="Show the project after creation"),
creation_date: Optional[str] = typer.Option(None, "--creation-date", help="Creation date (ISO8601)"),
completion_date: Optional[str] = typer.Option(None, "--completion-date", help="Completion date (ISO8601)"),
dry_run: bool = typer.Option(False, "--dry-run", help="Show URL without executing"),
):
"""Create a new project in Things"""
params = {
"title": title,
"notes": notes,
"when": when.value if when else when_date,
"deadline": deadline,
"tags": tags,
"area": area,
"area-id": area_id,
"to-dos": "\n".join(split_items(todos)) if todos else None,
"completed": completed if completed else None,
"canceled": canceled if canceled else None,
"reveal": reveal if reveal else None,
"creation-date": creation_date,
"completion-date": completion_date,
}
url = build_url("add-project", params)
execute_url(url, dry_run)
@app.command()
def update(
task_id: str = typer.Option(..., "--id", help="Task ID (UUID)"),
title: Optional[str] = typer.Option(None, "--title", "-t", help="New title"),
notes: Optional[str] = typer.Option(None, "--notes", "-n", help="Replace notes"),
prepend_notes: Optional[str] = typer.Option(None, "--prepend-notes", help="Prepend to notes"),
append_notes: Optional[str] = typer.Option(None, "--append-notes", help="Append to notes"),
when: Optional[When] = typer.Option(None, "--when", "-w", help="When to schedule"),
when_date: Optional[str] = typer.Option(None, "--when-date", help="Custom date (yyyy-mm-dd)"),
deadline: Optional[str] = typer.Option(None, "--deadline", "-d", help="Deadline (empty string to clear)"),
tags: Optional[str] = typer.Option(None, "--tags", help="Replace tags (comma-separated)"),
add_tags: Optional[str] = typer.Option(None, "--add-tags", help="Add tags (comma-separated)"),
checklist: Optional[str] = typer.Option(None, "--checklist", help="Replace checklist items"),
prepend_checklist: Optional[str] = typer.Option(None, "--prepend-checklist", help="Prepend checklist items"),
append_checklist: Optional[str] = typer.Option(None, "--append-checklist", help="Append checklist items"),
list_name: Optional[str] = typer.Option(None, "--list", help="Move to project/area"),
list_id: Optional[str] = typer.Option(None, "--list-id", help="Move to project/area ID"),
heading: Optional[str] = typer.Option(None, "--heading", help="Move to heading"),
heading_id: Optional[str] = typer.Option(None, "--heading-id", help="Move to heading ID"),
completed: bool = typer.Option(False, "--completed", help="Mark as completed"),
canceled: bool = typer.Option(False, "--canceled", help="Mark as canceled"),
duplicate: bool = typer.Option(False, "--duplicate", help="Duplicate before updating"),
reveal: bool = typer.Option(False, "--reveal", "-r", help="Show the task after update"),
creation_date: Optional[str] = typer.Option(None, "--creation-date", help="Creation date (ISO8601)"),
completion_date: Optional[str] = typer.Option(None, "--completion-date", help="Completion date (ISO8601)"),
dry_run: bool = typer.Option(False, "--dry-run", help="Show URL without executing"),
):
"""Update an existing task in Things (requires auth token)"""
auth_token = get_auth_token()
if not auth_token and not dry_run:
console.print("[red]Error: THINGS_TOKEN environment variable required for update command[/red]")
raise typer.Exit(1)
params = {
"id": task_id,
"auth-token": auth_token,
"title": title,
"notes": notes,
"prepend-notes": prepend_notes,
"append-notes": append_notes,
"when": when.value if when else when_date,
"deadline": deadline,
"tags": tags,
"add-tags": add_tags,
"checklist-items": "\n".join(split_items(checklist)) if checklist else None,
"prepend-checklist-items": "\n".join(split_items(prepend_checklist)) if prepend_checklist else None,
"append-checklist-items": "\n".join(split_items(append_checklist)) if append_checklist else None,
"list": list_name,
"list-id": list_id,
"heading": heading,
"heading-id": heading_id,
"completed": completed if completed else None,
"canceled": canceled if canceled else None,
"duplicate": duplicate if duplicate else None,
"reveal": reveal if reveal else None,
"creation-date": creation_date,
"completion-date": completion_date,
}
url = build_url("update", params)
execute_url(url, dry_run)
@app.command("update-project")
def update_project(
project_id: str = typer.Option(..., "--id", help="Project ID (UUID)"),
title: Optional[str] = typer.Option(None, "--title", "-t", help="New title"),
notes: Optional[str] = typer.Option(None, "--notes", "-n", help="Replace notes"),
prepend_notes: Optional[str] = typer.Option(None, "--prepend-notes", help="Prepend to notes"),
append_notes: Optional[str] = typer.Option(None, "--append-notes", help="Append to notes"),
when: Optional[When] = typer.Option(None, "--when", "-w", help="When to schedule"),
when_date: Optional[str] = typer.Option(None, "--when-date", help="Custom date (yyyy-mm-dd)"),
deadline: Optional[str] = typer.Option(None, "--deadline", "-d", help="Deadline"),
tags: Optional[str] = typer.Option(None, "--tags", help="Replace tags (comma-separated)"),
add_tags: Optional[str] = typer.Option(None, "--add-tags", help="Add tags (comma-separated)"),
area: Optional[str] = typer.Option(None, "--area", help="Move to area"),
area_id: Optional[str] = typer.Option(None, "--area-id", help="Move to area ID"),
completed: bool = typer.Option(False, "--completed", help="Mark as completed"),
canceled: bool = typer.Option(False, "--canceled", help="Mark as canceled"),
duplicate: bool = typer.Option(False, "--duplicate", help="Duplicate before updating"),
reveal: bool = typer.Option(False, "--reveal", "-r", help="Show the project after update"),
creation_date: Optional[str] = typer.Option(None, "--creation-date", help="Creation date (ISO8601)"),
completion_date: Optional[str] = typer.Option(None, "--completion-date", help="Completion date (ISO8601)"),
dry_run: bool = typer.Option(False, "--dry-run", help="Show URL without executing"),
):
"""Update an existing project in Things (requires auth token)"""
auth_token = get_auth_token()
if not auth_token and not dry_run:
console.print("[red]Error: THINGS_TOKEN environment variable required for update-project command[/red]")
raise typer.Exit(1)
params = {
"id": project_id,
"auth-token": auth_token,
"title": title,
"notes": notes,
"prepend-notes": prepend_notes,
"append-notes": append_notes,
"when": when.value if when else when_date,
"deadline": deadline,
"tags": tags,
"add-tags": add_tags,
"area": area,
"area-id": area_id,
"completed": completed if completed else None,
"canceled": canceled if canceled else None,
"duplicate": duplicate if duplicate else None,
"reveal": reveal if reveal else None,
"creation-date": creation_date,
"completion-date": completion_date,
}
url = build_url("update-project", params)
execute_url(url, dry_run)
@app.command()
def show(
list_id: Optional[BuiltInList] = typer.Option(None, "--id", help="Built-in list ID"),
custom_id: Optional[str] = typer.Option(None, "--custom-id", help="Custom item/project/area/tag ID"),
query: Optional[str] = typer.Option(None, "--query", "-q", help="Search by name (quick find)"),
filter_tags: Optional[str] = typer.Option(None, "--filter", "-f", help="Filter by tags (comma-separated)"),
dry_run: bool = typer.Option(False, "--dry-run", help="Show URL without executing"),
):
"""Navigate to a specific view in Things"""
# Determine which ID to use
item_id = None
if list_id:
item_id = list_id.value
elif custom_id:
item_id = custom_id
params = {
"id": item_id,
"query": query,
"filter": filter_tags,
}
url = build_url("show", params)
execute_url(url, dry_run)
@app.command()
def search(
query: Optional[str] = typer.Option(None, "--query", "-q", help="Search query"),
dry_run: bool = typer.Option(False, "--dry-run", help="Show URL without executing"),
):
"""Open Things search interface with optional pre-filled query"""
params = {
"query": query,
}
url = build_url("search", params)
execute_url(url, dry_run)
@app.command()
def version(
dry_run: bool = typer.Option(False, "--dry-run", help="Show URL without executing"),
):
"""Check Things version information"""
url = build_url("version", {})
execute_url(url, dry_run)
console.print("[yellow]Note: Version info will be shown in Things app[/yellow]")
@app.command()
def json_command(
data: Optional[str] = typer.Option(None, "--data", "-d", help="JSON array as string"),
file: Optional[str] = typer.Option(None, "--file", "-f", help="Path to JSON file"),
reveal: bool = typer.Option(False, "--reveal", "-r", help="Show items after creation"),
dry_run: bool = typer.Option(False, "--dry-run", help="Show URL without executing"),
):
"""Execute a JSON-based command for batch operations (requires auth token)"""
auth_token = get_auth_token()
if not auth_token and not dry_run:
console.print("[red]Error: THINGS_TOKEN environment variable required for json command[/red]")
raise typer.Exit(1)
# Load JSON data
json_data = None
if file:
try:
with open(file, 'r') as f:
json_data = json.load(f)
except FileNotFoundError:
console.print(f"[red]Error: File not found: {file}[/red]")
raise typer.Exit(1)
except json.JSONDecodeError as e:
console.print(f"[red]Error parsing JSON file: {e}[/red]")
raise typer.Exit(1)
elif data:
try:
json_data = json.loads(data)
except json.JSONDecodeError as e:
console.print(f"[red]Error parsing JSON data: {e}[/red]")
raise typer.Exit(1)
else:
console.print("[red]Error: Either --data or --file must be provided[/red]")
raise typer.Exit(1)
# Validate it's a list
if not isinstance(json_data, list):
console.print("[red]Error: JSON data must be an array[/red]")
raise typer.Exit(1)
# Check rate limit (max 250 items)
if len(json_data) > 250:
console.print("[red]Error: Maximum 250 items allowed per request[/red]")
raise typer.Exit(1)
params = {
"data": json.dumps(json_data),
"auth-token": auth_token,
"reveal": reveal if reveal else None,
}
url = build_url("json", params)
execute_url(url, dry_run)
# ============================================================================
# Import/Export Commands
# ============================================================================
@app.command("import")
def import_json(
file: str = typer.Argument(..., help="Path to JSON file to import"),
reveal: bool = typer.Option(False, "--reveal", "-r", help="Show items after import"),
dry_run: bool = typer.Option(False, "--dry-run", help="Show URL without executing"),
):
"""Import tasks and projects from a JSON file"""
# This is essentially an alias for json-command with --file
json_command(data=None, file=file, reveal=reveal, dry_run=dry_run)
@app.command("export")
def export_template(
output: str = typer.Argument(..., help="Output file path"),
template_type: str = typer.Option("task", "--type", "-t", help="Template type: task, project, or batch"),
):
"""Export a JSON template for creating tasks/projects"""
templates = {
"task": [
{
"type": "to-do",
"attributes": {
"title": "Example Task",
"notes": "Task notes here",
"when": "today",
"tags": ["existing-tag1", "existing-tag2"],
"checklist-items": [
{"type": "checklist-item", "attributes": {"title": "Subtask 1"}},
{"type": "checklist-item", "attributes": {"title": "Subtask 2"}}
]
}
}
],
"project": [
{
"type": "project",
"attributes": {
"title": "Example Project",
"notes": "Project notes",
"tags": ["existing-tag"],
"items": [
{"type": "to-do", "attributes": {"title": "First task"}},
{"type": "heading", "attributes": {"title": "Section 1"}},
{"type": "to-do", "attributes": {"title": "Task in section"}},
]
}
}
],
"batch": [
{
"type": "to-do",
"attributes": {
"title": "Task 1",
"when": "today"
}
},
{
"type": "to-do",
"attributes": {
"title": "Task 2",
"when": "tomorrow"
}
},
{
"type": "project",
"attributes": {
"title": "Project with tasks",
"items": [
{"type": "to-do", "attributes": {"title": "Subtask 1"}},
{"type": "to-do", "attributes": {"title": "Subtask 2"}}
]
}
}
]
}
if template_type not in templates:
console.print(f"[red]Error: Unknown template type '{template_type}'[/red]")
console.print(f"[yellow]Available types: {', '.join(templates.keys())}[/yellow]")
raise typer.Exit(1)
try:
with open(output, 'w') as f:
json.dump(templates[template_type], f, indent=2)
console.print(f"[green]✓ Template exported to {output}[/green]")
except IOError as e:
console.print(f"[red]Error writing file: {e}[/red]")
raise typer.Exit(1)
# ============================================================================
# Read/List Commands (via JXA)
# ============================================================================
try:
import things_jxa
JXA_AVAILABLE = True
except ImportError:
JXA_AVAILABLE = False
@app.command()
def list(
view: Optional[str] = typer.Argument(None, help="List view: today, inbox, upcoming, anytime, someday, logbook, tags, areas, projects"),
tag: Optional[str] = typer.Option(None, "--tag", help="Filter by tag"),
area: Optional[str] = typer.Option(None, "--area", help="Filter by area"),
project: Optional[str] = typer.Option(None, "--project", help="Filter by project"),
locale: Optional[str] = typer.Option(None, "--locale", help="Locale code (e.g., 'de', 'en') or 'auto' for auto-detection. Default: auto"),
):
"""List tasks and metadata from Things 3 (read-only, requires JXA)"""
if not JXA_AVAILABLE:
console.print("[red]Error: things_jxa module not found[/red]")
console.print("[yellow]The list command requires the things_jxa.py module[/yellow]")
raise typer.Exit(1)
try:
# Metadata queries
if view == "tags":
tags = things_jxa.get_all_tags()
print(json.dumps(tags, indent=2, ensure_ascii=False))
return
if view == "areas":
areas = things_jxa.get_all_areas()
print(json.dumps(areas, indent=2, ensure_ascii=False))
return
if view == "projects":
projects = things_jxa.get_all_projects()
print(json.dumps(projects, indent=2, ensure_ascii=False))
return
# Task queries
tasks = []
if view and view in ["today", "inbox", "upcoming", "anytime", "someday", "logbook", "tomorrow"]:
# Built-in list view
tasks = things_jxa.get_list_tasks(view, locale=locale)
elif tag:
# Filter by tag
tasks = things_jxa.get_tasks_by_tag(tag)
elif area:
# Filter by area
tasks = things_jxa.get_tasks_by_area(area)
elif project:
# Filter by project
tasks = things_jxa.get_tasks_by_project(project)
else:
# No filter specified - show help
console.print("[yellow]Please specify a view or filter:[/yellow]")
console.print(" Views: today, inbox, upcoming, anytime, someday, logbook")
console.print(" Metadata: tags, areas, projects")
console.print(" Filters: --tag, --area, --project")
console.print(" Options: --locale [de|en|auto]")
console.print("\nExamples:")
console.print(" things list today")
console.print(" things list today --locale en")
console.print(" things list --tag work")
console.print(" things list --area Personal")
raise typer.Exit(1)
# Output as JSON
print(json.dumps(tasks, indent=2, ensure_ascii=False))
except RuntimeError as e:
console.print(f"[red]Error: {e}[/red]")
raise typer.Exit(1)
except Exception as e:
console.print(f"[red]Unexpected error: {e}[/red]")
raise typer.Exit(1)
# ============================================================================
# Entry point
# ============================================================================
if __name__ == "__main__":
app()