@@ -898,12 +898,14 @@ 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 )
@@ -914,7 +916,7 @@ def command_convert(config):
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,24 @@ 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 , default_flow_style = False )
936+ buf = open (newfile , 'w' )
937+ buf .write (newconfig )
938+ buf .close ()
939+ print ('New config saved to <%s>.' % newfile )
940+ elif 'yaml' in ext and confirmed :
941+ configparser = kaptan .Kaptan ()
942+ configparser .import_config (config )
943+ newfile = config .replace (ext , '.json' )
944+ newconfig = configparser .export ('json' , indent = 2 )
945+ buf = open (newfile , 'w' )
946+ buf .write (newconfig )
947+ buf .close ()
948+ print ('New config saved to <%s>.' % newfile )
929949
930950
931951@cli .command (
0 commit comments