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 help of the completion argument #19

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/cappa/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ def create_completion_arg(completion: bool | Arg = True) -> Arg | None:
return None

if isinstance(completion, bool):
completion = Arg(
return Arg(
name="completion",
long=["--completion"],
choices=["generate", "complete"],
group=(3, "Help"),
help="Use `--completion generate` to print shell-specific completion source",
).normalize()
help="Use `--completion generate` to print shell-specific completion source.",
).normalize(action=ArgAction.completion)

return completion.normalize(action=ArgAction.completion)

Expand Down
25 changes: 25 additions & 0 deletions tests/help/test_completion_choices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from __future__ import annotations

import re
from dataclasses import dataclass

import cappa
import pytest

from tests.utils import parse


def test_string_group(capsys):
@dataclass
class Args:
...

with pytest.raises(cappa.HelpExit) as e:
parse(Args, "--help", backend=cappa.backend)

assert e.value.code == 0

out = capsys.readouterr().out

options = re.findall(r"Valid\s+options:\s+generate,\s+complete", out, re.MULTILINE)
assert len(options) == 1