mirror of
https://github.com/osm-search/Nominatim.git
synced 2024-11-22 12:06:27 +03:00
add new format 'raw' for CLI commands
This dumps the original results with all details available.
This commit is contained in:
parent
b2dc01ad81
commit
15eb7f0bb1
@ -12,6 +12,7 @@ import argparse
|
||||
import logging
|
||||
import json
|
||||
import sys
|
||||
import pprint
|
||||
from functools import reduce
|
||||
|
||||
import nominatim_api as napi
|
||||
@ -113,12 +114,17 @@ def _list_formats(formatter: napi.FormatDispatcher, rtype: Type[Any]) -> int:
|
||||
for fmt in formatter.list_formats(rtype):
|
||||
print(fmt)
|
||||
print('debug')
|
||||
print('raw')
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def _print_output(formatter: napi.FormatDispatcher, result: Any,
|
||||
fmt: str, options: Mapping[str, Any]) -> None:
|
||||
|
||||
if fmt == 'raw':
|
||||
pprint.pprint(result)
|
||||
else:
|
||||
output = formatter.format_result(result, fmt, options)
|
||||
if formatter.get_content_type(fmt) == CONTENT_JSON:
|
||||
# reformat the result, so it is pretty-printed
|
||||
@ -174,7 +180,7 @@ class APISearch:
|
||||
if args.list_formats:
|
||||
return _list_formats(formatter, napi.SearchResults)
|
||||
|
||||
if args.format == 'debug':
|
||||
if args.format in ('debug', 'raw'):
|
||||
loglib.set_log_output('text')
|
||||
elif not formatter.supports_format(napi.SearchResults, args.format):
|
||||
raise UsageError(f"Unsupported format '{args.format}'. "
|
||||
@ -254,7 +260,7 @@ class APIReverse:
|
||||
if args.list_formats:
|
||||
return _list_formats(formatter, napi.ReverseResults)
|
||||
|
||||
if args.format == 'debug':
|
||||
if args.format in ('debug', 'raw'):
|
||||
loglib.set_log_output('text')
|
||||
elif not formatter.supports_format(napi.ReverseResults, args.format):
|
||||
raise UsageError(f"Unsupported format '{args.format}'. "
|
||||
@ -320,7 +326,7 @@ class APILookup:
|
||||
if args.list_formats:
|
||||
return _list_formats(formatter, napi.ReverseResults)
|
||||
|
||||
if args.format == 'debug':
|
||||
if args.format in ('debug', 'raw'):
|
||||
loglib.set_log_output('text')
|
||||
elif not formatter.supports_format(napi.ReverseResults, args.format):
|
||||
raise UsageError(f"Unsupported format '{args.format}'. "
|
||||
@ -402,7 +408,7 @@ class APIDetails:
|
||||
if args.list_formats:
|
||||
return _list_formats(formatter, napi.DetailedResult)
|
||||
|
||||
if args.format == 'debug':
|
||||
if args.format in ('debug', 'raw'):
|
||||
loglib.set_log_output('text')
|
||||
elif not formatter.supports_format(napi.DetailedResult, args.format):
|
||||
raise UsageError(f"Unsupported format '{args.format}'. "
|
||||
@ -473,7 +479,7 @@ class APIStatus:
|
||||
if args.list_formats:
|
||||
return _list_formats(formatter, napi.StatusResult)
|
||||
|
||||
if args.format == 'debug':
|
||||
if args.format in ('debug', 'raw'):
|
||||
loglib.set_log_output('text')
|
||||
elif not formatter.supports_format(napi.StatusResult, args.format):
|
||||
raise UsageError(f"Unsupported format '{args.format}'. "
|
||||
|
Loading…
Reference in New Issue
Block a user