From 8283ea766b5f576789de12e26b867818fe956994 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matth=C3=A4us=20G=2E=20Chajdas?= Date: Sat, 23 Jan 2021 13:34:39 +0100 Subject: Update based on review feedback. * Extract "is_only_option" method * Check -L argument to be a "known good" argument --- pygments/cmdline.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/pygments/cmdline.py b/pygments/cmdline.py index ad893e36..db6de0cd 100644 --- a/pygments/cmdline.py +++ b/pygments/cmdline.py @@ -145,23 +145,30 @@ def main_inner(parser, argns): 'Chajdas and contributors.' % __version__) return 0 + def is_only_option(opt): + return not any(v for (k, v) in vars(argns).items() if k != opt) + # handle ``pygmentize -L`` if argns.L is not None: - if any(v for (k, v) in vars(argns).items() if k != 'L'): + if not is_only_option('L'): parser.print_help(sys.stderr) return 2 # print version main(['', '-V']) - largs = argns.L + allowed_types = {'lexer', 'formatter', 'filter', 'style'} + largs = [arg.rstrip('s') for arg in argns.L] + if any(arg not in allowed_types for arg in largs): + parser.print_help(sys.stderr) + return 0 if not largs: - largs = ['lexer', 'formatter', 'filter', 'style'] + largs = allowed_types for arg in largs: - _print_list(arg.rstrip('s')) + _print_list(arg) return 0 # handle ``pygmentize -H`` if argns.H: - if any(v for (k, v) in vars(argns).items() if k != 'H'): + if not is_only_option('H'): parser.print_help(sys.stderr) return 2 what, name = argns.H -- cgit v1.2.1