@@ -898,50 +898,32 @@ def command_import_tmuxinator(configfile):
898
898
899
899
900
900
@cli .command (name = 'convert' )
901
- @click .option ('--yes' , '-y' , 'confirmed' , help = 'Auto confirms with "yes".' ,
902
- is_flag = True )
901
+ @click .option (
902
+ '--yes' , '-y' , 'confirmed' , help = 'Auto confirms with "yes".' , is_flag = True
903
+ )
903
904
@click .argument ('config' , type = ConfigPath (exists = True ), nargs = 1 )
904
905
def command_convert (confirmed , config ):
905
906
"""Convert a tmuxp config between JSON and YAML."""
906
907
907
908
_ , ext = os .path .splitext (config )
908
- if 'json' in ext and not confirmed :
909
- if click .confirm ('convert to <%s> to yaml?' % config ):
910
- configparser = kaptan .Kaptan ()
911
- configparser .import_config (config )
912
- newfile = config .replace (ext , '.yaml' )
913
- newconfig = configparser .export ('yaml' , indent = 2 , default_flow_style = False )
909
+ if 'json' in ext :
910
+ to_filetype = 'yaml'
911
+ elif 'yaml' in ext :
912
+ to_filetype = 'json'
913
+
914
+ configparser = kaptan .Kaptan ()
915
+ configparser .import_config (config )
916
+ newfile = config .replace (ext , '.%s' % to_filetype )
917
+
918
+ export_kwargs = {'default_flow_style' : False } if to_filetype == 'yaml' else {}
919
+ newconfig = configparser .export (to_filetype , indent = 2 , ** export_kwargs )
920
+
921
+ if not confirmed :
922
+ if click .confirm ('convert to <%s> to %s?' % (config , to_filetype )):
914
923
if click .confirm ('Save config to %s?' % newfile ):
915
- buf = open (newfile , 'w' )
916
- buf .write (newconfig )
917
- buf .close ()
918
- print ('New config saved to %s' % newfile )
919
- elif 'yaml' in ext and not confirmed :
920
- if click .confirm ('convert to <%s> to json?' % config ):
921
- configparser = kaptan .Kaptan ()
922
- configparser .import_config (config )
923
- newfile = config .replace (ext , '.json' )
924
- newconfig = configparser .export ('json' , indent = 2 )
925
- print (newconfig )
926
- if click .confirm ('Save config to <%s>?' % newfile ):
927
- buf = open (newfile , 'w' )
928
- buf .write (newconfig )
929
- buf .close ()
930
- 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 )
924
+ confirmed = True
925
+
926
+ if confirmed :
945
927
buf = open (newfile , 'w' )
946
928
buf .write (newconfig )
947
929
buf .close ()
0 commit comments