Skip to content

Commit

Permalink
🐛 Fix PowerShell completion with incomplete word (#360)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: svlandeg <svlandeg@github.com>
  • Loading branch information
4 people authored Aug 24, 2024
1 parent 3f566ed commit 70ffd68
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
runner = CliRunner()


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


def test_completion_powershell():
result = subprocess.run(
[sys.executable, "-m", "coverage", "run", mod.__file__, " "],
capture_output=True,
encoding="utf-8",
env={
**os.environ,
"_TUTORIAL003.PY_COMPLETE": "complete_powershell",
"_TYPER_COMPLETE_ARGS": "tutorial003.py --name Seb",
"_TYPER_COMPLETE_WORD_TO_COMPLETE": "Seb",
},
)
assert "Camila" not in result.stdout
assert "Carlos" not in result.stdout
assert "Sebastian" in result.stdout


def test_1():
result = runner.invoke(mod.app, ["--name", "Camila"])
assert result.exit_code == 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
runner = CliRunner()


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


def test_completion_powershell():
result = subprocess.run(
[sys.executable, "-m", "coverage", "run", mod.__file__, " "],
capture_output=True,
encoding="utf-8",
env={
**os.environ,
"_TUTORIAL003_AN.PY_COMPLETE": "complete_powershell",
"_TYPER_COMPLETE_ARGS": "tutorial003.py --name Seb",
"_TYPER_COMPLETE_WORD_TO_COMPLETE": "Seb",
},
)
assert "Camila" not in result.stdout
assert "Carlos" not in result.stdout
assert "Sebastian" in result.stdout


def test_1():
result = runner.invoke(mod.app, ["--name", "Camila"])
assert result.exit_code == 0
Expand Down
2 changes: 1 addition & 1 deletion typer/_completion_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def get_completion_args(self) -> Tuple[List[str], str]:
completion_args = os.getenv("_TYPER_COMPLETE_ARGS", "")
incomplete = os.getenv("_TYPER_COMPLETE_WORD_TO_COMPLETE", "")
cwords = click.parser.split_arg_string(completion_args)
args = cwords[1:]
args = cwords[1:-1] if incomplete else cwords[1:]
return args, incomplete

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

0 comments on commit 70ffd68

Please sign in to comment.