codapact-confluence 0.1.0__tar.gz

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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mike Hill
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,121 @@
1
+ Metadata-Version: 2.4
2
+ Name: codapact-confluence
3
+ Version: 0.1.0
4
+ Summary: Typed Python client and `codapact-confluence` CLI for the Confluence Cloud REST API v2, with Markdown rich text, generated by Codapact
5
+ Keywords: confluence,atlassian,markdown,adf,cli,api-client,codapact
6
+ Author: Mike Hill
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Environment :: Console
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Classifier: Typing :: Typed
15
+ Requires-Dist: codapact[keyring,browser]>=0.19.1,<0.20
16
+ Requires-Dist: adflux>=0.4.0,<0.5
17
+ Requires-Python: >=3.13
18
+ Project-URL: Homepage, https://github.com/mikejhill/codapact-confluence
19
+ Project-URL: Repository, https://github.com/mikejhill/codapact-confluence
20
+ Project-URL: Issues, https://github.com/mikejhill/codapact-confluence/issues
21
+ Project-URL: Generator, https://github.com/mikejhill/codapact
22
+ Description-Content-Type: text/markdown
23
+
24
+ # codapact-confluence
25
+
26
+ [![CI](https://github.com/mikejhill/codapact-confluence/actions/workflows/ci.yml/badge.svg)](https://github.com/mikejhill/codapact-confluence/actions/workflows/ci.yml) [![PyPI](https://img.shields.io/pypi/v/codapact-confluence)](https://pypi.org/project/codapact-confluence/) [![Python](https://img.shields.io/pypi/pyversions/codapact-confluence)](https://pypi.org/project/codapact-confluence/) [![License](https://img.shields.io/github/license/mikejhill/codapact-confluence)](https://github.com/mikejhill/codapact-confluence/blob/HEAD/LICENSE) [![Confluence Cloud](https://img.shields.io/badge/Confluence_Cloud-2.0.0-blue)](https://developer.atlassian.com/cloud/confluence/rest/v2/) [![Generated by Codapact](https://img.shields.io/badge/generated_by-codapact_0.19.1-blue)](https://github.com/mikejhill/codapact)
27
+
28
+ Typed Python client and `codapact-confluence` command-line tool for [Confluence Cloud](https://developer.atlassian.com/cloud/confluence/rest/v2/), generated by [Codapact](https://github.com/mikejhill/codapact).
29
+
30
+ ## API source
31
+
32
+ Generated from this exact contract; regenerating it with the same Codapact version reproduces the code byte for byte.
33
+
34
+ | | |
35
+ | --- | --- |
36
+ | API | [Confluence Cloud](https://developer.atlassian.com/cloud/confluence/rest/v2/) |
37
+ | Contract | OpenAPI [`openapi.json`](https://github.com/mikejhill/codapact-confluence/blob/HEAD/openapi.json), pinned copy of <https://dac-static.atlassian.com/cloud/confluence/openapi-v2.v3.json> |
38
+ | Version | `2.0.0` |
39
+ | SHA-256 | `40535e2a2c01547d53d824d68299098c9073e5bf7ed98a71634706759becfa31` |
40
+ | Generator | [Codapact](https://github.com/mikejhill/codapact) `0.19.1` |
41
+
42
+ ## Run
43
+
44
+ With [uv](https://docs.astral.sh/uv/); uvx installs the package and its runtime on first use:
45
+
46
+ ```console
47
+ uvx codapact-confluence --help
48
+ uvx --refresh-package codapact-confluence codapact-confluence --version # update to the latest
49
+ ```
50
+
51
+ Requires Python 3.13 or newer.
52
+
53
+ ## Credentials
54
+
55
+ Save once in the OS keyring with `uvx codapact-confluence auth login`, or set per shell:
56
+
57
+ - `basic`: `CONFLUENCE_BASIC_USERNAME`, `CONFLUENCE_BASIC_PASSWORD`. Use your Atlassian account email as the username and an API token as the password (create one at https://id.atlassian.com/manage-profile/security/api-tokens).
58
+ - `session`: `CONFLUENCE_SESSION`. For sites where API tokens are disabled: signs in through a browser window and sends the session cookies.
59
+
60
+ `<VAR>_COMMAND` runs a command that prints the secret (e.g. a password manager). `uvx codapact-confluence doctor` checks settings, credentials, connectivity, and the login.
61
+
62
+ ## Use
63
+
64
+ ```console
65
+ uvx codapact-confluence space list-spaces --keys DOCS
66
+ uvx codapact-confluence page get --id 123456 --query body.markdown.value
67
+ uvx codapact-confluence page create --space-id 98765 --title 'Release notes' --markdown @notes.md
68
+ uvx codapact-confluence page update 123456 --body '{"id":"123456","status":"current","title":"Release notes","version":{"number":2}}' --markdown @notes.md
69
+ uvx codapact-confluence describe --brief # every command, for scripts and agents
70
+ ```
71
+
72
+ As a library:
73
+
74
+ ```python
75
+ from codapact_confluence import Client
76
+
77
+ client = Client()
78
+ ```
79
+
80
+ ## Agent skill
81
+
82
+ The package ships an agent skill that points agents at the CLI. Install it into a skills folder:
83
+
84
+ ```console
85
+ uvx codapact-confluence skill install --dir ~/.agents/skills # or any skills folder
86
+ uvx codapact-confluence skill show # print it
87
+ ```
88
+
89
+ Rerun after an update to refresh it; a copy with local edits needs `--force`.
90
+
91
+ ## Markdown
92
+
93
+ Page, blog post and comment bodies are Markdown both ways. `--markdown TEXT|@file|@-`
94
+ sets the body to send; commands with `--body-format` read `atlas_doc_format` and return it
95
+ as `body.markdown.value`. `--doc-format adf` (or `CONFLUENCE_DOC_FORMAT=adf`) keeps ADF.
96
+ Macros are directives such as `::toc{maxLevel=2}`, `:::info`, `:jira[PROJ-1]`; run
97
+ `uvx adflux macros NAME` for a macro's parameters and `uvx adflux syntax` for the dialect.
98
+
99
+ ## Sign-in
100
+
101
+ Set `--base-url` (or `CONFLUENCE_BASE_URL`) to your site, for example
102
+ `https://your-site.atlassian.net`. An API token is preferred: `codapact-confluence auth login
103
+ --scheme basic` with your Atlassian email and a token from
104
+ https://id.atlassian.com/manage-profile/security/api-tokens. Where API tokens are
105
+ disabled, `codapact-confluence auth login --scheme session` opens a browser window: the
106
+ CLI fills in your email and you type your password and any second factor yourself. The
107
+ session cookies go to your keyring and are renewed without a window until your identity
108
+ provider asks for you again. Browser sign-in needs Chrome,
109
+ Edge or `playwright install chromium`.
110
+
111
+ ## Development
112
+
113
+ The code in `gen/python/` is generated by [Codapact](https://github.com/mikejhill/codapact). Do not edit it; regenerate instead:
114
+
115
+ ```console
116
+ uvx codapact==0.19.1 sync --check # has the provider published a new contract?
117
+ uvx codapact==0.19.1 sync # pull it into the pinned copy
118
+ uvx codapact==0.19.1 generate # run where codapact.yaml is
119
+ uv run --directory gen/python pytest # offline: help, dry runs, scenarios
120
+ CONFLUENCE_E2E_LIVE=1 uv run --directory gen/python pytest -k live # read-only calls to the real API
121
+ ```
@@ -0,0 +1,98 @@
1
+ # codapact-confluence
2
+
3
+ [![CI](https://github.com/mikejhill/codapact-confluence/actions/workflows/ci.yml/badge.svg)](https://github.com/mikejhill/codapact-confluence/actions/workflows/ci.yml) [![PyPI](https://img.shields.io/pypi/v/codapact-confluence)](https://pypi.org/project/codapact-confluence/) [![Python](https://img.shields.io/pypi/pyversions/codapact-confluence)](https://pypi.org/project/codapact-confluence/) [![License](https://img.shields.io/github/license/mikejhill/codapact-confluence)](https://github.com/mikejhill/codapact-confluence/blob/HEAD/LICENSE) [![Confluence Cloud](https://img.shields.io/badge/Confluence_Cloud-2.0.0-blue)](https://developer.atlassian.com/cloud/confluence/rest/v2/) [![Generated by Codapact](https://img.shields.io/badge/generated_by-codapact_0.19.1-blue)](https://github.com/mikejhill/codapact)
4
+
5
+ Typed Python client and `codapact-confluence` command-line tool for [Confluence Cloud](https://developer.atlassian.com/cloud/confluence/rest/v2/), generated by [Codapact](https://github.com/mikejhill/codapact).
6
+
7
+ ## API source
8
+
9
+ Generated from this exact contract; regenerating it with the same Codapact version reproduces the code byte for byte.
10
+
11
+ | | |
12
+ | --- | --- |
13
+ | API | [Confluence Cloud](https://developer.atlassian.com/cloud/confluence/rest/v2/) |
14
+ | Contract | OpenAPI [`openapi.json`](https://github.com/mikejhill/codapact-confluence/blob/HEAD/openapi.json), pinned copy of <https://dac-static.atlassian.com/cloud/confluence/openapi-v2.v3.json> |
15
+ | Version | `2.0.0` |
16
+ | SHA-256 | `40535e2a2c01547d53d824d68299098c9073e5bf7ed98a71634706759becfa31` |
17
+ | Generator | [Codapact](https://github.com/mikejhill/codapact) `0.19.1` |
18
+
19
+ ## Run
20
+
21
+ With [uv](https://docs.astral.sh/uv/); uvx installs the package and its runtime on first use:
22
+
23
+ ```console
24
+ uvx codapact-confluence --help
25
+ uvx --refresh-package codapact-confluence codapact-confluence --version # update to the latest
26
+ ```
27
+
28
+ Requires Python 3.13 or newer.
29
+
30
+ ## Credentials
31
+
32
+ Save once in the OS keyring with `uvx codapact-confluence auth login`, or set per shell:
33
+
34
+ - `basic`: `CONFLUENCE_BASIC_USERNAME`, `CONFLUENCE_BASIC_PASSWORD`. Use your Atlassian account email as the username and an API token as the password (create one at https://id.atlassian.com/manage-profile/security/api-tokens).
35
+ - `session`: `CONFLUENCE_SESSION`. For sites where API tokens are disabled: signs in through a browser window and sends the session cookies.
36
+
37
+ `<VAR>_COMMAND` runs a command that prints the secret (e.g. a password manager). `uvx codapact-confluence doctor` checks settings, credentials, connectivity, and the login.
38
+
39
+ ## Use
40
+
41
+ ```console
42
+ uvx codapact-confluence space list-spaces --keys DOCS
43
+ uvx codapact-confluence page get --id 123456 --query body.markdown.value
44
+ uvx codapact-confluence page create --space-id 98765 --title 'Release notes' --markdown @notes.md
45
+ uvx codapact-confluence page update 123456 --body '{"id":"123456","status":"current","title":"Release notes","version":{"number":2}}' --markdown @notes.md
46
+ uvx codapact-confluence describe --brief # every command, for scripts and agents
47
+ ```
48
+
49
+ As a library:
50
+
51
+ ```python
52
+ from codapact_confluence import Client
53
+
54
+ client = Client()
55
+ ```
56
+
57
+ ## Agent skill
58
+
59
+ The package ships an agent skill that points agents at the CLI. Install it into a skills folder:
60
+
61
+ ```console
62
+ uvx codapact-confluence skill install --dir ~/.agents/skills # or any skills folder
63
+ uvx codapact-confluence skill show # print it
64
+ ```
65
+
66
+ Rerun after an update to refresh it; a copy with local edits needs `--force`.
67
+
68
+ ## Markdown
69
+
70
+ Page, blog post and comment bodies are Markdown both ways. `--markdown TEXT|@file|@-`
71
+ sets the body to send; commands with `--body-format` read `atlas_doc_format` and return it
72
+ as `body.markdown.value`. `--doc-format adf` (or `CONFLUENCE_DOC_FORMAT=adf`) keeps ADF.
73
+ Macros are directives such as `::toc{maxLevel=2}`, `:::info`, `:jira[PROJ-1]`; run
74
+ `uvx adflux macros NAME` for a macro's parameters and `uvx adflux syntax` for the dialect.
75
+
76
+ ## Sign-in
77
+
78
+ Set `--base-url` (or `CONFLUENCE_BASE_URL`) to your site, for example
79
+ `https://your-site.atlassian.net`. An API token is preferred: `codapact-confluence auth login
80
+ --scheme basic` with your Atlassian email and a token from
81
+ https://id.atlassian.com/manage-profile/security/api-tokens. Where API tokens are
82
+ disabled, `codapact-confluence auth login --scheme session` opens a browser window: the
83
+ CLI fills in your email and you type your password and any second factor yourself. The
84
+ session cookies go to your keyring and are renewed without a window until your identity
85
+ provider asks for you again. Browser sign-in needs Chrome,
86
+ Edge or `playwright install chromium`.
87
+
88
+ ## Development
89
+
90
+ The code in `gen/python/` is generated by [Codapact](https://github.com/mikejhill/codapact). Do not edit it; regenerate instead:
91
+
92
+ ```console
93
+ uvx codapact==0.19.1 sync --check # has the provider published a new contract?
94
+ uvx codapact==0.19.1 sync # pull it into the pinned copy
95
+ uvx codapact==0.19.1 generate # run where codapact.yaml is
96
+ uv run --directory gen/python pytest # offline: help, dry runs, scenarios
97
+ CONFLUENCE_E2E_LIVE=1 uv run --directory gen/python pytest -k live # read-only calls to the real API
98
+ ```
@@ -0,0 +1,66 @@
1
+ version: 1
2
+ source:
3
+ type: openapi
4
+ path: openapi.json
5
+ upstream: https://dac-static.atlassian.com/cloud/confluence/openapi-v2.v3.json
6
+ shape:
7
+ - server: {url: "https://your-site.atlassian.net", prefix: /wiki/api/v2}
8
+ - group: {by: tag}
9
+ - auth: {schemes: {basic: basic}}
10
+ - auth: {schemes: {session: {custom: "Browser sign-in"}}, alternative: true}
11
+ cli:
12
+ env_prefix: CONFLUENCE
13
+ extensions: ["codapact_confluence._docformat:extension"]
14
+ skill: {path: skills/codapact-confluence}
15
+ auth:
16
+ basic:
17
+ check: getSpaces
18
+ labels: {username: Atlassian email, secret: API token} # not the account password
19
+ docs: >-
20
+ Use your Atlassian account email as the username and an API token as the password
21
+ (create one at https://id.atlassian.com/manage-profile/security/api-tokens).
22
+ session:
23
+ check: getSpaces
24
+ docs: >-
25
+ For sites where API tokens are disabled: signs in through a browser window and
26
+ sends the session cookies.
27
+ browser:
28
+ login_url: "{base_url}/wiki"
29
+ cookies: [tenant.session.token]
30
+ headers: {X-Atlassian-Token: no-check}
31
+ signin_hosts: ["id.atlassian.com", "*.okta.com"]
32
+ # id.atlassian.com refuses passwords typed by automation (an edge bot screen), so
33
+ # the person types it; codapact fills in the email and waits.
34
+ password_entry: person
35
+ readme:
36
+ name: Confluence Cloud
37
+ docs: https://developer.atlassian.com/cloud/confluence/rest/v2/
38
+ repository: mikejhill/codapact-confluence
39
+ examples:
40
+ - "space list-spaces --keys DOCS"
41
+ - "page get --id 123456 --query body.markdown.value"
42
+ - "page create --space-id 98765 --title 'Release notes' --markdown @notes.md"
43
+ - "page update 123456 --body '{\"id\":\"123456\",\"status\":\"current\",\"title\":\"Release notes\",\"version\":{\"number\":2}}' --markdown @notes.md"
44
+ sections:
45
+ - title: Markdown
46
+ body: |
47
+ Page, blog post and comment bodies are Markdown both ways. `--markdown TEXT|@file|@-`
48
+ sets the body to send; commands with `--body-format` read `atlas_doc_format` and return it
49
+ as `body.markdown.value`. `--doc-format adf` (or `CONFLUENCE_DOC_FORMAT=adf`) keeps ADF.
50
+ Macros are directives such as `::toc{maxLevel=2}`, `:::info`, `:jira[PROJ-1]`; run
51
+ `uvx adflux macros NAME` for a macro's parameters and `uvx adflux syntax` for the dialect.
52
+ - title: Sign-in
53
+ body: |
54
+ Set `--base-url` (or `CONFLUENCE_BASE_URL`) to your site, for example
55
+ `https://your-site.atlassian.net`. An API token is preferred: `codapact-confluence auth login
56
+ --scheme basic` with your Atlassian email and a token from
57
+ https://id.atlassian.com/manage-profile/security/api-tokens. Where API tokens are
58
+ disabled, `codapact-confluence auth login --scheme session` opens a browser window: the
59
+ CLI fills in your email and you type your password and any second factor yourself. The
60
+ session cookies go to your keyring and are renewed without a window until your identity
61
+ provider asks for you again. Browser sign-in needs Chrome,
62
+ Edge or `playwright install chromium`.
63
+ targets:
64
+ - {name: python, output: gen/python, options: {package: codapact_confluence, distribution: codapact-confluence, include: {_docformat.py: handlers/docformat.py}}}
65
+ - {name: python-cli, output: gen/python}
66
+ - {name: python-readme, output: .}
@@ -0,0 +1,6 @@
1
+ """Generated client for The Confluence Cloud REST API v2."""
2
+
3
+ from .types import * # noqa: F403
4
+ from .client import Client
5
+
6
+ __all__ = ["Client"]
@@ -0,0 +1,6 @@
1
+ """Run the generated CLI with ``python -m``."""
2
+
3
+ from .cli import main
4
+
5
+ if __name__ == "__main__":
6
+ raise SystemExit(main())
@@ -0,0 +1,161 @@
1
+ """Markdown in, Markdown out: Confluence page, blog post and comment bodies as Markdown.
2
+
3
+ Confluence stores bodies as Atlassian Document Format (ADF), and also offers ``storage``
4
+ (XHTML) and ``wiki``. With ``--doc-format markdown`` (the default;
5
+ ``CONFLUENCE_DOC_FORMAT`` sets it too):
6
+
7
+ * a ``body`` given as a Markdown string, or as ``{"representation": "markdown", "value":
8
+ ...}``, is sent as ADF (``atlas_doc_format``);
9
+ * commands that take ``--body-format`` ask for ``atlas_doc_format`` unless you choose
10
+ another format, and every ADF body in a response comes back as
11
+ ``{"representation": "markdown", "value": ...}`` (under the key ``markdown``).
12
+
13
+ ``--doc-format adf`` sends and returns bodies unchanged. Conversion uses adflux with its
14
+ Confluence profile: macros (``::toc``, ``:::info``, ``:jira[KEY-1]``...), emoticons,
15
+ layouts. ``uvx adflux syntax`` documents the dialect; ``uvx adflux macros NAME`` shows a
16
+ macro's parameters.
17
+ """
18
+
19
+ from __future__ import annotations
20
+
21
+ import argparse
22
+ import json
23
+ import os
24
+ from typing import Any
25
+
26
+ from adflux import to_adf, to_markdown
27
+
28
+ PROFILE = "confluence"
29
+ ADF = "atlas_doc_format"
30
+ CHOICES = ("markdown", "adf")
31
+
32
+
33
+ def _adf_body(markdown: str) -> dict[str, str]:
34
+ return {"representation": ADF, "value": json.dumps(to_adf(markdown, PROFILE), ensure_ascii=False)}
35
+
36
+
37
+ def to_wire(value: Any, key: str | None = None) -> Any:
38
+ """Convert Markdown bodies to ADF bodies, recursively."""
39
+ if key == "body" and isinstance(value, str):
40
+ return _adf_body(value)
41
+ if isinstance(value, dict):
42
+ if value.get("representation") == "markdown" and isinstance(value.get("value"), str):
43
+ return _adf_body(value["value"])
44
+ return {k: to_wire(v, k) for k, v in value.items()}
45
+ if isinstance(value, list):
46
+ return [to_wire(v, key) for v in value]
47
+ return value
48
+
49
+
50
+ def is_adf(value: Any) -> bool:
51
+ """Whether ``value`` is an ADF document."""
52
+ return isinstance(value, dict) and value.get("type") == "doc" and isinstance(value.get("content"), list)
53
+
54
+
55
+ def from_wire(value: Any) -> Any:
56
+ """Convert ADF bodies (and bare ADF documents) in ``value`` to Markdown, recursively."""
57
+ if is_adf(value):
58
+ return to_markdown(value, PROFILE)
59
+ if isinstance(value, dict):
60
+ if value.get("representation") == ADF and isinstance(value.get("value"), str) and value["value"]:
61
+ return {**value, "representation": "markdown", "value": to_markdown(value["value"], PROFILE)}
62
+ out: dict[str, Any] = {}
63
+ for k, v in value.items():
64
+ converted = from_wire(v)
65
+ if k == ADF and isinstance(converted, dict) and converted.get("representation") == "markdown":
66
+ out["markdown"] = converted
67
+ else:
68
+ out[k] = converted
69
+ return out
70
+ if isinstance(value, list):
71
+ return [from_wire(v) for v in value]
72
+ return value
73
+
74
+
75
+ class MarkdownHook:
76
+ """Call hook that converts bodies between Markdown and ADF."""
77
+
78
+ def __init__(self, markdown: str | None = None) -> None:
79
+ self.markdown = markdown
80
+
81
+ def before(self, operation: Any, arguments: dict[str, Any]) -> dict[str, Any]:
82
+ if self.markdown is not None:
83
+ request = arguments.get("body")
84
+ if not isinstance(request, dict):
85
+ raise ValueError("--markdown is for commands that send a page, post or comment body")
86
+ arguments = {**arguments, "body": {**request, "body": self.markdown}}
87
+ out = {k: to_wire(v) if isinstance(v, dict | list) else v for k, v in arguments.items()}
88
+ names = {p.name for p in getattr(operation, "params", ())}
89
+ if "body_format" in names and out.get("body_format") is None:
90
+ out["body_format"] = ADF
91
+ return out
92
+
93
+ def after(self, operation: Any, result: Any) -> Any:
94
+ del operation
95
+ return from_wire(result)
96
+
97
+
98
+ class Extension:
99
+ """``cli.extensions`` entry: the ``--doc-format`` option."""
100
+
101
+ def __init__(self, runtime: Any) -> None:
102
+ self.prefix = getattr(runtime, "env_prefix", "CONFLUENCE")
103
+
104
+ def add_options(self, group: argparse._ArgumentGroup, hidden: bool) -> None:
105
+ group.add_argument(
106
+ "--doc-format",
107
+ choices=CHOICES,
108
+ default=argparse.SUPPRESS,
109
+ help=argparse.SUPPRESS
110
+ if hidden
111
+ else f"bodies as markdown (default) or raw adf JSON (env {self.prefix}_DOC_FORMAT)",
112
+ )
113
+ group.add_argument(
114
+ "--markdown",
115
+ metavar="TEXT|@FILE|@-",
116
+ default=argparse.SUPPRESS,
117
+ help=argparse.SUPPRESS
118
+ if hidden
119
+ else "the body to send, as Markdown text, @file, or @- for stdin (instead of --body JSON)",
120
+ )
121
+
122
+ def format(self, args: argparse.Namespace) -> str:
123
+ chosen = getattr(args, "doc_format", None) or os.environ.get(f"{self.prefix}_DOC_FORMAT") or "markdown"
124
+ if chosen not in CHOICES:
125
+ raise ValueError(f"{self.prefix}_DOC_FORMAT must be markdown or adf")
126
+ return chosen
127
+
128
+ def hooks(self, args: argparse.Namespace) -> list[Any]:
129
+ markdown = _read(getattr(args, "markdown", None))
130
+ if self.format(args) != "markdown":
131
+ if markdown is not None:
132
+ raise ValueError("--markdown needs --doc-format markdown")
133
+ return []
134
+ return [MarkdownHook(markdown)]
135
+
136
+ def notes(self) -> list[str]:
137
+ return [
138
+ "Bodies are Markdown in and out: --markdown TEXT|@file|@- sets the body to send; "
139
+ "responses return "
140
+ "body.markdown.value. --doc-format adf keeps ADF JSON. Dialect: uvx adflux syntax; "
141
+ "macros: uvx adflux macros NAME.",
142
+ ]
143
+
144
+
145
+ def _read(value: str | None) -> str | None:
146
+ if value is None:
147
+ return None
148
+ if value == "@-":
149
+ import sys
150
+
151
+ return sys.stdin.read()
152
+ if value.startswith("@"):
153
+ from pathlib import Path
154
+
155
+ return Path(value[1:]).read_text(encoding="utf-8")
156
+ return value
157
+
158
+
159
+ def extension(runtime: Any) -> Extension:
160
+ """Factory named in ``cli.extensions``."""
161
+ return Extension(runtime)