@@ -106,7 +106,8 @@ def build_arg_string(kwargs):
106
106
Transform keyword arguments into a GMT argument string.
107
107
108
108
Make sure all arguments have been previously converted to a string
109
- representation using the ``kwargs_to_strings`` decorator.
109
+ representation using the ``kwargs_to_strings`` decorator. The only
110
+ exceptions are True, False and None.
110
111
111
112
Any lists or tuples left will be interpreted as multiple entries for the
112
113
same command line argument. For example, the kwargs entry ``'B': ['xa',
@@ -128,10 +129,20 @@ def build_arg_string(kwargs):
128
129
129
130
>>> print(
130
131
... build_arg_string(
131
- ... dict(R="1/2/3/4", J="X4i", P="", E=200, X=None, Y=None)
132
+ ... dict(
133
+ ... R="1/2/3/4",
134
+ ... J="X4i",
135
+ ... P="",
136
+ ... E=200,
137
+ ... X=None,
138
+ ... Y=None,
139
+ ... A=True,
140
+ ... B=False,
141
+ ... Z=0,
142
+ ... )
132
143
... )
133
144
... )
134
- -E200 -JX4i -P -R1/2/3/4
145
+ -A - E200 -JX4i -P -R1/2/3/4 -Z0
135
146
>>> print(
136
147
... build_arg_string(
137
148
... dict(
@@ -144,18 +155,19 @@ def build_arg_string(kwargs):
144
155
... )
145
156
-Bxaf -Byaf -BWSen -I1/1p,blue -I2/0.25p,blue -JX4i -R1/2/3/4
146
157
"""
158
+
147
159
sorted_args = []
148
160
for key in sorted (kwargs ):
149
161
if is_nonstr_iter (kwargs [key ]):
150
162
for value in kwargs [key ]:
151
- sorted_args .append ("-{}{}" . format ( key , value ) )
152
- elif kwargs [key ] is None : # arguments like -XNone are invalid
163
+ sorted_args .append (f "-{ key } { value } " )
164
+ elif kwargs [key ] is None or kwargs [ key ] is False : # Skip None and False
153
165
continue
166
+ elif kwargs [key ] is True :
167
+ sorted_args .append (f"-{ key } " )
154
168
else :
155
- sorted_args .append ("-{}{}" .format (key , kwargs [key ]))
156
-
157
- arg_str = " " .join (sorted_args )
158
- return arg_str
169
+ sorted_args .append (f"-{ key } { kwargs [key ]} " )
170
+ return " " .join (sorted_args )
159
171
160
172
161
173
def is_nonstr_iter (value ):
0 commit comments