Skip to content

Commit

Permalink
implemented feature reuqest from issue tmux-python#589
Browse files Browse the repository at this point in the history
  • Loading branch information
aRkedos committed Aug 2, 2020
1 parent c87ca9e commit 48bff61
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions tmuxp/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,23 +898,25 @@ def command_import_tmuxinator(configfile):


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

_, ext = os.path.splitext(config)
if 'json' in ext:
if 'json' in ext and not confirmed:
if click.confirm('convert to <%s> to yaml?' % config):
configparser = kaptan.Kaptan()
configparser.import_config(config)
newfile = config.replace(ext, '.yaml')
newconfig = configparser.export('yaml', indent=2, default_flow_style=False)
if click.confirm('Save config to %s?' % newfile):
if click.confirm('convert config to %s?' % newfile):
buf = open(newfile, 'w')
buf.write(newconfig)
buf.close()
print('New config saved to %s' % newfile)
elif 'yaml' in ext:
elif 'yaml' in ext and not confirmed:
if click.confirm('convert to <%s> to json?' % config):
configparser = kaptan.Kaptan()
configparser.import_config(config)
Expand All @@ -926,6 +928,26 @@ def command_convert(config):
buf.write(newconfig)
buf.close()
print('New config saved to <%s>.' % newfile)
elif 'json' in ext and confirmed:
configparser = kaptan.Kaptan()
configparser.import_config(config)
newfile = config.replace(ext, '.yaml')
newconfig = configparser.export('yaml', indent=2)
print(newconfig)
buf = open(newfile, 'w')
buf.write(newconfig)
buf.close()
print('New config saved to <%s>.' % newfile)
elif 'yaml' in ext and confirmed:
configparser = kaptan.Kaptan()
configparser.import_config(config)
newfile = config.replace(ext, '.json')
newconfig = configparser.export('json', indent=2)
print(newconfig)
buf = open(newfile, 'w')
buf.write(newconfig)
buf.close()
print('New config saved to <%s>.' % newfile)


@cli.command(
Expand Down

0 comments on commit 48bff61

Please sign in to comment.