@@ -57,23 +57,26 @@ def not_empty(value):
57
57
return len (value ) != 0
58
58
59
59
60
+ class ArgumentError (Exception ):
61
+ pass
62
+
63
+
60
64
def prompt (msg , default , mapper = None , predicate = not_empty , header = None , no_prompt = False ):
61
65
if header is not None :
62
66
print (header )
63
67
while True :
64
68
# noinspection PyBroadException
65
69
try :
66
70
print (msg .format (default ), end = ": " )
67
- value = ("" if no_prompt else input ()) or default
68
- if mapper is not None :
69
- value = mapper (value )
71
+ in_value = ("" if no_prompt else input ()) or default
72
+ value = mapper (value ) if mapper is not None else in_value
70
73
if predicate (value ):
71
74
print ()
72
75
return value
73
76
except Exception :
74
77
pass
75
78
if no_prompt :
76
- raise ValueError ( )
79
+ raise ArgumentError ( f"' { in_value } ' is not an acceptable value" )
77
80
print ("Invalid value, try again" )
78
81
79
82
@@ -349,11 +352,15 @@ def create(args, zip):
349
352
file = sys .stderr ,
350
353
)
351
354
exit (1 )
352
- if args .flags_used :
353
- with contextlib .redirect_stdout (io .StringIO ()):
355
+ try :
356
+ if args .flags_used :
357
+ with contextlib .redirect_stdout (io .StringIO ()):
358
+ d = get_substitutes (args , os .path .basename (path ))
359
+ else :
354
360
d = get_substitutes (args , os .path .basename (path ))
355
- else :
356
- d = get_substitutes (args , os .path .basename (path ))
361
+ except ArgumentError as e :
362
+ print (str (e ), file = sys .stderr )
363
+ exit (1 )
357
364
mkdir (path )
358
365
mapping = {"e" : "executable/" , "h" : "header/" , "s" : "shared/" }
359
366
zip_paths = [("c/" if d ["c" ] else "" ) + mapping [d ["type_id" ]], "common/" ]
0 commit comments