Files
aitbc/cli/aitbc_cli/utils/__init__.py
aitbc 83a03be376
Some checks failed
CLI Tests / test-cli (push) Failing after 3s
Cross-Node Transaction Testing / transaction-test (push) Successful in 2s
Deploy to Testnet / deploy-testnet (push) Successful in 1m20s
Multi-Node Stress Testing / stress-test (push) Successful in 2s
Security Scanning / security-scan (push) Successful in 35s
fix: update output() signature with format and title parameters, fix Config import in dual_mode_wallet_adapter
- Added format and title parameters to output() function in utils/__init__.py
- Handle format='json'/'yaml' for structured data output
- Display optional title with underline separator when provided
- Fixed import in dual_mode_wallet_adapter.py from config.Config to aitbc_cli.config.CLIConfig
2026-05-19 20:20:40 +02:00

98 lines
2.5 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, format=None, title=None, **kwargs):
"""Print a regular output message (handles strings and structured data)"""
if not isinstance(message, str):
import json
if format == 'json' or format == 'yaml':
message = json.dumps(message, indent=2)
else:
# Table format — just JSON for now
message = json.dumps(message, indent=2)
if title:
echo(f"\n{title}")
echo("=" * len(title))
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',
]