def get_argument_parser(): root = ArgumentParser( 'lbrynet', description='An interface to the LBRY Network.', allow_abbrev=False, ) root.add_argument( '-v', '--version', dest='cli_version', action="store_true", help='Show lbrynet CLI version and exit.' ) root.set_defaults(group=None, command=None) CLIConfig.contribute_to_argparse(root) sub = root.add_subparsers(metavar='COMMAND') start = sub.add_parser( 'start', usage='lbrynet start [--config FILE] [--data-dir DIR] [--wallet-dir DIR] [--download-dir DIR] ...', help='Start LBRY Network interface.' ) start.add_argument( '--quiet', dest='quiet', action="store_true", help='Disable all console output.' ) start.add_argument( '--no-logging', dest='no_logging', action="store_true", help='Disable all logging of any kind.' ) start.add_argument( '--verbose', nargs="*", help=('Enable debug output for lbry logger and event loop. Optionally specify loggers for which debug output ' 'should selectively be applied.') ) start.add_argument( '--initial-headers', dest='initial_headers', help='Specify path to initial blockchain headers, faster than downloading them on first run.' ) Config.contribute_to_argparse(start) start.set_defaults(command='start', start_parser=start, doc=start.format_help()) api = Daemon.get_api_definitions() groups = {} for group_name in sorted(api['groups']): group_parser = sub.add_parser(group_name, group_name=group_name, help=api['groups'][group_name]) groups[group_name] = group_parser.add_subparsers(metavar='COMMAND') nicer_order = ['stop', 'get', 'publish', 'resolve'] for command_name in sorted(api['commands']): if command_name not in nicer_order: nicer_order.append(command_name) for command_name in nicer_order: command = api['commands'][command_name] if command['group'] is None: add_command_parser(sub, command) else: add_command_parser(groups[command['group']], command) return root
def write_api(f): examples = get_examples() api_definitions = Daemon.get_api_definitions() apis = {'main': {'doc': 'Ungrouped commands.', 'commands': []}} for group_name, group_doc in api_definitions['groups'].items(): apis[group_name] = {'doc': group_doc, 'commands': []} for method_name, command in api_definitions['commands'].items(): if 'replaced_by' in command: continue apis[command['group'] or 'main']['commands'].append( get_api(method_name, examples.get(method_name, []))) json.dump(apis, f, indent=4)