Skip to content

Commit ed58f32

Browse files
committed
move examples to separate section of api doc
1 parent 6231314 commit ed58f32

File tree

2 files changed

+939
-114
lines changed

2 files changed

+939
-114
lines changed

contrib/devtools/generate_json_api_v1.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,29 @@ def parse_params(args):
5050
return arguments
5151

5252

53+
def process_examples(examples: str):
54+
if not examples:
55+
return []
56+
examples = examples.strip()
57+
splits = examples.split('\n')
58+
result = []
59+
inner = {}
60+
for s in splits:
61+
if not s:
62+
continue
63+
if '> curl' in s:
64+
inner['curl'] = s.strip()
65+
elif '> lbrycrd' in s:
66+
inner['cli'] = s.strip()
67+
else:
68+
if 'title' in inner:
69+
result.append(inner)
70+
inner = {}
71+
inner['title'] = s.strip()
72+
result.append(inner)
73+
return result
74+
75+
5376
def get_api(section_name, command, command_help):
5477

5578
parsed = re_full.fullmatch(command_help)
@@ -61,15 +84,15 @@ def get_api(section_name, command, command_help):
6184
arguments = parse_params(args)
6285

6386
cmd_desc = re.sub('\s+', ' ', desc.strip()) if desc else ''
64-
if exmp and '--skip_examples' not in sys.argv:
65-
cmd_desc += '\nExamples:\n' + exmp.strip()
87+
examp_desc = process_examples(exmp)
6688
cmd_resl = resl.strip() if resl else None
6789

6890
ret = {
6991
'name': command,
7092
'namespace': section_name,
7193
'description': cmd_desc,
7294
'arguments': arguments,
95+
'examples': examp_desc
7396
}
7497
if cmd_resl is not None:
7598
ret['returns'] = cmd_resl

0 commit comments

Comments
 (0)