Skip to content

Commit 39afc21

Browse files
committed
cli.prompt_yes_no
1 parent 98f557b commit 39afc21

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Diff for: tmuxp/cli.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ def prompt_bool(name, default=False, yes_choices=None, no_choices=None):
7979
return False
8080

8181

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+
8289
def prompt_choices(name, choices, default=None, resolve=ascii_lowercase,
8390
no_choice=('none',)):
8491
"""
@@ -229,15 +236,15 @@ def load_workspace(config_file, args):
229236
builder.build()
230237

231238
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'):
233240
del os.environ['TMUX']
234241
os.execl(tmux_bin, 'tmux', 'switch-client', '-t', sconfig[
235242
'session_name'])
236243

237244
os.execl(tmux_bin, 'tmux', 'attach-session', '-t', sconfig[
238245
'session_name'])
239246
except exc.TmuxSessionExists as e:
240-
attach_session = prompt_bool(e.message + ' Attach?')
247+
attach_session = prompt_yes_no(e.message + ' Attach?', default='Y')
241248

242249
if 'TMUX' in os.environ:
243250
del os.environ['TMUX']
@@ -401,26 +408,26 @@ def command_convert(args):
401408
return
402409

403410
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'):
405412
configparser = kaptan.Kaptan()
406413
configparser.import_config(configfile)
407414
newfile = fullfile.replace(ext, '.yaml')
408415
newconfig = configparser.export(
409416
'yaml', indent=2, default_flow_style=False
410417
)
411-
if prompt_bool('write config to %s?' % (newfile)):
418+
if prompt_yes_no('write config to %s?' % (newfile), default='Y'):
412419
buf = open(newfile, 'w')
413420
buf.write(newconfig)
414421
buf.close()
415422
print('written new config to %s' % (newfile))
416423
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'):
418425
configparser = kaptan.Kaptan()
419426
configparser.import_config(configfile)
420427
newfile = fullfile.replace(ext, '.json')
421428
newconfig = configparser.export('json', indent=2)
422429
print(newconfig)
423-
if prompt_bool('write config to <%s>?' % (newfile)):
430+
if prompt_yes_no('write config to <%s>?' % (newfile), default='Y'):
424431
buf = open(newfile, 'w')
425432
buf.write(newconfig)
426433
buf.close()

0 commit comments

Comments
 (0)