@@ -898,12 +898,14 @@ 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
903
@click .argument ('config' , type = ConfigPath (exists = True ), nargs = 1 )
902
- def command_convert (config ):
904
+ def command_convert (confirmed , config ):
903
905
"""Convert a tmuxp config between JSON and YAML."""
904
906
905
907
_ , ext = os .path .splitext (config )
906
- if 'json' in ext :
908
+ if 'json' in ext and not confirmed :
907
909
if click .confirm ('convert to <%s> to yaml?' % config ):
908
910
configparser = kaptan .Kaptan ()
909
911
configparser .import_config (config )
@@ -914,7 +916,7 @@ def command_convert(config):
914
916
buf .write (newconfig )
915
917
buf .close ()
916
918
print ('New config saved to %s' % newfile )
917
- elif 'yaml' in ext :
919
+ elif 'yaml' in ext and not confirmed :
918
920
if click .confirm ('convert to <%s> to json?' % config ):
919
921
configparser = kaptan .Kaptan ()
920
922
configparser .import_config (config )
@@ -926,6 +928,24 @@ def command_convert(config):
926
928
buf .write (newconfig )
927
929
buf .close ()
928
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 )
945
+ buf = open (newfile , 'w' )
946
+ buf .write (newconfig )
947
+ buf .close ()
948
+ print ('New config saved to <%s>.' % newfile )
929
949
930
950
931
951
@cli .command (
0 commit comments