@@ -69,8 +69,18 @@ def prompt_bool(name, default=False, yes_choices=None, no_choices=None):
69
69
yes_choices = yes_choices or ('y' , 'yes' , '1' , 'on' , 'true' , 't' )
70
70
no_choices = no_choices or ('n' , 'no' , '0' , 'off' , 'false' , 'f' )
71
71
72
+ if default is None :
73
+ prompt_choice = 'y/n'
74
+ elif default is True :
75
+ prompt_choice = 'Y/n'
76
+ else :
77
+ prompt_choice = 'y/N'
78
+
79
+ prompt = name + ' [%s]' % prompt_choice
80
+ prompt += name .endswith ('?' ) and ' ' or ': '
81
+
72
82
while True :
73
- rv = prompt ( name , default and yes_choices [ 0 ] or no_choices [ 0 ] )
83
+ rv = input ( prompt )
74
84
if not rv :
75
85
return default
76
86
if rv .lower () in yes_choices :
@@ -80,11 +90,7 @@ def prompt_bool(name, default=False, yes_choices=None, no_choices=None):
80
90
81
91
82
92
def prompt_yes_no (name , default = True ):
83
- return prompt_bool (name ,
84
- default = default ,
85
- yes_choices = ['Y' , 'y' ],
86
- no_choices = ['n' ]
87
- )
93
+ return prompt_bool (name , default = default )
88
94
89
95
def prompt_choices (name , choices , default = None , resolve = ascii_lowercase ,
90
96
no_choice = ('none' ,)):
@@ -236,15 +242,15 @@ def load_workspace(config_file, args):
236
242
builder .build ()
237
243
238
244
if 'TMUX' in os .environ :
239
- if prompt_yes_no ('Already inside TMUX, load session?' , default = 'Y' ):
245
+ if prompt_yes_no ('Already inside TMUX, load session?' ):
240
246
del os .environ ['TMUX' ]
241
247
os .execl (tmux_bin , 'tmux' , 'switch-client' , '-t' , sconfig [
242
248
'session_name' ])
243
249
244
250
os .execl (tmux_bin , 'tmux' , 'attach-session' , '-t' , sconfig [
245
251
'session_name' ])
246
252
except exc .TmuxSessionExists as e :
247
- attach_session = prompt_yes_no (e .message + ' Attach?' , default = 'Y' )
253
+ attach_session = prompt_yes_no (e .message + ' Attach?' )
248
254
249
255
if 'TMUX' in os .environ :
250
256
del os .environ ['TMUX' ]
@@ -408,26 +414,26 @@ def command_convert(args):
408
414
return
409
415
410
416
if 'json' in ext :
411
- if prompt_yes_no ('convert to <%s> to yaml?' % (fullfile ), default = 'Y' ):
417
+ if prompt_yes_no ('convert to <%s> to yaml?' % (fullfile )):
412
418
configparser = kaptan .Kaptan ()
413
419
configparser .import_config (configfile )
414
420
newfile = fullfile .replace (ext , '.yaml' )
415
421
newconfig = configparser .export (
416
422
'yaml' , indent = 2 , default_flow_style = False
417
423
)
418
- if prompt_yes_no ('write config to %s?' % (newfile ), default = 'Y' ):
424
+ if prompt_yes_no ('write config to %s?' % (newfile )):
419
425
buf = open (newfile , 'w' )
420
426
buf .write (newconfig )
421
427
buf .close ()
422
428
print ('written new config to %s' % (newfile ))
423
429
elif 'yaml' in ext :
424
- if prompt_yes_no ('convert to <%s> to json?' % (fullfile ), default = 'Y' ):
430
+ if prompt_yes_no ('convert to <%s> to json?' % (fullfile )):
425
431
configparser = kaptan .Kaptan ()
426
432
configparser .import_config (configfile )
427
433
newfile = fullfile .replace (ext , '.json' )
428
434
newconfig = configparser .export ('json' , indent = 2 )
429
435
print (newconfig )
430
- if prompt_yes_no ('write config to <%s>?' % (newfile ), default = 'Y' ):
436
+ if prompt_yes_no ('write config to <%s>?' % (newfile )):
431
437
buf = open (newfile , 'w' )
432
438
buf .write (newconfig )
433
439
buf .close ()
0 commit comments