Skip to content

Commit

Permalink
move examples to separate section of api doc
Browse files Browse the repository at this point in the history
  • Loading branch information
BrannonKing committed Feb 12, 2019
1 parent 6231314 commit ed58f32
Show file tree
Hide file tree
Showing 2 changed files with 939 additions and 114 deletions.
27 changes: 25 additions & 2 deletions contrib/devtools/generate_json_api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,29 @@ def parse_params(args):
return arguments


def process_examples(examples: str):
if not examples:
return []
examples = examples.strip()
splits = examples.split('\n')
result = []
inner = {}
for s in splits:
if not s:
continue
if '> curl' in s:
inner['curl'] = s.strip()
elif '> lbrycrd' in s:
inner['cli'] = s.strip()
else:
if 'title' in inner:
result.append(inner)
inner = {}
inner['title'] = s.strip()
result.append(inner)
return result


def get_api(section_name, command, command_help):

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

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

ret = {
'name': command,
'namespace': section_name,
'description': cmd_desc,
'arguments': arguments,
'examples': examp_desc
}
if cmd_resl is not None:
ret['returns'] = cmd_resl
Expand Down
Loading

0 comments on commit ed58f32

Please sign in to comment.