Skip to content

Commit

Permalink
Merge pull request #428 from amperser/exit-codes
Browse files Browse the repository at this point in the history
Use exit codes
  • Loading branch information
suchow committed Mar 31, 2016
2 parents 571566c + 0187fac commit c2a39e0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
8 changes: 8 additions & 0 deletions proselint/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,22 @@ def proselint(paths=None, version=None, initialize=None, clean=None,
filepaths = extract_files(list(paths))

# Lint the files
num_errors = 0
for fp in filepaths:
try:
f = click.open_file(fp, 'r+', encoding="utf-8")
errors = lint(f, debug=debug)
num_errors += len(errors)
show_errors(fp, errors, output_json, compact=compact)
except:
pass

# Return an exit code
if num_errors > 0:
sys.exit(1)
else:
sys.exit(0)


def extract_files(files):
"""Expand list of paths to include all text files matching the pattern."""
Expand Down
2 changes: 1 addition & 1 deletion proselint/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Proselint version number."""

__version__ = "0.4.4"
__version__ = "0.5.0"
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.4.4
current_version = 0.5.0
commit = True
tag = True
tag_name = {new_version}
Expand Down
21 changes: 21 additions & 0 deletions tests/test_exit_codes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Check that the CLI returns the appropriate exit code."""

import subprocess


def test_exit_code_demo():
"""Ensure that linting the demo returns an exit code of 1."""
try:
subprocess.check_output("proselint --demo", shell=True)

except subprocess.CalledProcessError as grepexc:
assert(grepexc.returncode == 1)


def test_exit_code_version():
"""Ensure that getting the version returns an exit code of 0."""
try:
subprocess.check_output("proselint --version", shell=True)

except subprocess.CalledProcessError:
assert(False)

0 comments on commit c2a39e0

Please sign in to comment.