From 88397ce0e17027a0ed4802f81d4b4c1d2c4a8754 Mon Sep 17 00:00:00 2001 From: marc tobias Date: Thu, 5 Sep 2024 16:31:16 +0200 Subject: [PATCH] rename CLI parameter "extra-params" to "optional-api-params" --- README.md | 24 +++++++++++------------- opencage/batch.py | 2 +- opencage/command_line.py | 21 +++++++++++---------- test/cli/test_cli_args.py | 6 +++--- 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 0b51433..096c415 100644 --- a/README.md +++ b/README.md @@ -117,23 +117,21 @@ Use `opencage forward` or `opencage reverse` ``` opencage forward --help +options: -h, --help show this help message and exit --api-key API_KEY Your OpenCage API key - --input INPUT Input file name - --output OUTPUT Output file name + --input FILENAME Input file name + --output FILENAME Output file name --headers If the first row should be treated as a header row - --input-columns INPUT_COLUMNS - Comma-separated list of integers (default '1') - --add-columns ADD_COLUMNS - Comma-separated list of output columns - --workers WORKERS Number of parallel geocoding requests (default 1) - --timeout TIMEOUT Timeout in seconds (default 10) - --retries RETRIES Number of retries (default 5) - --api-domain API_DOMAIN - API domain (default api.opencagedata.com) - --extra-params EXTRA_PARAMS + --input-columns Comma-separated list of integers (default '1') + --add-columns Comma-separated list of output columns (default 'lat,lng,_type,_category,country_code,country,state,county,_normalized_city,postcode,road,house_number,confidence,formatted') + --workers Number of parallel geocoding requests (default 1) + --timeout Timeout in seconds (default 10) + --retries Number of retries (default 5) + --api-domain API domain (default api.opencagedata.com) + --optional-api-params Extra parameters for each request (e.g. language=fr,no_dedupe=1) - --limit LIMIT Stop after this number of lines in the input + --limit Stop after this number of lines in the input --dry-run Read the input file but no geocoding --no-progress Display no progress bar --quiet No progress bar and no messages diff --git a/opencage/batch.py b/opencage/batch.py index 2fb7ad1..9d3f8fc 100644 --- a/opencage/batch.py +++ b/opencage/batch.py @@ -140,7 +140,7 @@ def on_backoff(details): async def _geocode_one_address(): async with OpenCageGeocode(self.options.api_key, domain=self.options.api_domain, sslcontext=self.sslcontext) as geocoder: geocoding_results = None - params = { 'no_annotations': 1, **self.options.extra_params } + params = { 'no_annotations': 1, **self.options.optional_api_params } try: if self.options.command == 'reverse': diff --git a/opencage/command_line.py b/opencage/command_line.py index 3345103..efb3059 100644 --- a/opencage/command_line.py +++ b/opencage/command_line.py @@ -39,8 +39,8 @@ def parse_args(args): for subparser in [subparser_forward, subparser_reverse]: subparser.add_argument("--api-key", required=True, type=api_key_type, help="Your OpenCage API key") - subparser.add_argument("--input", required=True, type=argparse.FileType('r', encoding='utf-8'), help="Input file name") - subparser.add_argument("--output", required=True, type=str, help="Output file name") + subparser.add_argument("--input", required=True, type=argparse.FileType('r', encoding='utf-8'), help="Input file name", metavar='FILENAME') + subparser.add_argument("--output", required=True, type=str, help="Output file name", metavar='FILENAME') add_optional_arguments(subparser) @@ -59,14 +59,15 @@ def parse_args(args): def add_optional_arguments(parser): parser.add_argument("--headers", action="store_true", help="If the first row should be treated as a header row") default_input_cols = '1,2' if re.match(r'.*reverse', parser.prog) else '1' - parser.add_argument("--input-columns", type=comma_separated_type(int), default=default_input_cols, help=f"Comma-separated list of integers (default '{default_input_cols}')") - parser.add_argument("--add-columns", type=comma_separated_type(str), default="lat,lng,_type,_category,country_code,country,state,county,_normalized_city,postcode,road,house_number,confidence,formatted", help="Comma-separated list of output columns") - parser.add_argument("--workers", type=ranged_type(int, 1, 20), default=1, help="Number of parallel geocoding requests (default 1)") - parser.add_argument("--timeout", type=ranged_type(int, 1, 60), default=10, help="Timeout in seconds (default 10)") - parser.add_argument("--retries", type=ranged_type(int, 1, 60), default=10, help="Number of retries (default 5)") - parser.add_argument("--api-domain", type=str, default="api.opencagedata.com", help="API domain (default api.opencagedata.com)") - parser.add_argument("--extra-params", type=comma_separated_dict_type, default="", help="Extra parameters for each request (e.g. language=fr,no_dedupe=1)") - parser.add_argument("--limit", type=int, default=0, help="Stop after this number of lines in the input") + parser.add_argument("--input-columns", type=comma_separated_type(int), default=default_input_cols, help=f"Comma-separated list of integers (default '{default_input_cols}')", metavar='') + default_add_cols = 'lat,lng,_type,_category,country_code,country,state,county,_normalized_city,postcode,road,house_number,confidence,formatted' + parser.add_argument("--add-columns", type=comma_separated_type(str), default=default_add_cols, help=f"Comma-separated list of output columns (default '{default_add_cols}')", metavar='') + parser.add_argument("--workers", type=ranged_type(int, 1, 20), default=1, help="Number of parallel geocoding requests (default 1)", metavar='') + parser.add_argument("--timeout", type=ranged_type(int, 1, 60), default=10, help="Timeout in seconds (default 10)", metavar='') + parser.add_argument("--retries", type=ranged_type(int, 1, 60), default=10, help="Number of retries (default 5)", metavar='') + parser.add_argument("--api-domain", type=str, default="api.opencagedata.com", help="API domain (default api.opencagedata.com)", metavar='') + parser.add_argument("--optional-api-params", type=comma_separated_dict_type, default="", help="Extra parameters for each request (e.g. language=fr,no_dedupe=1)", metavar='') + parser.add_argument("--limit", type=int, default=0, help="Stop after this number of lines in the input", metavar='') parser.add_argument("--dry-run", action="store_true", help="Read the input file but no geocoding") parser.add_argument("--no-progress", action="store_true", help="Display no progress bar") parser.add_argument("--quiet", action="store_true", help="No progress bar and no messages") diff --git a/test/cli/test_cli_args.py b/test/cli/test_cli_args.py index f8e5bb7..c198f8e 100644 --- a/test/cli/test_cli_args.py +++ b/test/cli/test_cli_args.py @@ -94,7 +94,7 @@ def test_full_argument_list(): "--retries", "1", "--dry-run", "--api-domain", "bulk.opencagedata.com", - "--extra-params", "extra=1", + "--optional-api-params", "extra=1", "--no-progress", "--quiet" ]) @@ -112,7 +112,7 @@ def test_full_argument_list(): assert args.retries == 1 assert args.dry_run is True assert args.api_domain == "bulk.opencagedata.com" - assert args.extra_params == { "extra": "1" } + assert args.optional_api_params == { "extra": "1" } assert args.no_progress is True assert args.quiet is True @@ -134,6 +134,6 @@ def test_defaults(): assert args.retries == 10 assert args.dry_run is False assert args.api_domain == "api.opencagedata.com" - assert args.extra_params == {} + assert args.optional_api_params == {} assert args.no_progress is False assert args.quiet is False