mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-03-29 10:16:52 +00:00
Revert to using argparse's mutually exclusive options.
This commit is contained in:
parent
3d305e15ef
commit
d566f5bfff
1 changed files with 8 additions and 8 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue