From b440e1bb2211918ef2b34138a65e0cb6c3a66057 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Thu, 24 Feb 2022 17:02:19 +0530 Subject: [PATCH] [devscripts] Improve `prepare_manpage` Closes #2873 --- devscripts/prepare_manpage.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/devscripts/prepare_manpage.py b/devscripts/prepare_manpage.py index 069d99eeb..6612723f7 100644 --- a/devscripts/prepare_manpage.py +++ b/devscripts/prepare_manpage.py @@ -75,21 +75,17 @@ def filter_options(readme): section = re.search(r'(?sm)^# USAGE AND OPTIONS\n.+?(?=^# )', readme).group(0) options = '# OPTIONS\n' for line in section.split('\n')[1:]: - if line.lstrip().startswith('-'): - split = re.split(r'\s{2,}', line.lstrip()) - # Description string may start with `-` as well. If there is - # only one piece then it's a description bit not an option. - if len(split) > 1: - option, description = split - split_option = option.split(' ') + mobj = re.fullmatch(r'\s{4}(?P-(?:,\s|[^\s])+)(?:\s(?P([^\s]|\s(?!\s))+))?(\s{2,}(?P.+))?', line) + if not mobj: + options += f'{line.lstrip()}\n' + continue + option, metavar, description = mobj.group('opt', 'meta', 'desc') - if not split_option[-1].startswith('-'): # metavar - option = ' '.join(split_option[:-1] + [f'*{split_option[-1]}*']) - - # Pandoc's definition_lists. See http://pandoc.org/README.html - options += f'\n{option}\n: {description}\n' - continue - options += line.lstrip() + '\n' + # Pandoc's definition_lists. See http://pandoc.org/README.html + option = f'{option} *{metavar}*' if metavar else option + description = f'{description}\n' if description else '' + options += f'\n{option}\n: {description}' + continue return readme.replace(section, options, 1)