@@ -915,34 +915,36 @@ def command_import_tmuxinator(configfile):
915915
916916
917917@cli .command (name = 'convert' )
918+ @click .option (
919+ '--yes' , '-y' , 'confirmed' , help = 'Auto confirms with "yes".' , is_flag = True
920+ )
918921@click .argument ('config' , type = ConfigPath (exists = True ), nargs = 1 )
919- def command_convert (config ):
922+ def command_convert (confirmed , config ):
920923 """Convert a tmuxp config between JSON and YAML."""
921924
922925 _ , ext = os .path .splitext (config )
923926 if 'json' in ext :
924- if click .confirm ('convert to <%s> to yaml?' % config ):
925- configparser = kaptan .Kaptan ()
926- configparser .import_config (config )
927- newfile = config .replace (ext , '.yaml' )
928- newconfig = configparser .export ('yaml' , indent = 2 , default_flow_style = False )
929- if click .confirm ('Save config to %s?' % newfile ):
930- buf = open (newfile , 'w' )
931- buf .write (newconfig )
932- buf .close ()
933- print ('New config saved to %s' % newfile )
927+ to_filetype = 'yaml'
934928 elif 'yaml' in ext :
935- if click .confirm ('convert to <%s> to json?' % config ):
936- configparser = kaptan .Kaptan ()
937- configparser .import_config (config )
938- newfile = config .replace (ext , '.json' )
939- newconfig = configparser .export ('json' , indent = 2 )
940- print (newconfig )
941- if click .confirm ('Save config to <%s>?' % newfile ):
942- buf = open (newfile , 'w' )
943- buf .write (newconfig )
944- buf .close ()
945- print ('New config saved to <%s>.' % newfile )
929+ to_filetype = 'json'
930+
931+ configparser = kaptan .Kaptan ()
932+ configparser .import_config (config )
933+ newfile = config .replace (ext , '.%s' % to_filetype )
934+
935+ export_kwargs = {'default_flow_style' : False } if to_filetype == 'yaml' else {}
936+ newconfig = configparser .export (to_filetype , indent = 2 , ** export_kwargs )
937+
938+ if not confirmed :
939+ if click .confirm ('convert to <%s> to %s?' % (config , to_filetype )):
940+ if click .confirm ('Save config to %s?' % newfile ):
941+ confirmed = True
942+
943+ if confirmed :
944+ buf = open (newfile , 'w' )
945+ buf .write (newconfig )
946+ buf .close ()
947+ print ('New config saved to <%s>.' % newfile )
946948
947949
948950@cli .command (
0 commit comments