- Changed bare except clauses to specific exception types in web3_utils.py, testing.py, messages.py, and message_storage.py - Replaced print() calls with logger in testing.py, agent_discovery.py, compliance_agent.py, coordinator.py, trading_agent.py, keys.py, escrow.py, persistent_spending_tracker.py, sync_cli.py, and client.py - Added logger initialization using get_logger(__name__) in compliance_agent.py, coordinator.py, trading_agent.py, keys.py, escrow.py, persistent_spending_tracker.py, and client.py - Removed hardcoded secret
88 lines
2.1 KiB
Python
88 lines
2.1 KiB
Python
"""
|
|
CLI utility functions for output formatting and error handling
|
|
"""
|
|
|
|
import base64
|
|
import logging
|
|
|
|
from click import echo, secho
|
|
|
|
# Import new utility modules
|
|
from . import wallet
|
|
from . import blockchain
|
|
from . import chain_id
|
|
from . import island_credentials
|
|
from .wallet import decrypt_private_key
|
|
from .blockchain import get_chain_info, get_network_status, get_blockchain_analytics
|
|
|
|
|
|
def output(message: str, **kwargs):
|
|
"""Print a regular output message"""
|
|
echo(message, **kwargs)
|
|
|
|
|
|
def error(message: str, **kwargs):
|
|
"""Print an error message in red"""
|
|
secho(message, fg="red", **kwargs)
|
|
|
|
|
|
def success(message: str, **kwargs):
|
|
"""Print a success message in green"""
|
|
secho(message, fg="green", **kwargs)
|
|
|
|
|
|
def info(message: str, **kwargs):
|
|
"""Print an info message in blue"""
|
|
secho(message, fg="blue", **kwargs)
|
|
|
|
|
|
def warning(message: str, **kwargs):
|
|
"""Print a warning message in yellow"""
|
|
secho(message, fg="yellow", **kwargs)
|
|
|
|
|
|
def encrypt_value(value: str, key: str = None) -> str:
|
|
"""Lightweight reversible encoding used for CLI compatibility."""
|
|
return base64.b64encode(value.encode("utf-8")).decode("ascii")
|
|
|
|
|
|
def decrypt_value(encrypted: str, key: str = None) -> str:
|
|
"""Reverse the lightweight compatibility encoding."""
|
|
return base64.b64decode(encrypted.encode("ascii")).decode("utf-8")
|
|
|
|
|
|
def setup_logging(verbosity: int, debug: bool = False) -> str:
|
|
"""Configure basic CLI logging for compatibility with the generated entrypoint."""
|
|
if debug or verbosity >= 2:
|
|
level = logging.DEBUG
|
|
level_name = "DEBUG"
|
|
elif verbosity == 1:
|
|
level = logging.INFO
|
|
level_name = "INFO"
|
|
else:
|
|
level = logging.WARNING
|
|
level_name = "WARNING"
|
|
|
|
logging.basicConfig(level=level, format="%(message)s")
|
|
return level_name
|
|
|
|
|
|
__all__ = [
|
|
'output',
|
|
'error',
|
|
'success',
|
|
'info',
|
|
'warning',
|
|
'encrypt_value',
|
|
'decrypt_value',
|
|
'setup_logging',
|
|
'wallet',
|
|
'blockchain',
|
|
'chain_id',
|
|
'island_credentials',
|
|
'decrypt_private_key',
|
|
'get_chain_info',
|
|
'get_network_status',
|
|
'get_blockchain_analytics',
|
|
]
|