@@ -202,6 +202,9 @@ def json_file_to_dict(fname):
202
202
# Wowza, double closure
203
203
def argparse_type (casedness , prefer_hyphen = False ) :
204
204
def middle (list , type_name ):
205
+ # validate that an argument passed in (as string) is a member of the list of possible
206
+ # arguments. Offer a suggestion if the case of the string, or the hyphens/underscores
207
+ # do not match the expected style of the argument.
205
208
def parse_type (string ):
206
209
if prefer_hyphen : newstring = casedness (string ).replace ("_" ,"-" )
207
210
else : newstring = casedness (string ).replace ("-" ,"_" )
@@ -214,22 +217,27 @@ def parse_type(string):
214
217
return parse_type
215
218
return middle
216
219
220
+ # short cuts for the argparse_type versions
217
221
argparse_uppercase_type = argparse_type (str .upper , False )
218
222
argparse_lowercase_type = argparse_type (str .lower , False )
219
223
argparse_uppercase_hyphen_type = argparse_type (str .upper , True )
220
224
argparse_lowercase_hyphen_type = argparse_type (str .lower , True )
221
225
226
+ # An argument parser combinator that takes in an argument parser and creates a new parser that
227
+ # accepts a comma separated list of the same thing.
222
228
def argparse_many (fn ):
223
229
def wrap (string ):
224
230
return [fn (s ) for s in string .split ("," )]
225
231
return wrap
226
232
233
+ # An argument parser that verifies that a string passed in corresponds to a file
227
234
def argparse_filestring_type (string ) :
228
235
if exists (string ) :
229
236
return string
230
237
else :
231
238
raise argparse .ArgumentTypeError ("{0}" " does not exist in the filesystem." .format (string ))
232
239
240
+ # render a list of strings as a in a bunch of columns
233
241
def columnate (strings , seperator = ", " , chars = 80 ):
234
242
col_width = max (len (s ) for s in strings )
235
243
total_width = col_width + len (seperator )
0 commit comments