Skip to content

Commit

Permalink
fix: include --version flag (#9)
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii authored Apr 18, 2023
1 parent f9c52ba commit 1af81ec
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/check_sdist/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

from __future__ import annotations

__version__ = "0.1.1"
__version__ = "0.1.2"

__all__ = ["__version__"]
11 changes: 8 additions & 3 deletions src/check_sdist/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import argparse
import contextlib
from collections.abc import Sequence
from pathlib import Path

import pathspec

from . import __version__
from ._compat import tomllib
from .git import git_files
from .inject import inject_junk_files
Expand Down Expand Up @@ -69,9 +71,12 @@ def compare(source_dir: Path, *, isolated: bool, verbose: bool = False) -> int:
return 0


def main() -> None:
def main(sys_args: Sequence[str] | None = None, /) -> None:
"""Parse the command line arguments and call compare()."""
parser = argparse.ArgumentParser()
parser = argparse.ArgumentParser(prog=None if sys_args is None else "check-sdist")
parser.add_argument(
"--version", action="version", version=f"%(prog)s {__version__}"
)
parser.add_argument(
"--source-dir",
type=Path,
Expand All @@ -94,7 +99,7 @@ def main() -> None:
action="store_true",
help="Print out SDist contents too",
)
args = parser.parse_args()
args = parser.parse_args(sys_args)

with contextlib.ExitStack() as stack:
if args.inject_junk:
Expand Down
15 changes: 15 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from __future__ import annotations

import pytest

from check_sdist import __version__
from check_sdist.__main__ import main


def test_version(capsys):
with pytest.raises(SystemExit):
main(["--version"])

out, err = capsys.readouterr()
assert out == f"check-sdist {__version__}\n"
assert not err

0 comments on commit 1af81ec

Please sign in to comment.