Skip to content

Commit 089b464

Browse files
committed
Create ConfigPath to resolve paths during CLI
callback is no longer resolved before type=, so do that checking by subclassing Click.Path
1 parent dbb0789 commit 089b464

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

tmuxp/cli.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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

208213
def scan_config_argument(ctx, param, value, config_dir=None):
@@ -719,9 +724,7 @@ 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', type=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)
@@ -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-
type=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
)
862862
def 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-
type=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
)
878875
def 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', type=click.Path(exists=True), nargs=1, callback=scan_config_argument
887-
)
882+
@click.argument('config', type=ConfigPath(exists=True), nargs=1)
888883
def command_convert(config):
889884
"""Convert a tmuxp config between JSON and YAML."""
890885

0 commit comments

Comments
 (0)