[devscripts] Improve prepare_manpage

Closes #2873
This commit is contained in:
pukkandan 2022-02-24 17:02:19 +05:30
parent 03f830040a
commit b440e1bb22
No known key found for this signature in database
GPG key ID: 7EEE9E1E817D0A39

View file

@ -75,21 +75,17 @@ def filter_options(readme):
section = re.search(r'(?sm)^# USAGE AND OPTIONS\n.+?(?=^# )', readme).group(0) section = re.search(r'(?sm)^# USAGE AND OPTIONS\n.+?(?=^# )', readme).group(0)
options = '# OPTIONS\n' options = '# OPTIONS\n'
for line in section.split('\n')[1:]: for line in section.split('\n')[1:]:
if line.lstrip().startswith('-'): mobj = re.fullmatch(r'\s{4}(?P<opt>-(?:,\s|[^\s])+)(?:\s(?P<meta>([^\s]|\s(?!\s))+))?(\s{2,}(?P<desc>.+))?', line)
split = re.split(r'\s{2,}', line.lstrip()) if not mobj:
# Description string may start with `-` as well. If there is options += f'{line.lstrip()}\n'
# only one piece then it's a description bit not an option. continue
if len(split) > 1: option, metavar, description = mobj.group('opt', 'meta', 'desc')
option, description = split
split_option = option.split(' ')
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 # Pandoc's definition_lists. See http://pandoc.org/README.html
options += f'\n{option}\n: {description}\n' option = f'{option} *{metavar}*' if metavar else option
description = f'{description}\n' if description else ''
options += f'\n{option}\n: {description}'
continue continue
options += line.lstrip() + '\n'
return readme.replace(section, options, 1) return readme.replace(section, options, 1)