From d566f5bffffdfb0b33196ccbb71e11a3d47e3f5e Mon Sep 17 00:00:00 2001 From: Ryan Miguel Date: Sat, 22 Oct 2022 14:50:06 -0700 Subject: [PATCH] Revert to using argparse's mutually exclusive options. --- pre_commit_hooks/file_contents_sorter.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pre_commit_hooks/file_contents_sorter.py b/pre_commit_hooks/file_contents_sorter.py index 7477657..5435188 100644 --- a/pre_commit_hooks/file_contents_sorter.py +++ b/pre_commit_hooks/file_contents_sorter.py @@ -49,25 +49,25 @@ def sort_file_contents( def main(argv: Sequence[str] | None = None) -> int: - parser = argparse.ArgumentParser() + parser = argparse.ArgumentParser(exit_on_error=False) parser.add_argument('filenames', nargs='+', help='Files to sort') - parser.add_argument( + group = parser.add_mutually_exclusive_group() + group.add_argument( '--ignore-case', action='store_const', const=bytes.lower, default=None, help='fold lower case to upper case characters', ) - parser.add_argument( + group.add_argument( '--unique', action='store_true', help='ensure each line is unique', ) - args = parser.parse_args(argv) - - if args.ignore_case and args.unique: - print('ERROR: usage of --unique and --ignore-case is unsupported. \ - Please update your configuration.') + try: + args = parser.parse_args(argv) + except argparse.ArgumentError as e: + print(f'{e}') return FAIL retv = PASS