Skip to content

Commit

Permalink
Add -e.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwilk committed Jan 13, 2023
1 parent 85c239b commit a1ed3e3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doc/manpage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ that finds incorrect indefinite articles.
Options
-------

-e
Exit with non-zero status if any incorrect articles were found.
--ipa
Print phonemes using IPA (International Phonetic Alphabet)
instead of ASCII phoneme mnemonics.
Expand Down
8 changes: 7 additions & 1 deletion lib/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def check_word(loc, art, word, *, ipa=False):
elif art.lower() != correct_art:
correct_art = coerce_case(art, correct_art)
print(f'{loc}: {art} {word} -> {correct_art} {word} /{phon}/')
return False
return True

def main():
'''
Expand All @@ -87,6 +89,7 @@ def main():
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
ap = ArgumentParser(description='"a" vs "an" checker')
ap.add_argument('--version', action=VersionAction)
ap.add_argument('-e', action='store_true', help='exit with non-zero status if issues were found')
ap.add_argument('--ipa', action='store_true', help='use IPA instead of ASCII phoneme mnemonics')
ap.add_argument('--traceback', action='store_true', help=argparse.SUPPRESS)
ap.add_argument('files', metavar='FILE', nargs='*', default=['-'],
Expand All @@ -96,6 +99,7 @@ def main():
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding, line_buffering=sys.stdout.line_buffering)
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding, line_buffering=sys.stdout.line_buffering)
init_phonetics()
ok = True
rc = 0
for path in options.files:
try:
Expand All @@ -109,7 +113,9 @@ def main():
continue
with file:
for loc, art, word in parse_file(file):
check_word(loc, art, word, ipa=options.ipa)
ok &= check_word(loc, art, word, ipa=options.ipa)
if rc == 0 and options.e and not ok:
rc = 2
sys.exit(rc)

__all__ = ['main']
Expand Down
8 changes: 8 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ def test_bad_io():
assert_is_instance(actual.rc, OSError)
assert_equal(actual.rc.errno, errno.ENOENT)

@testcase
def test_e():
argv = ['anorack', '-e']
actual = run_main(argv, 'a African')
assert_equal('<stdin>:', actual.stdout[:8])
assert_equal('', actual.stderr)
assert_equal(actual.rc, 2)

@testcase
def test_changelog():
argv = ['anorack', 'doc/changelog']
Expand Down

0 comments on commit a1ed3e3

Please sign in to comment.