Exemplo n.º 1
0
def get_argument_parser():
    main = ArgumentParser(
        'lbrynet',
        description='An interface to the LBRY Network.',
        allow_abbrev=False,
    )
    main.add_argument('-v',
                      '--version',
                      dest='cli_version',
                      action="store_true",
                      help='Show lbrynet CLI version and exit.')
    main.set_defaults(group=None, command=None)
    CLIConfig.contribute_to_argparse(main)
    sub = main.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(
        '--verbose',
        nargs="*",
        help=
        ('Enable debug output. Optionally specify loggers for which debug output '
         'should selectively be applied.'))
    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 main
Exemplo n.º 2
0
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)