Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix PowerShell completion with incomplete word #360

Merged
merged 10 commits into from
Aug 24, 2024
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
Loading