Skip to content

Commit 7b3654a

Browse files
committed
tmux_cmd(feat[logging]): Add pre-execution command logging
why: tmux_cmd logs stdout after execution and exceptions, but never logs the command before execution. Pre-execution logging is the prerequisite for a future dry-run mode in tmuxp (tmuxinator's debug / teamocil's --debug equivalent). what: - Add logger.debug call before subprocess.Popen in tmux_cmd.__init__ - Add test verifying pre-execution log message contains command
1 parent 3be0433 commit 7b3654a

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/libtmux/common.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ def __init__(self, *args: t.Any) -> None:
259259

260260
self.cmd = cmd
261261

262+
logger.debug("running %s", subprocess.list2cmdline(cmd))
263+
262264
try:
263265
self.process = subprocess.Popen(
264266
cmd,

tests/test_common.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import logging
56
import re
67
import sys
78
import typing as t
@@ -27,6 +28,7 @@
2728
)
2829

2930
if t.TYPE_CHECKING:
31+
from libtmux.server import Server
3032
from libtmux.session import Session
3133

3234
version_regex = re.compile(r"([0-9]\.[0-9])|(master)")
@@ -508,3 +510,15 @@ def mock_get_version() -> LooseVersion:
508510
elif check_type == "type_check":
509511
assert mock_version is not None # For type checker
510512
assert isinstance(has_version(mock_version), bool)
513+
514+
515+
def test_tmux_cmd_pre_execution_logging(
516+
caplog: pytest.LogCaptureFixture,
517+
server: Server,
518+
) -> None:
519+
"""Verify tmux_cmd logs command before execution."""
520+
with caplog.at_level(logging.DEBUG, logger="libtmux.common"):
521+
server.cmd("list-sessions")
522+
assert any(
523+
"running" in r.message and "list-sessions" in r.message for r in caplog.records
524+
)

0 commit comments

Comments
 (0)