diff --git a/changelog.md b/changelog.md index e9a22261..94bac45f 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,7 @@ Upcoming (TBD) Features -------- * Add `/ping` special command. +* Hide timings after `/system clear`. Documentation diff --git a/mycli/packages/special/iocommands.py b/mycli/packages/special/iocommands.py index b6def048..d9eaf8c2 100644 --- a/mycli/packages/special/iocommands.py +++ b/mycli/packages/special/iocommands.py @@ -787,8 +787,9 @@ def execute_system_command(arg: str, **_) -> list[SQLResult]: completed_process = subprocess.run(command, check=False) if completed_process.returncode: return [SQLResult(status=f'Command exited with return code {completed_process.returncode}')] - else: - return [SQLResult()] + if command[0].lower() == 'clear': + return [] + return [SQLResult()] else: process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) try: diff --git a/test/pytests/test_special_iocommands.py b/test/pytests/test_special_iocommands.py index ff40736b..ba29c272 100644 --- a/test/pytests/test_special_iocommands.py +++ b/test/pytests/test_special_iocommands.py @@ -1491,6 +1491,7 @@ def raise_value_error(*_args, **_kwargs): [ ('-r echo ok', 0, None), ('vim file.sql', 1, 'Command exited with return code 1'), + ('clear', 1, 'Command exited with return code 1'), ], ) def test_execute_system_command_raw_modes( @@ -1512,6 +1513,20 @@ def fake_run(cmd: list[str], check: bool = False) -> SimpleNamespace: assert result.status == expected_status +@pytest.mark.parametrize('command', ['clear', 'CLEAR', '-r clear']) +def test_execute_system_clear_returns_no_result(monkeypatch, command: str) -> None: + calls: list[list[str]] = [] + + def fake_run(cmd: list[str], check: bool = False) -> SimpleNamespace: + calls.append(cmd) + return SimpleNamespace(returncode=0) + + monkeypatch.setattr(iocommands.subprocess, 'run', fake_run) + + assert iocommands.execute_system_command(command) == [] + assert calls == [[part for part in command.split() if part != '-r']] + + def test_execute_system_command_nonraw_paths(monkeypatch) -> None: monkeypatch.setattr(iocommands.locale, 'getpreferredencoding', lambda do_setlocale: 'utf-8')