clan-cli: Improved --debug output by indenting commands, add TRACE_DEPTH environment variable
This commit is contained in:
@@ -1,13 +1,24 @@
|
||||
import logging
|
||||
import os
|
||||
import shlex
|
||||
|
||||
from clan_app import main
|
||||
from clan_cli.custom_logger import get_caller
|
||||
from clan_cli.custom_logger import get_callers
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def print_trace(msg: str) -> None:
|
||||
trace_depth = int(os.environ.get("TRACE_DEPTH", "0"))
|
||||
callers = get_callers(2, 2 + trace_depth)
|
||||
|
||||
if "run_no_stdout" in callers[0]:
|
||||
callers = get_callers(3, 3 + trace_depth)
|
||||
callers_str = "\n".join(f"{i+1}: {caller}" for i, caller in enumerate(callers))
|
||||
log.debug(f"{msg} \nCallers: \n{callers_str}")
|
||||
|
||||
|
||||
def run(args: list[str]) -> None:
|
||||
cmd = shlex.join(["clan", *args])
|
||||
log.debug(f"$ {cmd} \nCaller: {get_caller()}")
|
||||
print_trace(f"$ {cmd}")
|
||||
main(args)
|
||||
|
||||
Reference in New Issue
Block a user