Skip to content

Commit 24ecdc8

Browse files
committed
fix: render bash completion block correctly
1 parent fa2ad9f commit 24ecdc8

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎o2switch_cli/cli/completion_support.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ def managed_bashrc_block(
4343
for command_name in command_names:
4444
command_path = (resolved_completion_dir / command_name).expanduser()
4545
source_lines.append(f' [[ -r "{command_path}" ]] && source "{command_path}"')
46+
rendered_lines = "\n".join(source_lines)
4647
return (
4748
f"{BASHRC_MARKER_START}\n"
4849
'if [[ -n "${BASH_VERSION:-}" ]]; then\n'
49-
f"{source_lines}\n"
50+
f"{rendered_lines}\n"
5051
"fi\n"
5152
f"{BASHRC_MARKER_END}\n"
5253
)

‎tests/test_completion_support.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,22 @@ def test_install_and_remove_bash_completion_manage_files_and_bashrc(tmp_path: Pa
3232
assert "# >>> o2switch-cli completion >>>" in bashrc
3333
assert str(completion_dir / "o2switch-cli") in bashrc
3434
assert str(completion_dir / "o2switch_cli") in bashrc
35+
assert "['" not in bashrc
36+
assert '[[ -r "' in bashrc
37+
assert 'source "' in bashrc
3538

3639
removed = remove_bash_completion(completion_dir=completion_dir, bashrc_path=bashrc_path)
3740

3841
assert {path.name for path in removed} == set(COMMAND_NAMES)
3942
assert not (completion_dir / "o2switch-cli").exists()
4043
assert not (completion_dir / "o2switch_cli").exists()
4144
assert "# >>> o2switch-cli completion >>>" not in bashrc_path.read_text()
45+
46+
47+
def test_managed_bashrc_block_renders_shell_lines_not_python_list(tmp_path: Path) -> None:
48+
completion_dir = tmp_path / "completions"
49+
block = install_bash_completion(completion_dir=completion_dir, bashrc_path=tmp_path / ".bashrc")
50+
del block
51+
rendered = (tmp_path / ".bashrc").read_text()
52+
assert "['" not in rendered
53+
assert ", '" not in rendered

0 commit comments

Comments
 (0)