@@ -79,6 +79,13 @@ def prompt_bool(name, default=False, yes_choices=None, no_choices=None):
79
79
return False
80
80
81
81
82
+ 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
+ )
88
+
82
89
def prompt_choices (name , choices , default = None , resolve = ascii_lowercase ,
83
90
no_choice = ('none' ,)):
84
91
"""
@@ -229,15 +236,15 @@ def load_workspace(config_file, args):
229
236
builder .build ()
230
237
231
238
if 'TMUX' in os .environ :
232
- if prompt_bool ('Already inside TMUX, load session?' ):
239
+ if prompt_yes_no ('Already inside TMUX, load session?' , default = 'Y ' ):
233
240
del os .environ ['TMUX' ]
234
241
os .execl (tmux_bin , 'tmux' , 'switch-client' , '-t' , sconfig [
235
242
'session_name' ])
236
243
237
244
os .execl (tmux_bin , 'tmux' , 'attach-session' , '-t' , sconfig [
238
245
'session_name' ])
239
246
except exc .TmuxSessionExists as e :
240
- attach_session = prompt_bool (e .message + ' Attach?' )
247
+ attach_session = prompt_yes_no (e .message + ' Attach?' , default = 'Y ' )
241
248
242
249
if 'TMUX' in os .environ :
243
250
del os .environ ['TMUX' ]
@@ -401,26 +408,26 @@ def command_convert(args):
401
408
return
402
409
403
410
if 'json' in ext :
404
- if prompt_bool ('convert to <%s> to yaml?' % (fullfile )):
411
+ if prompt_yes_no ('convert to <%s> to yaml?' % (fullfile ), default = 'Y' ):
405
412
configparser = kaptan .Kaptan ()
406
413
configparser .import_config (configfile )
407
414
newfile = fullfile .replace (ext , '.yaml' )
408
415
newconfig = configparser .export (
409
416
'yaml' , indent = 2 , default_flow_style = False
410
417
)
411
- if prompt_bool ('write config to %s?' % (newfile )):
418
+ if prompt_yes_no ('write config to %s?' % (newfile ), default = 'Y' ):
412
419
buf = open (newfile , 'w' )
413
420
buf .write (newconfig )
414
421
buf .close ()
415
422
print ('written new config to %s' % (newfile ))
416
423
elif 'yaml' in ext :
417
- if prompt_bool ('convert to <%s> to json?' % (fullfile )):
424
+ if prompt_yes_no ('convert to <%s> to json?' % (fullfile ), default = 'Y' ):
418
425
configparser = kaptan .Kaptan ()
419
426
configparser .import_config (configfile )
420
427
newfile = fullfile .replace (ext , '.json' )
421
428
newconfig = configparser .export ('json' , indent = 2 )
422
429
print (newconfig )
423
- if prompt_bool ('write config to <%s>?' % (newfile )):
430
+ if prompt_yes_no ('write config to <%s>?' % (newfile ), default = 'Y' ):
424
431
buf = open (newfile , 'w' )
425
432
buf .write (newconfig )
426
433
buf .close ()
0 commit comments