Generate lines for rpc title and synopsis with request parameters
(schema, name)
| 348 | |
| 349 | |
| 350 | def generate_header(schema, name): |
| 351 | """Generate lines for rpc title and synopsis with request parameters""" |
| 352 | output_title(esc_underscores(''.join([name, ' -- ', schema['title']])), '=', 0, 1) |
| 353 | if schema.get('rpc'): |
| 354 | output_title('SYNOPSIS') |
| 355 | # Add command level warning if exists |
| 356 | if 'warning' in schema: |
| 357 | output('**(WARNING: {})**\n\n'.format(esc_underscores(schema['warning']))) |
| 358 | # generate the rpc command details with request parameters |
| 359 | request = schema.get('request', {}) |
| 360 | properties = request.get('properties', {}) |
| 361 | toplevels = list(properties.keys()) |
| 362 | output('{} '.format(fmt_propname(name))) |
| 363 | i = 0 |
| 364 | while i < len(toplevels): |
| 365 | # Skip hidden properties |
| 366 | if 'hidden' in properties[toplevels[i]] and properties[toplevels[i]]['hidden']: |
| 367 | i += 1 |
| 368 | continue |
| 369 | # Search for the parameter in 'dependentUpon' array |
| 370 | dependent_upon_obj = request['dependentUpon'] if 'dependentUpon' in request else [] |
| 371 | if toplevels[i] in dependent_upon_obj: |
| 372 | # Output parameters with appropriate separator |
| 373 | output('{}*{}* '.format('' if 'required' in request and toplevels[i] in request['required'] else '[', esc_underscores(toplevels[i]))) |
| 374 | output_conditional_params(dependent_upon_obj[toplevels[i]], 'dependentUpon') |
| 375 | toplevels = [key for key in toplevels if key not in dependent_upon_obj[toplevels[i]]] |
| 376 | output('{}'.format('' if 'required' in request and toplevels[i] in request['required'] else '] ')) |
| 377 | else: |
| 378 | # Search for the parameter in any conditional sub-arrays (oneOfMany, pairedWith) |
| 379 | condition, foundinsubarray = search_key_in_conditional_array(request, toplevels[i]) |
| 380 | # If param found in the conditional sub-array |
| 381 | if condition != '' and foundinsubarray is not None: |
| 382 | # Output parameters with appropriate separator |
| 383 | output_conditional_params(foundinsubarray, condition) |
| 384 | # Remove found keys from toplevels array |
| 385 | toplevels = [key for key in toplevels if key not in foundinsubarray] |
| 386 | # Reset the cursor to the previous index |
| 387 | i = i - 1 |
| 388 | else: |
| 389 | # Print the key as it is if it doesn't exist in conditional array |
| 390 | output('{}'.format(fmt_paramname(toplevels[i], False if 'required' in request and toplevels[i] in request['required'] else True))) |
| 391 | i += 1 |
| 392 | # plugin.json is an exception where all parameters cannot be printed deu to their dependency on different subcommands |
| 393 | # So, add ... at the end for plugin schema |
| 394 | if schema.get('rpc') == 'plugin': |
| 395 | output('...') |
| 396 | output('\n') |
| 397 | |
| 398 | |
| 399 | def generate_description(schema): |
no test coverage detected