- with napi.NominatimAPI(args.project_dir) as api:
- params: Dict[str, Any] = {'max_results': args.limit + min(args.limit, 10),
- 'address_details': True, # needed for display name
- 'geometry_output': _get_geometry_output(args),
- 'geometry_simplification': args.polygon_threshold,
- 'countries': args.countrycodes,
- 'excluded': args.exclude_place_ids,
- 'viewbox': args.viewbox,
- 'bounded_viewbox': args.bounded,
- 'locales': _get_locales(args, api.config.DEFAULT_LANGUAGE)
- }
-
- if args.query:
- results = api.search(args.query, **params)
- else:
- results = api.search_address(amenity=args.amenity,
- street=args.street,
- city=args.city,
- county=args.county,
- state=args.state,
- postalcode=args.postalcode,
- country=args.country,
- **params)
+ try:
+ with napi.NominatimAPI(args.project_dir) as api:
+ params: Dict[str, Any] = {'max_results': args.limit + min(args.limit, 10),
+ 'address_details': True, # needed for display name
+ 'geometry_output': _get_geometry_output(args),
+ 'geometry_simplification': args.polygon_threshold,
+ 'countries': args.countrycodes,
+ 'excluded': args.exclude_place_ids,
+ 'viewbox': args.viewbox,
+ 'bounded_viewbox': args.bounded,
+ 'locales': _get_locales(args, api.config.DEFAULT_LANGUAGE)
+ }
+
+ if args.query:
+ results = api.search(args.query, **params)
+ else:
+ results = api.search_address(amenity=args.amenity,
+ street=args.street,
+ city=args.city,
+ county=args.county,
+ state=args.state,
+ postalcode=args.postalcode,
+ country=args.country,
+ **params)
+ except napi.UsageError as ex:
+ raise UsageError(ex) from ex