Skip to content

Commit 4bf5eed

Browse files
authored
Merge branch 'master' into fix-various-fixes-after-1.0.0
2 parents 845764f + 37fac02 commit 4bf5eed

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/aleph_client/commands/message.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
from aleph_message.models import AlephMessage, ProgramMessage
2222
from aleph_message.models.base import MessageType
2323
from aleph_message.models.item_hash import ItemHash
24+
from aleph_message.status import MessageStatus
2425

2526
from aleph_client.commands import help_strings
2627
from aleph_client.commands.utils import (
2728
colorful_json,
2829
colorful_message_json,
30+
colorized_status,
2931
input_multiline,
3032
setup_logging,
3133
str_to_datetime,
@@ -39,9 +41,14 @@
3941
async def get(
4042
item_hash: str = typer.Argument(..., help="Item hash of the message"),
4143
):
42-
async with AlephHttpClient(api_server=settings.API_HOST) as client:
43-
message: AlephMessage = await client.get_message(item_hash=ItemHash(item_hash))
44-
typer.echo(colorful_message_json(message))
44+
async with AlephHttpClient(api_server=sdk_settings.API_HOST) as client:
45+
message, status = await client.get_message(item_hash=ItemHash(item_hash), with_status=True)
46+
typer.echo(f"Message Status: {colorized_status(status)}")
47+
if status == MessageStatus.REJECTED:
48+
reason = await client.get_message_error(item_hash=ItemHash(item_hash))
49+
typer.echo(colorful_json(json.dumps(reason, indent=4)))
50+
else:
51+
typer.echo(colorful_message_json(message))
4552

4653

4754
@app.command()

src/aleph_client/commands/utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from aleph.sdk.exceptions import ForgottenMessageError, MessageNotFoundError
1515
from aleph.sdk.types import GenericMessage
1616
from aleph_message.models import AlephMessage, ItemHash
17+
from aleph_message.status import MessageStatus
1718
from pygments import highlight
1819
from pygments.formatters.terminal256 import Terminal256Formatter
1920
from pygments.lexers import JsonLexer
@@ -34,6 +35,18 @@ def colorful_json(obj: str):
3435
)
3536

3637

38+
def colorized_status(status: MessageStatus) -> str:
39+
"""Return a colored status string based on its value."""
40+
status_colors = {
41+
MessageStatus.REJECTED: typer.colors.RED,
42+
MessageStatus.PROCESSED: typer.colors.GREEN,
43+
MessageStatus.PENDING: typer.colors.YELLOW,
44+
MessageStatus.FORGOTTEN: typer.colors.BRIGHT_BLACK,
45+
}
46+
color = status_colors.get(status, typer.colors.WHITE)
47+
return typer.style(status, fg=color, bold=True)
48+
49+
3750
def colorful_message_json(message: GenericMessage):
3851
"""Render a message in JSON with colors."""
3952
return colorful_json(message.json(sort_keys=True, indent=4))

0 commit comments

Comments
 (0)