diff --git a/pyproject.toml b/pyproject.toml index 54620c00..e98f44f7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,7 @@ classifiers = [ ] dependencies = [ - "aleph-sdk-python>=1.0.0,<2", + "aleph-sdk-python>=1.0.1,<2", "setuptools>=65.5.0", "aleph-message>=0.4.9", "aiohttp==3.9.5", diff --git a/src/aleph_client/commands/message.py b/src/aleph_client/commands/message.py index 9a69c40c..0795b5eb 100644 --- a/src/aleph_client/commands/message.py +++ b/src/aleph_client/commands/message.py @@ -21,11 +21,13 @@ from aleph_message.models import AlephMessage, ProgramMessage from aleph_message.models.base import MessageType from aleph_message.models.item_hash import ItemHash +from aleph_message.status import MessageStatus from aleph_client.commands import help_strings from aleph_client.commands.utils import ( colorful_json, colorful_message_json, + colorized_status, input_multiline, setup_logging, str_to_datetime, @@ -41,8 +43,13 @@ async def get( item_hash: str = typer.Argument(..., help="Item hash of the message"), ): async with AlephHttpClient(api_server=sdk_settings.API_HOST) as client: - message: AlephMessage = await client.get_message(item_hash=ItemHash(item_hash)) - typer.echo(colorful_message_json(message)) + message, status = await client.get_message(item_hash=ItemHash(item_hash), with_status=True) + typer.echo(f"Message Status: {colorized_status(status)}") + if status == MessageStatus.REJECTED: + reason = await client.get_message_error(item_hash=ItemHash(item_hash)) + typer.echo(colorful_json(json.dumps(reason, indent=4))) + else: + typer.echo(colorful_message_json(message)) @app.command() diff --git a/src/aleph_client/commands/utils.py b/src/aleph_client/commands/utils.py index 6e716fc9..70c3d8f4 100644 --- a/src/aleph_client/commands/utils.py +++ b/src/aleph_client/commands/utils.py @@ -13,6 +13,7 @@ from aleph.sdk.conf import settings as sdk_settings from aleph.sdk.types import GenericMessage from aleph_message.models import ItemHash +from aleph_message.status import MessageStatus from pygments import highlight from pygments.formatters.terminal256 import Terminal256Formatter from pygments.lexers import JsonLexer @@ -33,6 +34,18 @@ def colorful_json(obj: str): ) +def colorized_status(status: MessageStatus) -> str: + """Return a colored status string based on its value.""" + status_colors = { + MessageStatus.REJECTED: typer.colors.RED, + MessageStatus.PROCESSED: typer.colors.GREEN, + MessageStatus.PENDING: typer.colors.YELLOW, + MessageStatus.FORGOTTEN: typer.colors.BRIGHT_BLACK, + } + color = status_colors.get(status, typer.colors.WHITE) + return typer.style(status, fg=color, bold=True) + + def colorful_message_json(message: GenericMessage): """Render a message in JSON with colors.""" return colorful_json(message.json(sort_keys=True, indent=4))