forked from Backblaze/B2_Command_Line_Tool
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add autocomplete support for zsh and fish shells
- Loading branch information
1 parent
e38f495
commit 63966eb
Showing
6 changed files
with
175 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add autocomplete support for `zsh` and `fish` shells. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
###################################################################### | ||
# | ||
# File: test/unit/console_tool/test_install_autocomplete.py | ||
# | ||
# Copyright 2024 Backblaze Inc. All Rights Reserved. | ||
# | ||
# License https://www.backblaze.com/using_b2_code.html | ||
# | ||
###################################################################### | ||
|
||
import contextlib | ||
import shutil | ||
from test.helpers import skip_on_windows | ||
|
||
import pexpect | ||
import pytest | ||
|
||
|
||
@contextlib.contextmanager | ||
def pexpect_shell(shell_bin, env): | ||
p = pexpect.spawn(f"{shell_bin} -i", env=env, maxread=1000) | ||
p.setwinsize(100, 100) # required to see all suggestions in tests | ||
yield p | ||
p.close() | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"shell", | ||
[ | ||
"bash", | ||
"zsh", | ||
"fish", | ||
], | ||
) | ||
@skip_on_windows | ||
def test_install_autocomplete(b2_cli, env, shell, monkeypatch): | ||
shell_bin = shutil.which(shell) | ||
if shell_bin is None: | ||
pytest.skip(f"{shell} is not installed") | ||
|
||
monkeypatch.setenv("SHELL", shell_bin) | ||
b2_cli.run( | ||
["install-autocomplete"], | ||
expected_part_of_stdout=f"Autocomplete successfully installed for {shell}", | ||
) | ||
|
||
if shell == "fish": # no idea how to test fish autocompletion (does not seem to work with dummy terminal) | ||
return | ||
|
||
with pexpect_shell(shell_bin, env=env) as pshell: | ||
pshell.send("b2 \t\t") | ||
pshell.expect_exact(["authorize-account", "download-file", "get-bucket"], timeout=30) |