Skip to content
Merged
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
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Upcoming (TBD)
Features
--------
* Add `/ping` special command.
* Hide timings after `/system clear`.


Documentation
Expand Down
5 changes: 3 additions & 2 deletions mycli/packages/special/iocommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 15 additions & 0 deletions test/pytests/test_special_iocommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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')

Expand Down
Loading