Skip to content

Commit

Permalink
rename CLI parameter "extra-params" to "optional-api-params"
Browse files Browse the repository at this point in the history
  • Loading branch information
mtmail committed Sep 5, 2024
1 parent 8060553 commit 88397ce
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
24 changes: 11 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion opencage/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
21 changes: 11 additions & 10 deletions opencage/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions test/cli/test_cli_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
])
Expand All @@ -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

Expand All @@ -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

0 comments on commit 88397ce

Please sign in to comment.