Skip to content

Commit

Permalink
Merge pull request #111 from bwhmather/version-flag
Browse files Browse the repository at this point in the history
Add `--version` flag to executable
  • Loading branch information
bwhmather committed Jan 22, 2024
2 parents 018ca2d + 0add90b commit 8f7e380
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/ssort/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
import sys

from ssort import __version__
from ssort._exceptions import UnknownEncodingError
from ssort._files import find_python_files
from ssort._ssort import ssort
Expand All @@ -19,6 +20,12 @@ def main():
description="Sort python statements into dependency order",
)

parser.add_argument(
"--version",
dest="version",
action="store_true",
help="Outputs version information and then exit",
)
parser.add_argument(
"--diff",
dest="show_diff",
Expand All @@ -38,6 +45,10 @@ def main():

args = parser.parse_args()

if args.version:
sys.stdout.write(f"ssort {__version__}\n")
return

unsorted = 0
unsortable = 0
unchanged = 0
Expand Down
11 changes: 11 additions & 0 deletions tests/test_executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest

from ssort import __version__
from ssort._utils import escape_path

_good = b"""
Expand Down Expand Up @@ -393,6 +394,16 @@ def test_ssort_unreadable_file(ssort, tmp_path):
assert (actual_msgs, actual_status) == (expected_msgs, expected_status)


def test_ssort_version():
result = subprocess.run(
["ssort", "--version"],
capture_output=True,
encoding="utf-8",
)
output = result.stdout
assert output == f"ssort {__version__}\n"


def test_ssort_run_module():
entrypoint_result = subprocess.run(
["ssort", "--help"],
Expand Down

0 comments on commit 8f7e380

Please sign in to comment.