This is an automated email from the ASF dual-hosted git repository.
sbp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-releases-client.git
The following commit(s) were added to refs/heads/main by this push:
new 98d91f2 Add a function to select JSON output if configured
98d91f2 is described below
commit 98d91f260f3c22b88da2348efc71b4f53d39ad98
Author: Sean B. Palmer <[email protected]>
AuthorDate: Wed Oct 22 20:05:56 2025 +0100
Add a function to select JSON output if configured
---
pyproject.toml | 4 ++--
src/atrclient/client.py | 11 +++++++----
src/atrclient/config.py | 19 ++++++++++++++++---
src/atrclient/results.py | 5 +----
src/atrclient/show.py | 17 +++++++++++++++++
uv.lock | 4 ++--
6 files changed, 45 insertions(+), 15 deletions(-)
diff --git a/pyproject.toml b/pyproject.toml
index d86f204..c4123c2 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -11,7 +11,7 @@ build-backend = "hatchling.build"
[project]
name = "apache-trusted-releases"
-version = "0.20251022.1835"
+version = "0.20251022.1904"
description = "ATR CLI and Python API"
readme = "README.md"
requires-python = ">=3.13"
@@ -79,4 +79,4 @@ filterwarnings = [
]
[tool.uv]
-exclude-newer = "2025-10-22T18:35:00Z"
+exclude-newer = "2025-10-22T19:04:00Z"
diff --git a/src/atrclient/client.py b/src/atrclient/client.py
index feba8be..40c899d 100755
--- a/src/atrclient/client.py
+++ b/src/atrclient/client.py
@@ -104,7 +104,9 @@ def app_announce(
announce = api.release_announce(announce_args)
if not announce.success:
show.error_and_exit("Failed to announce release.")
- print("Announcement sent.")
+ # The result only contains a success bool
+ # Therefore the ReleaseAnnounceArgs actually contain most of the
information
+ show.json_or_message(announce_args, "Announcement sent.")
@APP.command(name="api", help="Call the API directly.")
@@ -120,11 +122,12 @@ def app_api(path: str, /, **kwargs: str) -> None:
kwargs["version"] = kwargs["_version"]
del kwargs["_version"]
if not basic.is_json(kwargs):
- show.error_and_exit(f"Unexpected API response: {kwargs}")
+ show.error_and_exit(f"Unexpected API request payload type: {kwargs}")
if not basic.is_json_dict(kwargs):
- show.error_and_exit(f"Unexpected API response: {kwargs}")
+ show.error_and_exit(f"Unexpected API request payload type: {kwargs}")
json_data = asyncio.run(web.post_json(url, kwargs, jwt_value, verify_ssl))
- print(json.dumps(json_data, indent=None))
+ # Always show JSON output
+ show.json_or_message(json_data)
@APP_CHECK.command(name="exceptions", help="Get check exceptions for a release
revision.")
diff --git a/src/atrclient/config.py b/src/atrclient/config.py
index 38bc11b..a8f65fe 100644
--- a/src/atrclient/config.py
+++ b/src/atrclient/config.py
@@ -38,11 +38,24 @@ import atrclient.models as models
import atrclient.show as show
import atrclient.web as web
-YAML_DEFAULTS: dict[str, Any] = {"asf": {}, "atr": {}, "tokens": {}}
+YAML_DEFAULTS: dict[str, Any] = {"asf": {}, "atr": {}, "output": {}, "tokens":
{}}
YAML_SCHEMA: strictyaml.Map = strictyaml.Map(
{
- strictyaml.Optional("atr"):
strictyaml.Map({strictyaml.Optional("host"): strictyaml.Str()}),
- strictyaml.Optional("asf"):
strictyaml.Map({strictyaml.Optional("uid"): strictyaml.Str()}),
+ strictyaml.Optional("atr"): strictyaml.Map(
+ {
+ strictyaml.Optional("host"): strictyaml.Str(),
+ }
+ ),
+ strictyaml.Optional("asf"): strictyaml.Map(
+ {
+ strictyaml.Optional("uid"): strictyaml.Str(),
+ }
+ ),
+ strictyaml.Optional("output"): strictyaml.Map(
+ {
+ strictyaml.Optional("json"): strictyaml.Bool(),
+ }
+ ),
strictyaml.Optional("tokens"): strictyaml.Map(
{
strictyaml.Optional("pat"): strictyaml.Str(),
diff --git a/src/atrclient/results.py b/src/atrclient/results.py
index 01cd273..e4de70d 100644
--- a/src/atrclient/results.py
+++ b/src/atrclient/results.py
@@ -19,7 +19,4 @@ from __future__ import annotations
import atrclient.models.schema as schema
-
-class Announce(schema.Strict):
- success: bool = schema.example(True)
- message: str = schema.example("Announcement sent.")
+_ = schema
diff --git a/src/atrclient/show.py b/src/atrclient/show.py
index 090289d..a7959f8 100644
--- a/src/atrclient/show.py
+++ b/src/atrclient/show.py
@@ -17,9 +17,14 @@
from __future__ import annotations
+import json
import sys
from typing import NoReturn
+import atrclient.basic as basic
+import atrclient.config as config
+import atrclient.models.schema as schema
+
def error_and_exit(message: str, code: int = 1) -> NoReturn:
sys.stderr.write(f"atr: error: {message}\n")
@@ -27,6 +32,18 @@ def error_and_exit(message: str, code: int = 1) -> NoReturn:
raise SystemExit(code)
+def json_or_message(data: basic.JSON | schema.Strict, message: str | None =
None) -> None:
+ cfg = config.read()
+ output_json = config.get(cfg, ["output", "json"])
+ if (output_json is True) or (message is None):
+ if isinstance(data, schema.Strict):
+ print(json.dumps(data.model_dump(), indent=None))
+ else:
+ print(json.dumps(data, indent=None))
+ else:
+ print(message)
+
+
def warning(message: str) -> None:
sys.stderr.write(f"atr: warning: {message}\n")
sys.stderr.flush()
diff --git a/uv.lock b/uv.lock
index c3d7e46..c1e93b5 100644
--- a/uv.lock
+++ b/uv.lock
@@ -3,7 +3,7 @@ revision = 3
requires-python = ">=3.13"
[options]
-exclude-newer = "2025-10-22T18:35:00Z"
+exclude-newer = "2025-10-22T19:04:00Z"
[[package]]
name = "aiohappyeyeballs"
@@ -118,7 +118,7 @@ wheels = [
[[package]]
name = "apache-trusted-releases"
-version = "0.20251022.1835"
+version = "0.20251022.1904"
source = { editable = "." }
dependencies = [
{ name = "aiohttp" },
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]