X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/bc7f6209d83dcc161f093ce9907991facabb3491..e1fc1566f3759700fa82d4875057192d0853b2f1:/nominatim/clicmd/api.py diff --git a/nominatim/clicmd/api.py b/nominatim/clicmd/api.py index b899afad..cc65f5f6 100644 --- a/nominatim/clicmd/api.py +++ b/nominatim/clicmd/api.py @@ -2,7 +2,7 @@ # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 2022 by the Nominatim developer community. +# Copyright (C) 2023 by the Nominatim developer community. # For a full list of authors see the git log. """ Subcommand definitions for API calls from the command line. @@ -14,6 +14,8 @@ import logging from nominatim.tools.exec_utils import run_api_script from nominatim.errors import UsageError from nominatim.clicmd.args import NominatimArgs +from nominatim.api import NominatimAPI, StatusResult +import nominatim.api.v1 as api_output # Do not repeat documentation of subcommand classes. # pylint: disable=C0111 @@ -248,9 +250,9 @@ class APIDetails: if args.node: params = dict(osmtype='N', osmid=args.node) elif args.way: - params = dict(osmtype='W', osmid=args.node) + params = dict(osmtype='W', osmid=args.way) elif args.relation: - params = dict(osmtype='R', osmid=args.node) + params = dict(osmtype='R', osmid=args.relation) else: params = dict(place_id=args.place_id) if args.object_class: @@ -264,7 +266,7 @@ class APIDetails: class APIStatus: - """\ + """ Execute API status query. This command works exactly the same as if calling the /status endpoint on @@ -274,10 +276,13 @@ class APIStatus: """ def add_args(self, parser: argparse.ArgumentParser) -> None: + formats = api_output.list_formats(StatusResult) group = parser.add_argument_group('API parameters') - group.add_argument('--format', default='text', choices=['text', 'json'], + group.add_argument('--format', default=formats[0], choices=formats, help='Format of result') def run(self, args: NominatimArgs) -> int: - return _run_api('status', args, dict(format=args.format)) + status = NominatimAPI(args.project_dir).status() + print(api_output.format_result(status, args.format)) + return 0