in generate_commands_from_synopsis.py [0:0]
def get_options(name, manpage, alias_to_idx):
change_name = {
'grep': 'egrep',
'gcc': 'aarch64-linux-gnu-gcc-8',
'vim': 'rvim',
'rename': 'file-rename'
}
name = change_name.get(name, name)
x = manpage[manpage['name'] == name]
if len(x) < 1:
x = alias_to_idx.get(name, None)
if x is None or len(x) < 1:
return None
else:
x = manpage.loc[x]
options = []
paragraphs = x.iloc[0]['paragraphs']
for p in paragraphs:
text = p['text'].strip()
if not p['is_option']:
super_option_regex = r"^(?:\<[^>]+\>)?(-{1,2}\w+)(?:\<\/[^>]+\>)?[\t ]*"
match = re.match(super_option_regex, text)
if not match:
continue
p['short'] = []
p['long'] = []
p['expectsarg'] = None
p['argument'] = None
while match:
found_text = match.group(1)
if found_text.startswith("--"):
p['long'].append(found_text)
else:
p['short'].append(found_text)
text = re.sub(super_option_regex, "", text, 1)
match = re.match(super_option_regex, text)
if 'short' not in p:
continue
option = {
'short': p['short'],
'long': p['long'],
'expectsarg': p['expectsarg'],
'argument': p['argument']
}
if '\n' in text:
text = text[text.find('\n') + 1:].strip()
while text.startswith('<'):
if '\n' in text:
text = text[text.find('\n') + 1:].strip()
else:
text = re.sub("^\<[^>]+\>.*?\<\/[^>]+\>\s*", "", text).strip()
option['text'] = text
options.append(option)
return options