Skip to content

Commit 48bff61

Browse files
committed
implemented feature reuqest from issue #589
1 parent c87ca9e commit 48bff61

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

tmuxp/cli.py

+26-4
Original file line numberDiff line numberDiff line change
@@ -898,23 +898,25 @@ def command_import_tmuxinator(configfile):
898898

899899

900900
@cli.command(name='convert')
901+
@click.option('--yes', '-y', 'confirmed', help='Auto confirms with "yes".',
902+
is_flag=True)
901903
@click.argument('config', type=ConfigPath(exists=True), nargs=1)
902-
def command_convert(config):
904+
def command_convert(confirmed, config):
903905
"""Convert a tmuxp config between JSON and YAML."""
904906

905907
_, ext = os.path.splitext(config)
906-
if 'json' in ext:
908+
if 'json' in ext and not confirmed:
907909
if click.confirm('convert to <%s> to yaml?' % config):
908910
configparser = kaptan.Kaptan()
909911
configparser.import_config(config)
910912
newfile = config.replace(ext, '.yaml')
911913
newconfig = configparser.export('yaml', indent=2, default_flow_style=False)
912-
if click.confirm('Save config to %s?' % newfile):
914+
if click.confirm('convert config to %s?' % newfile):
913915
buf = open(newfile, 'w')
914916
buf.write(newconfig)
915917
buf.close()
916918
print('New config saved to %s' % newfile)
917-
elif 'yaml' in ext:
919+
elif 'yaml' in ext and not confirmed:
918920
if click.confirm('convert to <%s> to json?' % config):
919921
configparser = kaptan.Kaptan()
920922
configparser.import_config(config)
@@ -926,6 +928,26 @@ def command_convert(config):
926928
buf.write(newconfig)
927929
buf.close()
928930
print('New config saved to <%s>.' % newfile)
931+
elif 'json' in ext and confirmed:
932+
configparser = kaptan.Kaptan()
933+
configparser.import_config(config)
934+
newfile = config.replace(ext, '.yaml')
935+
newconfig = configparser.export('yaml', indent=2)
936+
print(newconfig)
937+
buf = open(newfile, 'w')
938+
buf.write(newconfig)
939+
buf.close()
940+
print('New config saved to <%s>.' % newfile)
941+
elif 'yaml' in ext and confirmed:
942+
configparser = kaptan.Kaptan()
943+
configparser.import_config(config)
944+
newfile = config.replace(ext, '.json')
945+
newconfig = configparser.export('json', indent=2)
946+
print(newconfig)
947+
buf = open(newfile, 'w')
948+
buf.write(newconfig)
949+
buf.close()
950+
print('New config saved to <%s>.' % newfile)
929951

930952

931953
@cli.command(

0 commit comments

Comments
 (0)