trello-board-cli 0.2.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,117 @@
1
+ Metadata-Version: 2.4
2
+ Name: trello-board-cli
3
+ Version: 0.2.0
4
+ Summary: LLM-friendly command-line interface for Trello.
5
+ Author-email: tranch <tranch.xiao@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/tranch/trello-cli
8
+ Project-URL: Issues, https://github.com/tranch/trello-cli/issues
9
+ Keywords: trello,cli,llm,automation
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Programming Language :: Python :: 3.15
19
+ Classifier: Topic :: Utilities
20
+ Requires-Python: >=3.11
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: requests>=2.31
24
+ Requires-Dist: typer>=0.12
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest>=8; extra == "dev"
27
+ Dynamic: license-file
28
+
29
+ # trello-cli
30
+
31
+ LLM-friendly command-line interface for Trello.
32
+
33
+ All commands write JSON to stdout. Errors are written to stderr and exit with
34
+ code 1.
35
+
36
+ ## Install from PyPI
37
+
38
+ The PyPI distribution is named `trello-board-cli` because the `trello-cli`
39
+ distribution name is already taken. The installed command remains `trello-cli`:
40
+
41
+ ```bash
42
+ pipx install trello-board-cli
43
+ ```
44
+
45
+ ## Install for local development
46
+
47
+ ```bash
48
+ cd ~/Workspace/trello-cli
49
+ python3 -m venv .venv
50
+ . .venv/bin/activate
51
+ pip install -e ".[dev]"
52
+ ```
53
+
54
+ This installs a `trello-cli` executable into the active environment. To deploy
55
+ it onto your normal `$PATH`, install it with the Python used by that path, or
56
+ use `pipx`:
57
+
58
+ ```bash
59
+ pipx install -e ~/Workspace/trello-cli
60
+ ```
61
+
62
+ ## Credentials
63
+
64
+ Credential loading priority:
65
+
66
+ 1. `TRELLO_API_KEY` and `TRELLO_TOKEN`
67
+ 2. `~/.config/trello-cli/config.toml`
68
+
69
+ Run:
70
+
71
+ ```bash
72
+ trello-cli auth
73
+ ```
74
+
75
+ ## Commands
76
+
77
+ ```bash
78
+ trello-cli list-boards
79
+ trello-cli whoami
80
+ trello-cli list-lists --board-id <id>
81
+ trello-cli list-cards --list-id <id>
82
+ trello-cli get-card --card-id <id>
83
+ trello-cli get-card --card-id <id> --format markdown
84
+ trello-cli get-card --short-id 413
85
+ trello-cli get-card --short-id 413 --card-filter all
86
+ trello-cli create-card --list-id <id> --name "Task title" --desc "Details"
87
+ trello-cli create-card --list-id <id> --name "Task title" --text-file notes.md
88
+ trello-cli update-card --card-id <id> --name "New title"
89
+ trello-cli update-card --card-id <id> --due 2025-12-31T09:00:00.000Z
90
+ trello-cli update-card --card-id <id> --closed
91
+ trello-cli add-comment --card-id <id> --text "Comment text"
92
+ trello-cli add-comment --card-id <id> --text-file comment.md
93
+ trello-cli add-comment --short-id 413 --text "Comment text"
94
+ trello-cli add-comment --short-id 413 --card-filter all --text "Comment text"
95
+ trello-cli list-comments --card-id <id>
96
+ trello-cli create-checklist --card-id <id> --name "Checklist"
97
+ trello-cli create-checklist --card-id <id> --name "Todos" --items-file /path/to/items.md
98
+ trello-cli get-checklist --checklist-id <id>
99
+ trello-cli update-checklist --checklist-id <id> --name "Updated checklist"
100
+ trello-cli delete-checklist --checklist-id <id>
101
+ trello-cli add-checkitem --checklist-id <id> --name "Item text" --checked
102
+ trello-cli get-checkitem --card-id <id> --checkitem-id <id>
103
+ trello-cli update-checkitem --card-id <id> --checkitem-id <id> --state complete
104
+ trello-cli delete-checkitem --card-id <id> --checkitem-id <id>
105
+ trello-cli list-checklists --card-id <id>
106
+ ```
107
+
108
+ Card descriptions and comments accept Markdown. Literal `\\n`, `\\r\\n`, and
109
+ `\\r` sequences supplied by LLMs are normalized to real line breaks before the
110
+ request is sent. Use `--text-file` (or `-` for stdin) when passing
111
+ multi-line Markdown directly.
112
+
113
+ ## Agent skill
114
+
115
+ This repository includes `SKILL.md`, an agent-oriented guide for using and
116
+ maintaining `trello-cli`. Codex can install it as a skill; other agents can read
117
+ the same file as project-specific operating instructions.
@@ -0,0 +1,12 @@
1
+ trello_board_cli-0.2.0.dist-info/licenses/LICENSE,sha256=jubGyUsDc0w2GoThI4cU0HIVtvt97Y6hPWaqk7QLm3Y,1063
2
+ trello_cli/__init__.py,sha256=BMcWdL4BWJSl2kUUpsiWlZQjSOUV1TNs2BN348l36DM,49
3
+ trello_cli/__main__.py,sha256=wu5N2wk8mvBgyvr2ghmQf4prezAe0_i-p123VVreyYc,62
4
+ trello_cli/cli.py,sha256=uOnrvPdfyunJp4Bpkyw78cZ7f_1CH4541ttch6BQMS0,17061
5
+ trello_cli/client.py,sha256=QlDVtUYU7GdKNBE4k9pDYBrknAXRC-b2aFdsG6mPwgU,11408
6
+ trello_cli/config.py,sha256=Ej4k8vjrValHKPRGw4QGixcfGFo8oM8c6CMpPba7vn0,1104
7
+ trello_cli/markdown.py,sha256=SpqKFZf2_KSj3Iy6IEeBrtoXETl8EGJ1otMp_kKly-w,661
8
+ trello_board_cli-0.2.0.dist-info/METADATA,sha256=RTF7rgiJwBy6hcw9oLvzfYX4iGZ1fs6Owgm7KGYWQA4,3989
9
+ trello_board_cli-0.2.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
10
+ trello_board_cli-0.2.0.dist-info/entry_points.txt,sha256=tw_yCRm9GWL69W7RzStUQC_Bgv61LkgwofwKlEX3SuI,51
11
+ trello_board_cli-0.2.0.dist-info/top_level.txt,sha256=D3DuG7NFnq9B7uBpa5m7xtXDrB_7BPfV3M2f5oAWzjI,11
12
+ trello_board_cli-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ trello-cli = trello_cli.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 tranch
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ trello_cli
trello_cli/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ """Trello CLI package."""
2
+
3
+ __version__ = "0.1.0"
trello_cli/__main__.py ADDED
@@ -0,0 +1,5 @@
1
+ from .cli import main
2
+
3
+
4
+ if __name__ == "__main__":
5
+ main()
trello_cli/cli.py ADDED
@@ -0,0 +1,507 @@
1
+ import json
2
+ import webbrowser
3
+ from pathlib import Path
4
+
5
+ import typer
6
+
7
+ from .client import TrelloClient, TrelloError
8
+ from .config import CONFIG_PATH, load_config_file, write_config
9
+
10
+ app = typer.Typer(
11
+ help="LLM-friendly Trello CLI. All output is JSON.",
12
+ add_completion=False,
13
+ )
14
+
15
+
16
+ def main() -> None:
17
+ app()
18
+
19
+
20
+ def _print(data: object) -> None:
21
+ typer.echo(json.dumps(data, ensure_ascii=False, indent=2))
22
+
23
+
24
+ def _fail(message: str) -> None:
25
+ typer.echo(json.dumps({"error": message}, ensure_ascii=False), err=True)
26
+ raise typer.Exit(code=1)
27
+
28
+
29
+ def _client() -> TrelloClient:
30
+ try:
31
+ return TrelloClient()
32
+ except RuntimeError as exc:
33
+ _fail(str(exc))
34
+
35
+
36
+ def _read_markdown_file(path: str) -> str:
37
+ """Read Markdown from a file, or stdin when path is ``-``."""
38
+ if path == "-":
39
+ return typer.get_text_stream("stdin").read()
40
+ file_path = Path(path)
41
+ if not file_path.is_file():
42
+ _fail(f"File not found: {path}")
43
+ return file_path.read_text(encoding="utf-8")
44
+
45
+
46
+ def _resolve_board(board_id: str | None) -> str:
47
+ """Return the explicit board_id or fall back to the configured default."""
48
+ if board_id:
49
+ return board_id
50
+ cfg = load_config_file()
51
+ default = cfg.get("default_board", "")
52
+ if not default:
53
+ _fail("No board specified and no default_board configured.")
54
+ return default
55
+
56
+
57
+ def _init(
58
+ api_key: str = typer.Option(
59
+ ...,
60
+ "--api-key",
61
+ prompt="Trello API Key",
62
+ help="Your Trello Power-Up API key.",
63
+ ),
64
+ token: str = typer.Option(
65
+ ...,
66
+ "--token",
67
+ prompt="Trello Token",
68
+ hide_input=True,
69
+ help="Your Trello OAuth token.",
70
+ ),
71
+ default_board: str = typer.Option(
72
+ "",
73
+ "--default-board",
74
+ help="Default board ID to use when --board-id is omitted.",
75
+ ),
76
+ ) -> None:
77
+ """Write credentials to ~/.config/trello-cli/config.toml."""
78
+ write_config(api_key=api_key, token=token, default_board=default_board)
79
+ typer.echo(f"Config written to {CONFIG_PATH}")
80
+
81
+
82
+ @app.command("auth")
83
+ def auth(
84
+ api_key: str = typer.Option(
85
+ ...,
86
+ "--api-key",
87
+ prompt="Trello API Key",
88
+ help="Your Trello Power-Up API key.",
89
+ ),
90
+ expiration: str = typer.Option(
91
+ "never",
92
+ "--expiration",
93
+ help="Token expiration: never / 30days / 1day.",
94
+ ),
95
+ default_board: str = typer.Option(
96
+ "",
97
+ "--default-board",
98
+ help="Default board ID to use when --board-id is omitted.",
99
+ ),
100
+ ) -> None:
101
+ """Open the Trello authorization URL in your browser to obtain a token."""
102
+ url = (
103
+ "https://trello.com/1/authorize"
104
+ f"?expiration={expiration}"
105
+ "&name=trello-cli"
106
+ "&scope=read,write"
107
+ "&response_type=token"
108
+ f"&key={api_key}"
109
+ )
110
+ typer.echo(f"Opening: {url}")
111
+ webbrowser.open(url)
112
+ typer.echo("Copy the token shown in the browser")
113
+
114
+ token = typer.prompt("Trello Token", hide_input=True)
115
+
116
+ if not token:
117
+ _fail("Token is required.")
118
+
119
+ _init(api_key=api_key, token=token, default_board=default_board)
120
+
121
+
122
+ @app.command("list-boards")
123
+ def list_boards() -> None:
124
+ """List all Trello boards accessible to the authenticated user."""
125
+ try:
126
+ _print(_client().list_boards())
127
+ except TrelloError as exc:
128
+ _fail(str(exc))
129
+
130
+
131
+ @app.command("whoami")
132
+ def whoami() -> None:
133
+ """Get the Trello member represented by the configured API token."""
134
+ try:
135
+ _print(_client().get_current_user())
136
+ except TrelloError as exc:
137
+ _fail(str(exc))
138
+
139
+
140
+ @app.command("list-lists")
141
+ def list_lists(
142
+ board_id: str | None = typer.Option(None, "--board-id", help="Trello board ID."),
143
+ ) -> None:
144
+ """List all open lists (columns) in a board."""
145
+ try:
146
+ _print(_client().list_lists(board_id=_resolve_board(board_id)))
147
+ except TrelloError as exc:
148
+ _fail(str(exc))
149
+
150
+
151
+ @app.command("list-cards")
152
+ def list_cards(
153
+ list_id: str = typer.Option(..., "--list-id", help="Trello list ID."),
154
+ ) -> None:
155
+ """List all open cards in a list."""
156
+ try:
157
+ _print(_client().list_cards(list_id=list_id))
158
+ except TrelloError as exc:
159
+ _fail(str(exc))
160
+
161
+
162
+ @app.command("get-card")
163
+ def get_card(
164
+ card_id: str | None = typer.Option(None, "--card-id", help="Trello card ID."),
165
+ short_id: int | None = typer.Option(
166
+ None,
167
+ "--short-id",
168
+ min=1,
169
+ help="Board-scoped card number shown in a Trello card URL.",
170
+ ),
171
+ card_filter: str = typer.Option(
172
+ "open",
173
+ "--card-filter",
174
+ help="Cards to scan for --short-id: open, closed, or all.",
175
+ ),
176
+ output_format: str = typer.Option(
177
+ "json",
178
+ "--format",
179
+ help="Output format: json (default) or markdown (description only).",
180
+ ),
181
+ ) -> None:
182
+ """Get full details of a single card."""
183
+ try:
184
+ client = _client()
185
+ if output_format not in {"json", "markdown"}:
186
+ _fail("format must be either json or markdown.")
187
+ if card_id and short_id:
188
+ _fail("Specify either --card-id or --short-id, not both.")
189
+ if card_id:
190
+ card = client.get_card(card_id=card_id)
191
+ elif short_id:
192
+ board_id = _resolve_board(None)
193
+ card = client.get_card_by_short_id(
194
+ board_id=board_id,
195
+ short_id=short_id,
196
+ card_filter=card_filter,
197
+ )
198
+ else:
199
+ _fail("Specify either --card-id or --short-id.")
200
+ if output_format == "markdown":
201
+ typer.echo(card.get("desc", ""), nl=bool(card.get("desc", "")))
202
+ else:
203
+ _print(card)
204
+ except (TrelloError, ValueError) as exc:
205
+ _fail(str(exc))
206
+
207
+
208
+ @app.command("create-card")
209
+ def create_card(
210
+ list_id: str = typer.Option(..., "--list-id", help="Target list ID."),
211
+ name: str = typer.Option(..., "--name", help="Card title."),
212
+ desc: str = typer.Option("", "--desc", help="Card description (Markdown supported)."),
213
+ text_file: str | None = typer.Option(
214
+ None,
215
+ "--text-file",
216
+ help="Read the Markdown description from a UTF-8 file, or '-' for stdin.",
217
+ ),
218
+ due: str | None = typer.Option(
219
+ None,
220
+ "--due",
221
+ help="Due date in ISO 8601, e.g. 2025-12-31T09:00:00.000Z.",
222
+ ),
223
+ ) -> None:
224
+ """Create a new card in the specified list."""
225
+ try:
226
+ if text_file is not None and desc:
227
+ _fail("Specify either --desc or --text-file, not both.")
228
+ description = _read_markdown_file(text_file) if text_file is not None else desc
229
+ _print(_client().create_card(list_id=list_id, name=name, desc=description, due=due))
230
+ except TrelloError as exc:
231
+ _fail(str(exc))
232
+
233
+
234
+ @app.command("update-card")
235
+ def update_card(
236
+ card_id: str = typer.Option(..., "--card-id", help="Card ID to update."),
237
+ name: str | None = typer.Option(None, "--name", help="New card title."),
238
+ desc: str | None = typer.Option(None, "--desc", help="New card description."),
239
+ text_file: str | None = typer.Option(
240
+ None,
241
+ "--text-file",
242
+ help="Read the new Markdown description from a UTF-8 file, or '-' for stdin.",
243
+ ),
244
+ due: str | None = typer.Option(
245
+ None,
246
+ "--due",
247
+ help="New due date (ISO 8601), or 'null' to clear it.",
248
+ ),
249
+ closed: bool = typer.Option(False, "--closed/--open", help="Archive or unarchive the card."),
250
+ ) -> None:
251
+ """
252
+ Update one or more fields on an existing card.
253
+ Only provided flags are changed; omitted flags are left untouched.
254
+ """
255
+ resolved_due = None if due == "null" else due
256
+ resolved_closed: bool | None = closed if closed else None
257
+ try:
258
+ if text_file is not None and desc is not None:
259
+ _fail("Specify either --desc or --text-file, not both.")
260
+ description = _read_markdown_file(text_file) if text_file is not None else desc
261
+ _print(
262
+ _client().update_card(
263
+ card_id=card_id,
264
+ name=name,
265
+ desc=description,
266
+ due=resolved_due,
267
+ closed=resolved_closed,
268
+ )
269
+ )
270
+ except (TrelloError, ValueError) as exc:
271
+ _fail(str(exc))
272
+
273
+
274
+ @app.command("add-comment")
275
+ def add_comment(
276
+ text: str | None = typer.Option(None, "--text", help="Comment text (Markdown supported)."),
277
+ text_file: str | None = typer.Option(
278
+ None,
279
+ "--text-file",
280
+ help="Read Markdown comment text from a UTF-8 file, or '-' for stdin.",
281
+ ),
282
+ card_id: str | None = typer.Option(None, "--card-id", help="Trello card ID."),
283
+ short_id: int | None = typer.Option(
284
+ None,
285
+ "--short-id",
286
+ min=1,
287
+ help="Board-scoped card number shown in a Trello card URL.",
288
+ ),
289
+ card_filter: str = typer.Option(
290
+ "open",
291
+ "--card-filter",
292
+ help="Cards to scan for --short-id: open, closed, or all.",
293
+ ),
294
+ ) -> None:
295
+ """Add a comment to a card."""
296
+ try:
297
+ if text_file is not None and text is not None:
298
+ _fail("Specify either --text or --text-file, not both.")
299
+ if text_file is None and text is None:
300
+ _fail("Specify either --text or --text-file.")
301
+ comment_text = _read_markdown_file(text_file) if text_file is not None else text
302
+ client = _client()
303
+ if card_id and short_id:
304
+ _fail("Specify either --card-id or --short-id, not both.")
305
+ if short_id:
306
+ board_id = _resolve_board(None)
307
+ card_id = client.get_card_by_short_id(
308
+ board_id=board_id,
309
+ short_id=short_id,
310
+ card_filter=card_filter,
311
+ )["id"]
312
+ if not card_id:
313
+ _fail("Specify either --card-id or --short-id.")
314
+ _print(client.add_comment(card_id=card_id, text=comment_text))
315
+ except (TrelloError, ValueError) as exc:
316
+ _fail(str(exc))
317
+
318
+
319
+ @app.command("list-comments")
320
+ def list_comments(
321
+ card_id: str = typer.Option(..., "--card-id", help="Trello card ID."),
322
+ ) -> None:
323
+ """List all comments on a card."""
324
+ try:
325
+ _print(_client().list_comments(card_id=card_id))
326
+ except TrelloError as exc:
327
+ _fail(str(exc))
328
+
329
+
330
+ @app.command("create-checklist")
331
+ def create_checklist(
332
+ card_id: str = typer.Option(..., "--card-id", help="Card ID to add the checklist to."),
333
+ name: str = typer.Option(..., "--name", help="Checklist title."),
334
+ items_file: str | None = typer.Option(
335
+ None,
336
+ "--items-file",
337
+ help="Path to a markdown checklist file.",
338
+ ),
339
+ ) -> None:
340
+ """
341
+ Create a checklist on a card.
342
+
343
+ When --items-file is given, each line in the file is parsed as a checklist item.
344
+ Lines starting with '- [x]' are added as completed items; '- [ ]' as open items.
345
+ The [x]/[ ] prefix is stripped from the item name.
346
+ """
347
+ try:
348
+ client = _client()
349
+ checklist = client.create_checklist(card_id=card_id, name=name)
350
+ checklist_id = checklist["id"]
351
+
352
+ if items_file:
353
+ path = Path(items_file)
354
+ if not path.exists():
355
+ _fail(f"File not found: {items_file}")
356
+ for line in path.read_text(encoding="utf-8").splitlines():
357
+ stripped = line.strip()
358
+ if not stripped:
359
+ continue
360
+ is_checked = stripped.startswith("- [x]")
361
+ item_name = stripped[5:].strip() if stripped.startswith("- [") else stripped
362
+ item = client.add_checkitem(checklist_id=checklist_id, name=item_name)
363
+ if is_checked:
364
+ client.update_checkitem(
365
+ card_id=card_id,
366
+ checkitem_id=item["id"],
367
+ state="complete",
368
+ )
369
+ _print(client.list_checklists(card_id=card_id))
370
+ except (TrelloError, ValueError) as exc:
371
+ _fail(str(exc))
372
+
373
+
374
+ @app.command("add-checkitem")
375
+ def add_checkitem(
376
+ checklist_id: str = typer.Option(..., "--checklist-id", help="Checklist ID."),
377
+ name: str = typer.Option(..., "--name", help="Item text."),
378
+ pos: str | None = typer.Option(None, "--pos", help="Item position."),
379
+ checked: bool = typer.Option(False, "--checked", help="Create the item as completed."),
380
+ due: str | None = typer.Option(None, "--due", help="Due date in ISO 8601."),
381
+ due_reminder: int | None = typer.Option(None, "--due-reminder", help="Due reminder in minutes."),
382
+ member_id: str | None = typer.Option(None, "--member-id", help="Member ID assigned to the item."),
383
+ ) -> None:
384
+ """Add a single item to an existing checklist.
385
+
386
+ Position, due date, due reminder, and member assignment are advanced
387
+ Trello features and may require a subscription on the target board.
388
+ """
389
+ try:
390
+ _print(
391
+ _client().add_checkitem(
392
+ checklist_id=checklist_id,
393
+ name=name,
394
+ pos=pos,
395
+ checked=checked,
396
+ due=due,
397
+ due_reminder=due_reminder,
398
+ member_id=member_id,
399
+ )
400
+ )
401
+ except (TrelloError, ValueError) as exc:
402
+ _fail(str(exc))
403
+
404
+
405
+ @app.command("get-checklist")
406
+ def get_checklist(
407
+ checklist_id: str = typer.Option(..., "--checklist-id", help="Checklist ID."),
408
+ ) -> None:
409
+ """Get a checklist and all of its items."""
410
+ try:
411
+ _print(_client().get_checklist(checklist_id=checklist_id))
412
+ except TrelloError as exc:
413
+ _fail(str(exc))
414
+
415
+
416
+ @app.command("update-checklist")
417
+ def update_checklist(
418
+ checklist_id: str = typer.Option(..., "--checklist-id", help="Checklist ID."),
419
+ name: str | None = typer.Option(None, "--name", help="New checklist title."),
420
+ pos: str | None = typer.Option(None, "--pos", help="New checklist position."),
421
+ ) -> None:
422
+ """Update one or more fields on an existing checklist."""
423
+ try:
424
+ _print(_client().update_checklist(checklist_id=checklist_id, name=name, pos=pos))
425
+ except (TrelloError, ValueError) as exc:
426
+ _fail(str(exc))
427
+
428
+
429
+ @app.command("delete-checklist")
430
+ def delete_checklist(
431
+ checklist_id: str = typer.Option(..., "--checklist-id", help="Checklist ID."),
432
+ ) -> None:
433
+ """Delete a checklist."""
434
+ try:
435
+ _print(_client().delete_checklist(checklist_id=checklist_id))
436
+ except TrelloError as exc:
437
+ _fail(str(exc))
438
+
439
+
440
+ @app.command("get-checkitem")
441
+ def get_checkitem(
442
+ card_id: str = typer.Option(..., "--card-id", help="Card ID."),
443
+ checkitem_id: str = typer.Option(..., "--checkitem-id", help="Checklist item ID."),
444
+ ) -> None:
445
+ """Get a checklist item on a card."""
446
+ try:
447
+ _print(_client().get_checkitem(card_id=card_id, checkitem_id=checkitem_id))
448
+ except TrelloError as exc:
449
+ _fail(str(exc))
450
+
451
+
452
+ @app.command("update-checkitem")
453
+ def update_checkitem(
454
+ card_id: str = typer.Option(..., "--card-id", help="Card ID."),
455
+ checkitem_id: str = typer.Option(..., "--checkitem-id", help="Checklist item ID."),
456
+ name: str | None = typer.Option(None, "--name", help="New item text."),
457
+ state: str | None = typer.Option(None, "--state", help="Item state: complete or incomplete."),
458
+ checklist_id: str | None = typer.Option(None, "--checklist-id", help="Destination checklist ID."),
459
+ pos: str | None = typer.Option(None, "--pos", help="New item position."),
460
+ due: str | None = typer.Option(None, "--due", help="Due date in ISO 8601."),
461
+ due_reminder: int | None = typer.Option(None, "--due-reminder", help="Due reminder in minutes."),
462
+ member_id: str | None = typer.Option(None, "--member-id", help="Member ID assigned to the item."),
463
+ ) -> None:
464
+ """Update one or more fields on a checklist item.
465
+
466
+ Position, due date, due reminder, and member assignment are advanced
467
+ Trello features and may require a subscription on the target board.
468
+ """
469
+ try:
470
+ _print(
471
+ _client().update_checkitem(
472
+ card_id=card_id,
473
+ checkitem_id=checkitem_id,
474
+ name=name,
475
+ state=state,
476
+ checklist_id=checklist_id,
477
+ pos=pos,
478
+ due=due,
479
+ due_reminder=due_reminder,
480
+ member_id=member_id,
481
+ )
482
+ )
483
+ except (TrelloError, ValueError) as exc:
484
+ _fail(str(exc))
485
+
486
+
487
+ @app.command("delete-checkitem")
488
+ def delete_checkitem(
489
+ card_id: str = typer.Option(..., "--card-id", help="Card ID."),
490
+ checkitem_id: str = typer.Option(..., "--checkitem-id", help="Checklist item ID."),
491
+ ) -> None:
492
+ """Delete a checklist item from a card."""
493
+ try:
494
+ _print(_client().delete_checkitem(card_id=card_id, checkitem_id=checkitem_id))
495
+ except TrelloError as exc:
496
+ _fail(str(exc))
497
+
498
+
499
+ @app.command("list-checklists")
500
+ def list_checklists(
501
+ card_id: str = typer.Option(..., "--card-id", help="Trello card ID."),
502
+ ) -> None:
503
+ """List all checklists (with their items) on a card."""
504
+ try:
505
+ _print(_client().list_checklists(card_id=card_id))
506
+ except TrelloError as exc:
507
+ _fail(str(exc))
trello_cli/client.py ADDED
@@ -0,0 +1,332 @@
1
+ import os
2
+ from typing import Any, Literal
3
+
4
+ import requests
5
+
6
+ from .config import load_config_file
7
+ from .markdown import normalize_markdown
8
+
9
+ TRELLO_BASE = "https://api.trello.com/1"
10
+ CardFilter = Literal["open", "closed", "all"]
11
+ CARD_FILTERS: set[str] = {"open", "closed", "all"}
12
+
13
+
14
+ class TrelloError(Exception):
15
+ pass
16
+
17
+
18
+ class TrelloClient:
19
+ def __init__(self) -> None:
20
+ cfg = load_config_file()
21
+ self.api_key = os.environ.get("TRELLO_API_KEY") or cfg.get("api_key", "")
22
+ self.token = os.environ.get("TRELLO_TOKEN") or cfg.get("token", "")
23
+ if not self.api_key or not self.token:
24
+ raise RuntimeError(
25
+ "Trello credentials not found.\n"
26
+ "Please run 'trello-cli auth' to authenticate and save your credentials."
27
+ )
28
+ self._auth = {"key": self.api_key, "token": self.token}
29
+
30
+ def _get(self, path: str, **params: Any) -> Any:
31
+ response = requests.get(
32
+ f"{TRELLO_BASE}{path}",
33
+ params={**self._auth, **params},
34
+ timeout=15,
35
+ )
36
+ if not response.ok:
37
+ raise TrelloError(f"GET {path} -> {response.status_code}: {response.text}")
38
+ return response.json()
39
+
40
+ def _post(self, path: str, **data: Any) -> Any:
41
+ response = requests.post(
42
+ f"{TRELLO_BASE}{path}",
43
+ params=self._auth,
44
+ json=data,
45
+ timeout=15,
46
+ )
47
+ if not response.ok:
48
+ raise TrelloError(f"POST {path} -> {response.status_code}: {response.text}")
49
+ return response.json()
50
+
51
+ def _post_params(self, path: str, **params: Any) -> Any:
52
+ response = requests.post(
53
+ f"{TRELLO_BASE}{path}",
54
+ params={**self._auth, **params},
55
+ timeout=15,
56
+ )
57
+ if not response.ok:
58
+ raise TrelloError(f"POST {path} -> {response.status_code}: {response.text}")
59
+ return response.json()
60
+
61
+ def _put(self, path: str, **data: Any) -> Any:
62
+ response = requests.put(
63
+ f"{TRELLO_BASE}{path}",
64
+ params=self._auth,
65
+ json=data,
66
+ timeout=15,
67
+ )
68
+ if not response.ok:
69
+ raise TrelloError(f"PUT {path} -> {response.status_code}: {response.text}")
70
+ return response.json()
71
+
72
+ def _delete(self, path: str) -> Any:
73
+ response = requests.delete(
74
+ f"{TRELLO_BASE}{path}",
75
+ params=self._auth,
76
+ timeout=15,
77
+ )
78
+ if not response.ok:
79
+ raise TrelloError(f"DELETE {path} -> {response.status_code}: {response.text}")
80
+ return response.json() if response.content else {}
81
+
82
+ def list_boards(self) -> list[dict]:
83
+ boards = self._get("/members/me/boards", fields="id,name,url,closed")
84
+ return [
85
+ {"id": b["id"], "name": b["name"], "url": b["url"], "closed": b["closed"]}
86
+ for b in boards
87
+ ]
88
+
89
+ def get_current_user(self) -> dict:
90
+ """Return the member represented by the configured API token."""
91
+ return self._get("/members/me")
92
+
93
+ def list_lists(self, board_id: str) -> list[dict]:
94
+ lists = self._get(f"/boards/{board_id}/lists", filter="open", fields="id,name,pos")
95
+ return [{"id": item["id"], "name": item["name"], "pos": item["pos"]} for item in lists]
96
+
97
+ def list_cards(self, list_id: str) -> list[dict]:
98
+ cards = self._get(
99
+ f"/lists/{list_id}/cards",
100
+ filter="open",
101
+ fields="id,idShort,name,desc,due,url,idList,labels",
102
+ )
103
+ return [self._fmt(card) for card in cards]
104
+
105
+ def get_card(self, card_id: str) -> dict:
106
+ card = self._get(
107
+ f"/cards/{card_id}",
108
+ fields="id,idShort,name,desc,due,url,idList,idBoard,labels,closed",
109
+ )
110
+ return self._fmt(card)
111
+
112
+ def get_card_by_short_id(
113
+ self,
114
+ board_id: str,
115
+ short_id: int,
116
+ card_filter: CardFilter = "open",
117
+ ) -> dict:
118
+ """Return a card by its board-scoped Trello ``idShort`` value."""
119
+ if card_filter not in CARD_FILTERS:
120
+ raise ValueError(
121
+ f"card_filter must be one of: {', '.join(sorted(CARD_FILTERS))}."
122
+ )
123
+ cards = self._get(
124
+ f"/boards/{board_id}/cards",
125
+ filter=card_filter,
126
+ fields="id,idShort",
127
+ )
128
+ card_id = next(
129
+ (card["id"] for card in cards if card.get("idShort") == short_id),
130
+ None,
131
+ )
132
+ if card_id is None:
133
+ raise TrelloError(
134
+ f"Card short ID {short_id} was not found on board {board_id}."
135
+ )
136
+ return self.get_card(card_id)
137
+
138
+ def create_card(
139
+ self,
140
+ list_id: str,
141
+ name: str,
142
+ desc: str = "",
143
+ due: str | None = None,
144
+ ) -> dict:
145
+ payload: dict[str, Any] = {
146
+ "idList": list_id,
147
+ "name": name,
148
+ "desc": normalize_markdown(desc),
149
+ }
150
+ if due:
151
+ payload["due"] = due
152
+ return self._fmt(self._post("/cards", **payload))
153
+
154
+ def update_card(
155
+ self,
156
+ card_id: str,
157
+ name: str | None = None,
158
+ desc: str | None = None,
159
+ due: str | None = None,
160
+ closed: bool | None = None,
161
+ ) -> dict:
162
+ payload: dict[str, Any] = {}
163
+ if name is not None:
164
+ payload["name"] = name
165
+ if desc is not None:
166
+ payload["desc"] = normalize_markdown(desc)
167
+ if due is not None:
168
+ payload["due"] = due
169
+ if closed is not None:
170
+ payload["closed"] = closed
171
+ if not payload:
172
+ raise ValueError("At least one field must be specified.")
173
+ return self._fmt(self._put(f"/cards/{card_id}", **payload))
174
+
175
+ def add_comment(self, card_id: str, text: str) -> dict:
176
+ if not text.strip():
177
+ raise ValueError("Comment text must not be empty.")
178
+ return self._post_params(
179
+ f"/cards/{card_id}/actions/comments",
180
+ text=normalize_markdown(text),
181
+ )
182
+
183
+ def list_comments(self, card_id: str) -> list[dict]:
184
+ """Return comments on a card in Trello's action order."""
185
+ actions = self._get(
186
+ f"/cards/{card_id}/actions",
187
+ filter="commentCard",
188
+ fields="id,date,data,memberCreator",
189
+ )
190
+ return [self._fmt_comment(action) for action in actions]
191
+
192
+ def create_checklist(self, card_id: str, name: str) -> dict:
193
+ return self._post(f"/cards/{card_id}/checklists", name=name)
194
+
195
+ def get_checklist(self, checklist_id: str) -> dict:
196
+ return self._get(f"/checklists/{checklist_id}", checkItems="all")
197
+
198
+ def update_checklist(
199
+ self,
200
+ checklist_id: str,
201
+ name: str | None = None,
202
+ pos: str | float | int | None = None,
203
+ ) -> dict:
204
+ payload: dict[str, Any] = {}
205
+ if name is not None:
206
+ payload["name"] = name
207
+ if pos is not None:
208
+ payload["pos"] = pos
209
+ if not payload:
210
+ raise ValueError("At least one field must be specified.")
211
+ return self._put(f"/checklists/{checklist_id}", **payload)
212
+
213
+ def delete_checklist(self, checklist_id: str) -> Any:
214
+ return self._delete(f"/checklists/{checklist_id}")
215
+
216
+ def add_checkitem(
217
+ self,
218
+ checklist_id: str,
219
+ name: str,
220
+ pos: str | float | int | None = None,
221
+ checked: bool | None = None,
222
+ due: str | None = None,
223
+ due_reminder: int | None = None,
224
+ member_id: str | None = None,
225
+ ) -> dict:
226
+ """Add a checklist item.
227
+
228
+ ``pos``, ``due``, ``due_reminder``, and ``member_id`` are advanced
229
+ Trello features and may require a subscription on the target board.
230
+ """
231
+ payload: dict[str, Any] = {"name": name}
232
+ if pos is not None:
233
+ payload["pos"] = pos
234
+ if checked is not None:
235
+ payload["checked"] = checked
236
+ if due is not None:
237
+ payload["due"] = due
238
+ if due_reminder is not None:
239
+ payload["dueReminder"] = due_reminder
240
+ if member_id is not None:
241
+ payload["idMember"] = member_id
242
+ return self._post(f"/checklists/{checklist_id}/checkItems", **payload)
243
+
244
+ def get_checkitem(self, card_id: str, checkitem_id: str) -> dict:
245
+ return self._get(f"/cards/{card_id}/checkItem/{checkitem_id}")
246
+
247
+ def update_checkitem(
248
+ self,
249
+ card_id: str,
250
+ checkitem_id: str,
251
+ name: str | None = None,
252
+ state: str | None = None,
253
+ checklist_id: str | None = None,
254
+ pos: str | float | int | None = None,
255
+ due: str | None = None,
256
+ due_reminder: int | None = None,
257
+ member_id: str | None = None,
258
+ ) -> dict:
259
+ """Update a checklist item.
260
+
261
+ ``pos``, ``due``, ``due_reminder``, and ``member_id`` are advanced
262
+ Trello features and may require a subscription on the target board.
263
+ """
264
+ payload: dict[str, Any] = {}
265
+ if name is not None:
266
+ payload["name"] = name
267
+ if state is not None:
268
+ payload["state"] = state
269
+ if checklist_id is not None:
270
+ payload["idChecklist"] = checklist_id
271
+ if pos is not None:
272
+ payload["pos"] = pos
273
+ if due is not None:
274
+ payload["due"] = due
275
+ if due_reminder is not None:
276
+ payload["dueReminder"] = due_reminder
277
+ if member_id is not None:
278
+ payload["idMember"] = member_id
279
+ if not payload:
280
+ raise ValueError("At least one field must be specified.")
281
+ return self._put(f"/cards/{card_id}/checkItem/{checkitem_id}", **payload)
282
+
283
+ def delete_checkitem(self, card_id: str, checkitem_id: str) -> Any:
284
+ return self._delete(f"/cards/{card_id}/checkItem/{checkitem_id}")
285
+
286
+ def list_checklists(self, card_id: str) -> list[dict]:
287
+ card = self._get(
288
+ f"/cards/{card_id}",
289
+ checklists="all",
290
+ fields="id,name",
291
+ )
292
+ return [
293
+ {
294
+ "id": checklist["id"],
295
+ "name": checklist["name"],
296
+ "items": [
297
+ {"id": item["id"], "name": item["name"], "state": item["state"]}
298
+ for item in checklist.get("checkItems", [])
299
+ ],
300
+ }
301
+ for checklist in card.get("checklists", [])
302
+ ]
303
+
304
+ @staticmethod
305
+ def _fmt(card: dict) -> dict:
306
+ return {
307
+ "id": card.get("id"),
308
+ "short_id": card.get("idShort"),
309
+ "name": card.get("name"),
310
+ "desc": card.get("desc", ""),
311
+ "due": card.get("due"),
312
+ "url": card.get("url"),
313
+ "list_id": card.get("idList"),
314
+ "board_id": card.get("idBoard"),
315
+ "closed": card.get("closed", False),
316
+ "labels": [label.get("name") for label in card.get("labels", [])],
317
+ }
318
+
319
+ @staticmethod
320
+ def _fmt_comment(action: dict) -> dict:
321
+ member = action.get("memberCreator") or {}
322
+ data = action.get("data") or {}
323
+ return {
324
+ "id": action.get("id"),
325
+ "date": action.get("date"),
326
+ "text": data.get("text", ""),
327
+ "member_creator": {
328
+ "id": member.get("id"),
329
+ "username": member.get("username"),
330
+ "full_name": member.get("fullName"),
331
+ },
332
+ }
trello_cli/config.py ADDED
@@ -0,0 +1,38 @@
1
+ import tomllib
2
+ from pathlib import Path
3
+
4
+ CONFIG_PATH = Path.home() / ".config" / "trello-cli" / "config.toml"
5
+
6
+
7
+ def load_config_file(config_path: Path = CONFIG_PATH) -> dict[str, str]:
8
+ """Return Trello credentials from config.toml, or an empty dict."""
9
+ if not config_path.exists():
10
+ return {}
11
+
12
+ try:
13
+ with config_path.open("rb") as f:
14
+ data = tomllib.load(f)
15
+ except (tomllib.TOMLDecodeError, OSError):
16
+ return {}
17
+
18
+ section = data.get("trello", {})
19
+ return {
20
+ "api_key": section.get("api_key", ""),
21
+ "token": section.get("token", ""),
22
+ "default_board": section.get("default_board", ""),
23
+ }
24
+
25
+
26
+ def write_config(
27
+ api_key: str,
28
+ token: str,
29
+ config_path: Path = CONFIG_PATH,
30
+ default_board: str = "",
31
+ ) -> None:
32
+ config_path.parent.mkdir(parents=True, exist_ok=True)
33
+ board_line = f'\ndefault_board = "{default_board}"' if default_board else ""
34
+ config_path.write_text(
35
+ f'[trello]\napi_key = "{api_key}"\ntoken = "{token}"{board_line}\n',
36
+ encoding="utf-8",
37
+ )
38
+ config_path.chmod(0o600)
trello_cli/markdown.py ADDED
@@ -0,0 +1,19 @@
1
+ """Helpers for keeping Markdown text intact across LLM/CLI boundaries."""
2
+
3
+ import re
4
+
5
+
6
+ # Only decode newline escapes. Decoding the whole string as JSON would also
7
+ # change ordinary backslashes in Markdown (for example ``\\*`` or a Windows
8
+ # path), which is surprising for a text field.
9
+ _ESCAPED_NEWLINE = re.compile(r"(?<!\\)\\r\\n|(?<!\\)\\n|(?<!\\)\\r")
10
+
11
+
12
+ def normalize_markdown(text: str) -> str:
13
+ """Turn literal ``\\n``/``\\r\\n`` sequences into line breaks.
14
+
15
+ Real line breaks are left untouched. A doubled backslash is preserved so
16
+ callers can still intentionally write a literal ``\\n``.
17
+ """
18
+
19
+ return _ESCAPED_NEWLINE.sub("\n", text)