-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcourses.py
More file actions
59 lines (44 loc) · 1.44 KB
/
courses.py
File metadata and controls
59 lines (44 loc) · 1.44 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
"""Course commands — search, get, list."""
from __future__ import annotations
import cyclopts
from talk_python_cli.formatting import display
courses_app = cyclopts.App(
name='courses',
help='Browse and search Talk Python Training courses.',
)
def _client():
from talk_python_cli.app import get_client
return get_client()
@courses_app.command
def search(query: str, *, course_id: int | None = None) -> None:
"""Search courses, chapters, and lectures by keyword.
Parameters
----------
query
Keywords for course, chapter, or lecture titles.
course_id
Limit search to a specific course (optional).
"""
client = _client()
args: dict = {'query': query}
if course_id is not None:
args['course_id'] = course_id
content = client.call_tool('search_courses', args)
display(content, client.output_format)
@courses_app.command
def get(course_id: int) -> None:
"""Get full details for a course by ID, including chapters and lectures.
Parameters
----------
course_id
The course ID.
"""
client = _client()
content = client.call_tool('get_course_details', {'course_id': course_id})
display(content, client.output_format)
@courses_app.command(name='list')
def list_courses() -> None:
"""List all available Talk Python Training courses."""
client = _client()
content = client.call_tool('get_courses')
display(content, client.output_format)