@@ -196,13 +196,18 @@ def is_pure_name(path):
196196 )
197197
198198
199- def _create_scan_config_argument (config_dir ):
200- """For finding configurations in tmuxinator/teamocil"""
199+ class ConfigPath (click .Path ):
200+ def __init__ (self , config_dir = None , * args , ** kwargs ):
201+ super (ConfigPath , self ).__init__ (* args , ** kwargs )
202+ self .config_dir = config_dir
201203
202- def func (ctx , param , value ):
203- return scan_config_argument (ctx , param , value , config_dir )
204+ def convert (self , value , param , ctx ):
205+ config_dir = self .config_dir
206+ if callable (config_dir ):
207+ config_dir = config_dir ()
204208
205- return func
209+ value = scan_config (value , config_dir = config_dir )
210+ return super (ConfigPath , self ).convert (value , param , ctx )
206211
207212
208213def scan_config_argument (ctx , param , value , config_dir = None ):
@@ -719,25 +724,23 @@ def command_freeze(session_name, socket_name, socket_path):
719724
720725@cli .command (name = 'load' , short_help = 'Load tmuxp workspaces.' )
721726@click .pass_context
722- @click .argument (
723- 'config' , click .Path (exists = True ), nargs = - 1 , callback = scan_config_argument
724- )
727+ @click .argument ('config' , type = ConfigPath (exists = True ), nargs = - 1 )
725728@click .option ('-S' , 'socket_path' , help = 'pass-through for tmux -S' )
726729@click .option ('-L' , 'socket_name' , help = 'pass-through for tmux -L' )
727730@click .option ('--yes' , '-y' , 'answer_yes' , help = 'yes' , is_flag = True )
728731@click .option (
729732 '-d' , 'detached' , help = 'Load the session without attaching it' , is_flag = True
730733)
731734@click .option (
732- '-2' ,
733735 'colors' ,
736+ '-2' ,
734737 flag_value = 256 ,
735738 default = True ,
736739 help = 'Force tmux to assume the terminal supports 256 colours.' ,
737740)
738741@click .option (
739- '-8' ,
740742 'colors' ,
743+ '-8' ,
741744 flag_value = 88 ,
742745 help = 'Like -2, but indicates that the terminal supports 88 colours.' ,
743746)
@@ -854,10 +857,7 @@ def import_config(configfile, importfunc):
854857 name = 'teamocil' , short_help = 'Convert and import a teamocil config.'
855858)
856859@click .argument (
857- 'configfile' ,
858- click .Path (exists = True ),
859- nargs = 1 ,
860- callback = _create_scan_config_argument (get_teamocil_dir ),
860+ 'configfile' , type = ConfigPath (exists = True , config_dir = get_teamocil_dir ), nargs = 1
861861)
862862def command_import_teamocil (configfile ):
863863 """Convert a teamocil config from CONFIGFILE to tmuxp format and import
@@ -870,10 +870,7 @@ def command_import_teamocil(configfile):
870870 name = 'tmuxinator' , short_help = 'Convert and import a tmuxinator config.'
871871)
872872@click .argument (
873- 'configfile' ,
874- click .Path (exists = True ),
875- nargs = 1 ,
876- callback = _create_scan_config_argument (get_tmuxinator_dir ),
873+ 'configfile' , type = ConfigPath (exists = True , config_dir = get_tmuxinator_dir ), nargs = 1
877874)
878875def command_import_tmuxinator (configfile ):
879876 """Convert a tmuxinator config from CONFIGFILE to tmuxp format and import
@@ -882,9 +879,7 @@ def command_import_tmuxinator(configfile):
882879
883880
884881@cli .command (name = 'convert' )
885- @click .argument (
886- 'config' , click .Path (exists = True ), nargs = 1 , callback = scan_config_argument
887- )
882+ @click .argument ('config' , type = ConfigPath (exists = True ), nargs = 1 )
888883def command_convert (config ):
889884 """Convert a tmuxp config between JSON and YAML."""
890885
0 commit comments