Skip to content

Commit 70ffd68

Browse files
patricksurrytiangolopre-commit-ci[bot]svlandeg
authored
🐛 Fix PowerShell completion with incomplete word (#360)
Co-authored-by: Sebastián Ramírez <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: svlandeg <[email protected]>
1 parent 3f566ed commit 70ffd68

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

tests/test_tutorial/test_options_autocompletion/test_tutorial003.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
runner = CliRunner()
1010

1111

12-
def test_completion():
12+
def test_completion_zsh():
1313
result = subprocess.run(
1414
[sys.executable, "-m", "coverage", "run", mod.__file__, " "],
1515
capture_output=True,
@@ -25,6 +25,23 @@ def test_completion():
2525
assert "Sebastian" in result.stdout
2626

2727

28+
def test_completion_powershell():
29+
result = subprocess.run(
30+
[sys.executable, "-m", "coverage", "run", mod.__file__, " "],
31+
capture_output=True,
32+
encoding="utf-8",
33+
env={
34+
**os.environ,
35+
"_TUTORIAL003.PY_COMPLETE": "complete_powershell",
36+
"_TYPER_COMPLETE_ARGS": "tutorial003.py --name Seb",
37+
"_TYPER_COMPLETE_WORD_TO_COMPLETE": "Seb",
38+
},
39+
)
40+
assert "Camila" not in result.stdout
41+
assert "Carlos" not in result.stdout
42+
assert "Sebastian" in result.stdout
43+
44+
2845
def test_1():
2946
result = runner.invoke(mod.app, ["--name", "Camila"])
3047
assert result.exit_code == 0

tests/test_tutorial/test_options_autocompletion/test_tutorial003_an.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
runner = CliRunner()
1010

1111

12-
def test_completion():
12+
def test_completion_zsh():
1313
result = subprocess.run(
1414
[sys.executable, "-m", "coverage", "run", mod.__file__, " "],
1515
capture_output=True,
@@ -25,6 +25,23 @@ def test_completion():
2525
assert "Sebastian" in result.stdout
2626

2727

28+
def test_completion_powershell():
29+
result = subprocess.run(
30+
[sys.executable, "-m", "coverage", "run", mod.__file__, " "],
31+
capture_output=True,
32+
encoding="utf-8",
33+
env={
34+
**os.environ,
35+
"_TUTORIAL003_AN.PY_COMPLETE": "complete_powershell",
36+
"_TYPER_COMPLETE_ARGS": "tutorial003.py --name Seb",
37+
"_TYPER_COMPLETE_WORD_TO_COMPLETE": "Seb",
38+
},
39+
)
40+
assert "Camila" not in result.stdout
41+
assert "Carlos" not in result.stdout
42+
assert "Sebastian" in result.stdout
43+
44+
2845
def test_1():
2946
result = runner.invoke(mod.app, ["--name", "Camila"])
3047
assert result.exit_code == 0

typer/_completion_classes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def get_completion_args(self) -> Tuple[List[str], str]:
175175
completion_args = os.getenv("_TYPER_COMPLETE_ARGS", "")
176176
incomplete = os.getenv("_TYPER_COMPLETE_WORD_TO_COMPLETE", "")
177177
cwords = click.parser.split_arg_string(completion_args)
178-
args = cwords[1:]
178+
args = cwords[1:-1] if incomplete else cwords[1:]
179179
return args, incomplete
180180

181181
def format_completion(self, item: click.shell_completion.CompletionItem) -> str:

0 commit comments

Comments
 (0)