File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed
src/aleph_client/commands Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change 2121from aleph_message .models import AlephMessage , ProgramMessage
2222from aleph_message .models .base import MessageType
2323from aleph_message .models .item_hash import ItemHash
24+ from aleph_message .status import MessageStatus
2425
2526from aleph_client .commands import help_strings
2627from 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 ,
3941async 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 ()
Original file line number Diff line number Diff line change 1414from aleph .sdk .exceptions import ForgottenMessageError , MessageNotFoundError
1515from aleph .sdk .types import GenericMessage
1616from aleph_message .models import AlephMessage , ItemHash
17+ from aleph_message .status import MessageStatus
1718from pygments import highlight
1819from pygments .formatters .terminal256 import Terminal256Formatter
1920from 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+
3750def colorful_message_json (message : GenericMessage ):
3851 """Render a message in JSON with colors."""
3952 return colorful_json (message .json (sort_keys = True , indent = 4 ))
You can’t perform that action at this time.
0 commit comments