Raise an exception if the given parameter is not recognized and is longer than 2 characters
@@ -172,16 +172,20 @@ def build_arg_string(kwargs):
... )
... )
-BWSen -Bxaf -Byaf -I1/1p,blue -I2/0.25p,blue -JX4i -R1/2/3/4
+ >>> print(build_arg_string(dict(R="1/2/3/4", J="X4i", watre=True)))
+ Traceback (most recent call last):
+ ...
+ pygmt.exceptions.GMTInvalidInput: Unrecognized parameter 'watre'.
"""
gmt_args = []
- # Exclude arguments that are None and False
- filtered_kwargs = {
- k: v for k, v in kwargs.items() if (v is not None and v is not False)
- }
- for key in filtered_kwargs:
- if is_nonstr_iter(kwargs[key]):
- for value in kwargs[key]:
- gmt_args.append(f"-{key}{value}")
+
+ for key in kwargs:
+ if len(key) > 2: # raise an exception for unrecognized options
+ raise GMTInvalidInput(f"Unrecognized parameter '{key}'.")
+ if kwargs[key] is None or kwargs[key] is False:
+ pass # Exclude arguments that are None and False
+ elif is_nonstr_iter(kwargs[key]):
+ gmt_args.extend(f"-{key}{value}" for value in kwargs[key])
elif kwargs[key] is True:
gmt_args.append(f"-{key}")
else:
