Skip to content

Commit cf183a9

Browse files
committed
chore(cli): align check_eip_versions with other pytest clis
1 parent 22892db commit cf183a9

File tree

4 files changed

+44
-22
lines changed

4 files changed

+44
-22
lines changed
Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
"""CLI entry point for the EIP version checker pytest-based command."""
22

33
import sys
4+
from typing import List
45

56
import click
67
import pytest
78

9+
from .common import common_click_options, handle_help_flags
810

9-
@click.command(
10-
context_settings={
11-
"help_option_names": ["-h", "--help"],
12-
}
13-
)
14-
@click.option(
15-
"--github-token",
16-
help="GitHub API token required to avoid rate limiting when checking EIP versions",
17-
envvar="GITHUB_TOKEN",
18-
required=True,
19-
)
20-
def check_eip_versions(github_token: str) -> None:
21-
"""Run pytest with the `spec_version_checker` plugin."""
22-
args = ["-c", "pytest-check-eip-versions.ini", "--github-token", github_token]
2311

12+
@click.command(context_settings={"ignore_unknown_options": True})
13+
@common_click_options
14+
def check_eip_versions(pytest_args: List[str], **kwargs) -> None:
15+
"""Run pytest with the `spec_version_checker` plugin."""
16+
args = ["-c", "pytest-check-eip-versions.ini"]
17+
args += handle_help_flags(list(pytest_args), pytest_type="check-eip-versions")
2418
result = pytest.main(args)
2519
sys.exit(result)

src/cli/pytest_commands/common.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def common_click_options(func: Callable[..., Any]) -> Decorator:
3737

3838

3939
REQUIRED_FLAGS: Dict[str, List] = {
40+
"check-eip-versions": [],
4041
"fill": [],
4142
"consume": [],
4243
"execute": [
@@ -74,7 +75,15 @@ def handle_help_flags(pytest_args: List[str], pytest_type: str) -> List[str]:
7475
if ctx.params.get("help_flag"):
7576
return (
7677
[f"--{pytest_type}-help", *REQUIRED_FLAGS[pytest_type]]
77-
if pytest_type in {"consume", "fill", "execute", "execute-hive", "execute-recover"}
78+
if pytest_type
79+
in {
80+
"check-eip-versions",
81+
"consume",
82+
"fill",
83+
"execute",
84+
"execute-hive",
85+
"execute-recover",
86+
}
7887
else pytest_args
7988
)
8089
elif ctx.params.get("pytest_help_flag"):

src/pytest_plugins/help/help.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
def pytest_addoption(parser):
1313
"""Add command-line options to pytest for specific help commands."""
1414
help_group = parser.getgroup("help_options", "Help options for different commands")
15+
help_group.addoption(
16+
"--check-eip-versions-help",
17+
action="store_true",
18+
dest="show_check_eip_versions_help",
19+
default=False,
20+
help="Show help options only for the check_eip_versions command and exit.",
21+
)
1522
help_group.addoption(
1623
"--fill-help",
1724
action="store_true",
@@ -52,7 +59,16 @@ def pytest_addoption(parser):
5259
@pytest.hookimpl(tryfirst=True)
5360
def pytest_configure(config):
5461
"""Handle specific help flags by displaying the corresponding help message."""
55-
if config.getoption("show_fill_help"):
62+
if config.getoption("show_check_eip_versions_help"):
63+
show_specific_help(
64+
config,
65+
"pytest-check-eip-versions.ini",
66+
[
67+
"spec_version_checker",
68+
"EIP spec version",
69+
],
70+
)
71+
elif config.getoption("show_fill_help"):
5672
show_specific_help(
5773
config,
5874
"pytest.ini",

src/pytest_plugins/spec_version_checker/spec_version_checker.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@
1616

1717

1818
def pytest_addoption(parser):
19-
"""Add GitHub token option to pytest command line options."""
20-
group = parser.getgroup("github")
19+
"""Add Github token option to pytest command line options."""
20+
group = parser.getgroup(
21+
"spec_version_checker", "Arguments defining the EIP spec version checker"
22+
)
2123
group.addoption(
2224
"--github-token",
2325
action="store",
2426
dest="github_token",
2527
default=None,
26-
help="GitHub API token to avoid rate limiting",
28+
help="A Github API personal access token to avoid rate limiting",
2729
)
2830

2931

@@ -44,9 +46,10 @@ def pytest_configure(config):
4446

4547
if not github_token:
4648
pytest.exit(
47-
"A GitHub personal access token is required but has not been provided. "
48-
"Either set the GITHUB_TOKEN environment variable or use --github-token option. "
49-
"Generate a token at https://github.com/settings/personal-access-tokens/new"
49+
"A Github personal access token is required but has not been provided. "
50+
"Either set the GITHUB_TOKEN environment variable or specify one via --github-token. "
51+
"Generate a token for your Github account at "
52+
"https://github.com/settings/personal-access-tokens/new"
5053
)
5154

5255
config.github_token = github_token

0 commit comments

Comments
 (0)