Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,8 @@ class Command:
# sometimes we may return just a plain unicode string
"return_cmd": False,
"async": False,
# whether to echo each command before executing it
"x": False,
}

# this is a collection of validators to make sure the special kwargs make
Expand Down Expand Up @@ -1478,6 +1480,8 @@ def __call__(self, *args, **kwargs):
final_args = split_args

cmd.extend(final_args)
if call_args["x"]:
print(" ".join(cmd))

# if we're running in foreground mode, we need to completely bypass
# launching a RunningCommand and OProc and just do a spawn
Expand Down
12 changes: 12 additions & 0 deletions tests/sh_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3233,6 +3233,18 @@ def test_ok_code_ignores_bad_sig_exception(self):
else:
self.assertEqual(p.exit_code, -sig)

def test_x(self):
import sh

stdout = StringIO()
original_stdout = sys.stdout
sys.stdout = stdout

echo = sh.echo("hello", "world", _x=True, _return_cmd=True)

self.assertIn(str(" ".join(echo.cmd)), stdout.getvalue().strip())
sys.stdout = original_stdout


class MockTests(BaseTests):
def test_patch_command_cls(self):
Expand Down